Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jatcod3r committed Oct 24, 2024
1 parent 7d69d59 commit bb26bcb
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 24 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 }}
--directory "${{ github.workspace }}" \
--targets "${{ secrets.CODER_TARGETS }}"
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
39 changes: 21 additions & 18 deletions .scripts/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

set -euo pipefail

cd "$(dirname "$0")"

function usage() {
echo "Usage: ./$(basename "$0") [-h|--help] [-d|--directory] <template(s) directory> --url <Coder URL> --token <Coder session token>"
echo "Usage: ./$(basename "$0") [-h|--help] [-d|--directory] <template(s) directory> --targets <URL:token>"
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 \
Expand All @@ -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
Expand All @@ -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 <URL>:<Token> 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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <TEMPLATE_DIR>
coder templates push
```

OR

```console
coder templates push -d <TEMPLATE_DIR>
```
11 changes: 11 additions & 0 deletions base/README.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"markdown": {},
"excludes": [
"deprecated/*"
],
"plugins": [
"https://plugins.dprint.dev/markdown-0.17.0.wasm"
]
}

0 comments on commit bb26bcb

Please sign in to comment.