Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use variables instead of sedding
  • Loading branch information
johnstcn committed Jun 24, 2022
commit a3569fd3589ca0a45e939c264826c1b407c29671
17 changes: 10 additions & 7 deletions examples/lima/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ provision:
# Set up initial user
[ ! -e ~/.config/coderv2/session ] && coder login http://localhost:3000 --username admin --email admin@coder.com --password $(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8 | tee ${HOME}/.config/coderv2/password)
# Create an initial template
cd ${HOME}
echo code-server | coder templates init
cd ./docker-code-server
if [ $(arch) = "aarch64" ]; then
sed -i 's/arch.*=.*"amd64"/arch = "arm64"/' ./main.tf
temp_template_dir=$(mktemp -d)
echo code-server | coder templates init "${temp_template_dir}"
DOCKER_ARCH="amd64"
if [ "$(arch)" = "aarch64" ]; then
DOCKER_ARCH="arm64"
fi
coder templates create docker-code-server -y -d .
DOCKER_HOST=$(docker context inspect --format '{{.Endpoints.docker.Host}}')
printf 'docker_arch: "%s"\ndocker_host: "%s"\n' "${DOCKER_ARCH}" "${DOCKER_HOST}" | tee "${temp_template_dir}/params.yaml"
coder templates create "docker-code-server-${DOCKER_ARCH}" --directory "${temp_template_dir}" --parameter-file "${temp_template_dir}/params.yaml" --yes
rm -rfv "${temp_template_dir}"
probes:
- description: "docker to be installed"
script: |
Expand All @@ -127,7 +130,7 @@ probes:
See "/var/log/cloud-init-output.log" in the guest.
message: |
All Done! Your Coder instance is accessible at http://localhost:3000

Username: "admin@coder.com"
Password: Run `LIMA_INSTANCE=coder lima cat /home/${USER}.linux/.config/coderv2/password` 🤫

Expand Down
16 changes: 15 additions & 1 deletion examples/templates/docker-code-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,18 @@ tags: [local, docker]

## Getting started

Run `coder templates init` and select this template. Follow the instructions that appear.
Run `coder templates init` and select this template. Follow the instructions that appear.

## Supported Parameters

You can create a file containing parameters and pass the argument
`--parameter-file` to `coder templates create`.
See `params.sample.yaml` for more information.

This template has the following predefined parameters:

- `docker_host`: Path to (or address of) the Docker socket.
> You can determine the correct value for this by runnning
> `docker context ls`.
- `docker_arch`: Architecture of the host running Docker.
This can be `amd64`, `arm64`, or `armv7`.
20 changes: 19 additions & 1 deletion examples/templates/docker-code-server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,32 @@ terraform {
}
}

variable "docker_host" {
description = "Specify location of Docker socket (check `docker context ls` if you're not sure)"
sensitive = true
}

variable "docker_arch" {
description = "Specify architecture of docker host (amd64, arm64, or armv7)"
validation {
condition = contains(["amd64", "arm64", "armv7"], var.docker_arch)
error_message = "Value must be amd64, arm64, or armv7."
}
sensitive = true
}

provider "coder" {
}

provider "docker" {
host = var.docker_host
}

data "coder_workspace" "me" {
}

resource "coder_agent" "dev" {
arch = "amd64"
arch = var.docker_arch
os = "linux"
startup_script = "code-server --auth none"
}
Expand Down
18 changes: 5 additions & 13 deletions scripts/develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ set +u
CODER_DEV_ADMIN_PASSWORD="${CODER_DEV_ADMIN_PASSWORD:-password}"
set -u

# shellcheck disable=SC1090
source <(go env)

# Preflight checks: ensure we have our required dependencies, and make sure nothing is listening on port 3000 or 8080
dependencies curl git go make yarn
curl --fail http://127.0.0.1:3000 >/dev/null 2>&1 && echo '== ERROR: something is listening on port 3000. Kill it and re-run this script.' && exit 1
Expand Down Expand Up @@ -58,17 +55,12 @@ fi
# If we have docker available, then let's try to create a template!
if docker run --rm hello-world >/dev/null 2>&1; then
temp_template_dir=$(mktemp -d)
# cd "${temp_template_dir}"
echo code-server | go run "${PROJECT_ROOT}/cmd/coder/main.go" templates init "${temp_template_dir}"
if [[ "$GOARCH" = "arm64" ]]; then
# MacOS sed expects an argument to -i.
sed_ext_arg=""
if [[ "$GOOS" = "darwin" ]]; then
sed_ext_arg="''"
fi
sed -i "$sed_ext_arg" 's/arch.*=.*"amd64"/arch = "arm64"/' "${temp_template_dir}/main.tf"
fi
go run "${PROJECT_ROOT}/cmd/coder/main.go" templates create "docker-${GOARCH}" -d "${temp_template_dir}" -y
# shellcheck disable=SC1090
source <(go env | grep GOARCH)
DOCKER_HOST=$(docker context inspect --format '{{.Endpoints.docker.Host}}')
printf 'docker_arch: "%s"\ndocker_host: "%s"\n' "${GOARCH}" "${DOCKER_HOST}" | tee "${temp_template_dir}/params.yaml"
go run "${PROJECT_ROOT}/cmd/coder/main.go" templates create "docker-${GOARCH}" --directory "${temp_template_dir}" --parameter-file "${temp_template_dir}/params.yaml" --yes
rm -rfv "${temp_template_dir}"
fi

Expand Down