From bb26bcb5b6e3fe8c165512271b4399dccdfa3bd2 Mon Sep 17 00:00:00 2001 From: jatcod3r Date: Wed, 23 Oct 2024 18:28:55 -0700 Subject: [PATCH] fix --- .github/workflows/push.yaml | 10 ++++------ .gitignore | 37 +++++++++++++++++++++++++++++++++++ .scripts/push.sh | 39 ++++++++++++++++++++----------------- README.md | 27 +++++++++++++++++++++++++ base/README.md | 11 +++++++++++ dprint.json | 9 +++++++++ 6 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 base/README.md create mode 100644 dprint.json diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index eb87177..4d45e77 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -27,6 +27,8 @@ permissions: jobs: quick: runs-on: ubuntu-latest + strategy: + fail-fast: true steps: - name: Cancel previous runs if: github.event_name == 'pull_request' @@ -47,13 +49,9 @@ jobs: - name: Install Coder CLI run: | curl -L https://coder.com/install.sh | sh - curl -X GET http://${{ secrets.CODER_ENV }}/api/v2/organizations/{organization}/templates \ - -H 'Accept: application/json' \ - -H 'Coder-Session-Token: ${{ secrets.CODER_SESSION_TOKEN }}' - name: Push Templates to Coder run: | ${{ github.workspace }}/.scripts/push.sh \ - --url ${{ secrets.CODER_ENV }} \ - --token ${{ secrets.CODER_SESSION_TOKEN }} \ - --directory ${{ github.workspace }} \ No newline at end of file + --directory "${{ github.workspace }}" \ + --targets "${{ secrets.CODER_TARGETS }}" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2faf43d --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Ignore transient lock info files created by terraform apply +.terraform.tfstate.lock.info + +# Include override files you do wish to add to version control using negated pattern +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc diff --git a/.scripts/push.sh b/.scripts/push.sh index f3d3946..eea723a 100755 --- a/.scripts/push.sh +++ b/.scripts/push.sh @@ -2,24 +2,25 @@ set -euo pipefail +cd "$(dirname "$0")" + function usage() { - echo "Usage: ./$(basename "$0") [-h|--help] [-d|--directory] --url --token " + echo "Usage: ./$(basename "$0") [-h|--help] [-d|--directory] --targets " echo echo "This script pushes example templates a Coder environment." echo echo "Options:" echo " -h, --help Show this help text and exit" echo " -d, --directory Directory containing all base templates" - echo " --url URL of coderd server" - echo " --token Coder session" + echo " -t, --targets Coder URL Server w/ embedded token (e.g. coder.com:token123)" exit 1 } # Allow a failing exit status, as user input can cause this set +o errexit -LONGOPTS=help,url:,token:,directory: -OPTS=h,d: +LONGOPTS=help,targets:,directory: +OPTS=h,d:,t: PARSED=$(getopt \ --name="$(basename "$0")" \ --longoptions=$LONGOPTS \ @@ -35,13 +36,10 @@ while true; do shift BASE_DIR="$1" ;; - --url) - shift - CODER_URL="$1" - ;; - --token) + -t|--targets) + # The input to --targets should be a multiline string (e.g. newline delimited string) shift - CODER_SESSION_TOKEN="$1" + read -rd '' -a CODER_TARGETS <<< "$1" || true ;; -h|--help) usage @@ -60,11 +58,16 @@ done source "./templates.sh" -for TEMPLATE in "${TEMPLATES[@]}"; do - coder templates push \ - --url $CODER_URL \ - --token $CODER_SESSION_TOKEN \ - --directory $BASE_DIR/$TEMPLATE \ - --yes +# CODER_TARGETS should be an array where each line follows a : format. +IFS=";" +for TARGET in "${CODER_TARGETS[@]}"; do + read -r CODER_URL CODER_SESSION_TOKEN <<< "$TARGET" + for TEMPLATE in "${TEMPLATES[@]}"; do + coder templates push \ + --url $CODER_URL \ + --token $CODER_SESSION_TOKEN \ + --directory $BASE_DIR/$TEMPLATE \ + --yes + done done - +unset IFS \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..76039dc --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Coder Templates + +This is a repository that for my own Coder example templates and workflow experimentation. +For a list of base-level examples, list them in our CLI with `coder templates init`. + +> [Submit an issue](https://github.com/coder/coder/issues/new) if you encounter any issues! + +## Getting Started + +Clone this repository to create a template from any example listed here: + +```console +git clone https://github.com/coder/templates +``` + +To consume this repository's templates in your Coder deployment: + +```console +cd +coder templates push +``` + +OR + +```console +coder templates push -d +``` diff --git a/base/README.md b/base/README.md new file mode 100644 index 0000000..61f0484 --- /dev/null +++ b/base/README.md @@ -0,0 +1,11 @@ +--- +display_name: Base K8s Template +description: Provisions a Pod with Coder +icon: ../../../site/static/icon/aws.svg +maintainer_github: jatcod3r +verified: true +tags: [] +--- + +> **Note** +> This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case. diff --git a/dprint.json b/dprint.json new file mode 100644 index 0000000..b2ac2b9 --- /dev/null +++ b/dprint.json @@ -0,0 +1,9 @@ +{ + "markdown": {}, + "excludes": [ + "deprecated/*" + ], + "plugins": [ + "https://plugins.dprint.dev/markdown-0.17.0.wasm" + ] +} \ No newline at end of file