From 691216f3a1686f310f88664fc25e4e67b041418c Mon Sep 17 00:00:00 2001 From: Xander Harris Date: Wed, 2 Oct 2024 08:46:00 -0700 Subject: [PATCH 1/2] Add Dockerfile for local development Closes #59 --- .gitignore | 1 + CHANGELOG.md | 21 +++++--- README.md | 118 +++++++++++++++++++++++++++++++++++++------ auth_example_flow.sh | 2 +- docker/.bashrc | 25 +++++++++ docker/.zshrc | 18 +++++++ docker/Dockerfile | 26 ++++++++++ docker/README.md | 50 ++++++++++++++++++ install.sh | 2 +- symenv.sh | 10 ++-- test.sh | 11 ++-- 11 files changed, 250 insertions(+), 34 deletions(-) create mode 100644 docker/.bashrc create mode 100644 docker/.zshrc create mode 100644 docker/Dockerfile create mode 100644 docker/README.md mode change 100755 => 100644 test.sh diff --git a/.gitignore b/.gitignore index c52e2d1..a887036 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea symenv_debug.log +reflog \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 223a83a..af4fc38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,25 +1,30 @@ # symenv -## [1.2.16] - 2022-05-24 +## [1.2.17](https://github.com/platonic-io/symenv/releases/tag/v1.2.17) -### Added +### Fixed 1.2.17 - 2022-07-20 + +- Fixed artifact ordering by expecting 0s in the artifact counter (#53) + +## [1.2.16](https://github.com/platonic-io/symenv/releases/tag/v1.2.16) + +### Added - 2022-05-24 - Login function which is independent from any other commands. -## [1.2.13] - 2020-03-30 +## [1.2.13](https://github.com/platonic-io/symenv/releases/tag/v1.2.13) -### Removed +### Removed 1.2.13 - 2022-03-29 - Remove ability to install VSCode extension -### Fixed +### Fixed 1.2.13 - Symenv timeout issue with auth requests. It will timeout in 30 seconds now +## [1.2.12](https://github.com/platonic-io/symenv/releases/tag/v1.2.12) -## [1.2.12] - 2020-03-28 - -### Fixed +### Fixed 1.2.12 - 2020-03-28 - Add error catching for package download failures - Extract package tar directly to correct directory diff --git a/README.md b/README.md index 87b6f6a..79bfb4e 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,126 @@ -###### Development +# Readme + +## Usage + +The simplest way to get up and running is with +[Docker](https://www.docker.com/products/docker-desktop/). + +1. Pull the most recent version of the symenv image. + + ```shell + docker pull ghcr.io/platonic-io/symenv:latest + ``` + +2. Run the container on your local system with either bash or zsh. + + ```shell + # Use Bash + docker run --name symenv -it "ghcr.io/platonic-io/symenv:$(git describe --tags --abbrev=0)" bash + + # Use zsh -- Note that zsh is not officially supported. + docker run --name symenv -it "ghcr.io/platonic-io/symenv:$(git describe --tags --abbrev=0)" zsh + ``` + +3. Use the shell provided by the container to authenticate. + + ```shell + symenv login --registry=portal.platonic.io + ``` + +4. List the available versions. + + ```shell + symenv ls-remote + ``` + + This should produce a list of available versions similar to the following. + + ```shell + v2.0.0 + v2.0.1 + v2.0.2 + v2.0.3 + v3.0.0 + v4.0.0 + v4.1.0 + ``` + +5. Install one or more of the available versions. + + ```shell + symenv install v4.1.0 + ``` + +6. Use the assembly. + +## Development Prerequisites: + - `curl` or `wget` - `jq` - an account for Symbiont's portal -```shell -source ./test.sh -``` +### Development Usage -For usage against the staging portal, append a `--registry=` to commands that perform remote operations. Note that -you will also need to use a token created by said registry in order for authentication to work. If need be, use `symenv reset` -to clear your authentication token. -```shell -symenv install --registry=portal-staging.waf-symbiont.io -``` +1. Prepare the environment. + + ```shell + source ./test.sh + ``` + + You should see output similar to this. + + ```shell + => Downloading symenv as script to '/root/.symbiont' + [1]- Done symenv_download -s "$SYMENV_SOURCE_LOCAL" -o "$INSTALL_DIR/symenv.sh" || { symenv_echo "Failed to download '$SYMENV_SOURCE_LOCAL'" 1>&2; return 1; } + [2]+ Done symenv_download -s "$SYMENV_BASH_COMPLETION_SOURCE" -o "$INSTALL_DIR/bash_completion" || { symenv_echo "Failed to download '$SYMENV_BASH_COMPLETION_SOURCE'" 1>&2; return 2; } + + => Append to profile file then close and reopen your terminal to start using symenv or run the following to use it now: + + export SYMENV_DIR="$HOME/.symbiont" + [ -s "$SYMENV_DIR/symenv.sh" ] && \. "$SYMENV_DIR/symenv.sh" # This loads symenv + [ -s "$SYMENV_DIR/versions/current" ] && export PATH="$SYMENV_DIR/versions/current/bin":$PATH # This loads symenv managed SDK + [ -s "$SYMENV_DIR/bash_completion" ] && \. "$SYMENV_DIR/bash_completion" # This loads symenv bash_completion + ``` + +2. Choose a registry by appending the `--registry=portal.platonic.io` flag to commands + that perform remote operations. + + > Note that you will also need to use a token created by said registry + > in order for authentication to work. + > + > If need be, use `symenv reset` to clear your authentication token. + +3. Install the environment. -###### Installation + ```shell + symenv install --registry=portal.platonic.io v4.1.0 + ``` + +### Docker Usage + +You can find information on how to build and run a container with symenv [here](docker/README.md). + +## Installation Prerequisites: + - `curl` or `wget` - `jq` - an account for Symbiont's portal Remotely + ```shell curl --proto '=https' --tlsv1.2 -sSf https:////install.sh | bash -``` -eg. -```shell +# Example + curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/symbiont-io/symenv/main/install.sh | bash ``` -###### Commands +### Commands ```help Usage: @@ -52,4 +139,3 @@ Usage: --all Include the non-release versions symenv reset Resets your environment to a fresh install of symenv ``` - diff --git a/auth_example_flow.sh b/auth_example_flow.sh index c262c7d..8ceab0b 100755 --- a/auth_example_flow.sh +++ b/auth_example_flow.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash CODE_REQUEST_RESPONSE=$(curl --silent --proto '=https' --tlsv1.2 --request POST \ --url "https://internal-portal.us.auth0.com/oauth/device/code" \ diff --git a/docker/.bashrc b/docker/.bashrc new file mode 100644 index 0000000..4c7d5c3 --- /dev/null +++ b/docker/.bashrc @@ -0,0 +1,25 @@ +#!/bin/bash +# shellcheck disable=SC1091 + +CLICOLOR=1 +# shellcheck disable=SC2016 +LESS='-R --use-color -Dd+r$Du+b$' +LSCOLORS="Ea" +PS1='[\[\e[31m\]\u\[\e[0m\]@\[\e[32m\]\H\[\e[0m\]:\[\e[33m\]\w\[\e[0m\]]{\[\e[34m\]$?\[\e[0m\]}\$ ' +SYMENV_DIR="$HOME/.symbiont" + +# shellcheck disable=SC1091 +if [ -f /usr/share/bash-completion/bash_completion ]; then + source /usr/share/bash-completion/bash_completion +fi + +PATH="$SYMENV_DIR/versions/current/bin:$PATH" + +. "$HOME/.symbiont/symenv.sh" +. "$HOME/.symbiont/bash_completion" + +export CLICOLOR +export LESS +export LSCOLORS +export PS1 +export PATH diff --git a/docker/.zshrc b/docker/.zshrc new file mode 100644 index 0000000..e1ce93a --- /dev/null +++ b/docker/.zshrc @@ -0,0 +1,18 @@ +#!/usr/bin/zsh + +export SYMENV_DIR="$HOME/.symbiont" + +# This loads symenv +if [ -f "$SYMENV_DIR/symenv.sh" ]; then + source "$SYMENV_DIR/symenv.sh" +fi + +# This loads symenv managed SDK +if [ -f "$SYMENV_DIR/versions/current" ]; then + export PATH="$SYMENV_DIR/versions/current/bin":$PATH +fi + +# This loads symenv bash_completion +if [ -f "$SYMENV_DIR/bash_completion" ]; then + source "$SYMENV_DIR/bash_completion" +fi \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..38f6967 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,26 @@ +# syntax=docker/dockerfile:1 +FROM archlinux/archlinux:base-devel +ARG DATE="2024-10-02" +ARG VERSION="v0.0.0" +LABEL org.opencontainers.image.authors="xander@platonic.io" +LABEL org.opencontainers.image.date="${DATE}" +LABEL org.opencontainers.image.source="https://github.com/platonic-io/symenv" +LABEL org.opencontainers.image.version="${VERSION}" +RUN pacman -Syyu --noconfirm \ + bash-completion \ + curl \ + git \ + jq \ + unzip \ + vim \ + wget \ + zip \ + zsh \ + && ln -sfv /usr/bin/vim /usr/bin/vi \ + && useradd -s /bin/bash -m -g users -d /home/symenv symenv +COPY docker/.zshrc /home/symenv/.zshrc +COPY docker/.bashrc /home/symenv/.bashrc +USER symenv +RUN curl -L https://raw.githubusercontent.com/symbiont-io/symenv/main/install.sh | bash +WORKDIR /home/symenv/ +CMD ["/bin/bash"] \ No newline at end of file diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..2765364 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,50 @@ +# Symenv Docker Build + +If you'd like to customize the container you're running symenv in, you may +build a new one with this process. + +1. Build the Docker image to run locally. + + ```shell + docker build --build-arg=DATE="$(date +%Y-%m-%d)" --build-arg=VERSION="$(git describe --tags --abbrev=0-)" \ + -t ghcr.io/platonic-io/symenv:"$(git describe --tags --abbrev=0)" -f docker/Dockerfile \ + --progress plain . + ``` + +2. Run a container named `symenv` with the image we just built. + + ```shell + # Use Bash + docker run --name symenv -it "ghcr.io/platonic-io/symenv:$(git describe --tags --abbrev=0)" bash + + # Use zsh + docker run --name symenv -it "ghcr.io/platonic-io/symenv:$(git describe --tags --abbrev=0)" zsh + ``` + +3. From the running container you can list the remote versions available to install. + + ```shell + symenv ls-remote --registry=portal.platonic.io --force-auth + ``` + + 1. Follow the instructions to complete your login. + 2. Then attend to the list of available versions produced. + + ```shell + ✅ Authentication successful + v2.0.0 + v2.0.1 + v2.0.2 + v2.0.3 + v3.0.0 + v4.0.0 + v4.1.0 + ``` + +4. Now install one or more of them. + + ```shell + symenv install --registry=portal.platonic.io v4.1.0 + ``` + +You are now ready to deploy resources to the cloud of your choice. diff --git a/install.sh b/install.sh index ec3fd47..9038e7c 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash { # this ensures the entire script is downloaded # diff --git a/symenv.sh b/symenv.sh index e72e8f6..e831c62 100755 --- a/symenv.sh +++ b/symenv.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash # shellcheck disable=SC2039 # ^-- Ignore warning about `local`s @@ -472,7 +472,7 @@ ;; --force) FORCE_REINSTALL=1 ;; --debug) ;; - --force-auth) ;; + --force-auth) ;; *) if [ -n "${1-}" ]; then PROVIDED_VERSION="$1" @@ -540,7 +540,7 @@ symenv_err "SDK Failed to Download" return 44 fi - + tar xzf "${TARGET_FILE}" --directory "${TARGET_PATH}" --strip-components=2 rm "${TARGET_FILE}" @@ -566,7 +566,7 @@ #if there's no match, sed will just output the key itself # otherwise set the key equal to the left size of the equal and set the value to the right side - if [[ "$(echo $KEY | sed 's/^\(.*\)=\(.*\)$/\2/g' )" != $KEY && $VALUE == "" ]]; then + if [[ "$(echo $KEY | sed 's/^\(.*\)=\(.*\)$/\2/g' )" != $KEY && $VALUE == "" ]]; then symenv_debug "Equals passed to ${KEY} and no value ${VALUE}" VALUE="$(echo $KEY | sed 's/\(.*\)=\(.*\)/\2/g' )" KEY="$(echo $KEY | sed 's/\(.*\)=\(.*\)/\1/g' )" @@ -674,7 +674,7 @@ else # Otherwise, no file, means we go from scratch symenv_do_auth "$REGISTRY" - if [ "" = "${SYMENV_ACCESS_TOKEN}" ] | [ null = "${SYMENV_ACCESS_TOKEN}" ]; then + if [ "" = "${SYMENV_ACCESS_TOKEN}" ] | [ null = "${SYMENV_ACCESS_TOKEN}" ]; then return 1 fi touch "${HOME}/.symenvrc" diff --git a/test.sh b/test.sh old mode 100755 new mode 100644 index 3270790..3258de1 --- a/test.sh +++ b/test.sh @@ -1,4 +1,9 @@ -#!/usr/bin/env sh +#!/bin/sh -export SYM_DIR=`pwd` -[ -s "$SYM_DIR/symenv.sh" ] && \. "$SYM_DIR/symenv.sh" +SYM_DIR="$(pwd)" + +export SYM_DIR + +if [ -s "$SYM_DIR/symenv.sh" ]; then + /bin/sh "$SYM_DIR/symenv.sh" +fi From 6d979e9ce58f0df8c18e52a9533879bc6980f234 Mon Sep 17 00:00:00 2001 From: Xander Harris Date: Fri, 25 Oct 2024 05:26:00 -0700 Subject: [PATCH 2/2] Add pages workflow Closes #59 --- .github/workflows/pages.yml | 148 ++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 .github/workflows/pages.yml diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000..a5b3178 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,148 @@ +### +# ```{rubric} GitHub Pages Workflow +# ``` +# --- +# This is a basic workflow to help you get started with Actions. +# +# ```{literalinclude} /.github/workflows/pages.yml +# :language: yaml +# :start-at: "name: Test, Build, Deploy to GitHub Pages\n" +# :end-before: "###\n" +# ``` +# +# Set a name for the workflow. +name: Test, Build, Deploy to GitHub Pages +on: + pull_request: + branches: + - main + push: + branches: + - main + workflow_dispatch: {} + +### +# ```{rubric} Permissions Updates +# ``` +# Enable read for contents and issues, and write for checks and PRs. +# +# ```{literalinclude} /.github/workflows/pages.yml +# :language: yaml +# :start-at: "permissions:\n" +# :end-before: "###\n" +# ``` +permissions: + contents: read + issues: read + checks: write + pull-requests: write + +### +# ```{rubric} Workflow Jobs +# ``` +# --- +# A workflow run is made up of one or more +# jobs that can run sequentially or in parallel +# +jobs: + ### + # ```{rubric} markdownlint + # ``` + # --- + # Check that the markdown in this repo is up to our (arbitrary) standards. + # + # ```{literalinclude} /.github/workflows/pages.yml + # :language: yaml + # :start-at: "markdownlint:\n" + # :end-before: "###\n" + # ``` + markdownlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@main + - name: Set up NodeJS + uses: actions/setup-node@main + - name: Install the checker + run: npm i -g markdownlint-cli2 markdownlint-cli2-formatter-junit --save-dev + - name: Lint the Markdown + run: markdownlint-cli2 **/*.md *.md + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + check_name: markdownlint + comment_title: "Markdown Lint" + files: markdownlint-cli2-junit.xml + ### + # ```{rubric} Build GitHub Pages Site + # ``` + # --- + # Build the pages site using Sphinx and upload the resulting artifact. + # + # ```{literalinclude} /.github/workflows/pages.yml + # :language: yaml + # :start-at: " build:\n" + # :end-before: "###\n" + # ``` + build: + needs: markdownlint + runs-on: ubuntu-20.04 + permissions: + contents: read + pages: write + id-token: write + steps: + - run: | + curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null + sudo apt-get install apt-transport-https --yes + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list + sudo apt-get update + sudo apt-get install -y helm + - run: helm plugin install https://github.com/helm-unittest/helm-unittest + - uses: actions/checkout@main + with: + fetch-depth: 0 + - uses: actions/setup-python@main + with: + python-version: 3.11 + cache: pipenv + - name: Setup pages + uses: actions/configure-pages@main + - name: Install pipenv + run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python + - name: Install Python dependencies + run: | + pipenv install --dev + pipenv install -e . + - name: Build the static site + run: pipenv run sphinx-build -a -E . deploy + - name: Upload artifact + uses: actions/upload-pages-artifact@main + with: + path: './deploy' + ### + # ```{rubric} Deploy the Pages site + # ``` + # --- + # Download the artifact and deploy to pages. + # + # ```{literalinclude} /.github/workflows/pages.yml + # :language: yaml + # :start-at: " pages:\n" + # ``` + pages: + needs: build + runs-on: ubuntu-20.04 + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + permissions: + pages: write + id-token: write + steps: + - name: Download pages artifact + id: download + uses: actions/download-artifact@main + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4