chore(scripts/develop.sh): auto determine first org name and run terraform init (#15603)

Updates `develop.sh` to automatically determine the name of the 'first
org' when pushing the initial template.

Also runs `terraform init` before running `coder templates push` (pet
peeve).
This commit is contained in:
Cian Johnston
2024-11-20 14:01:13 +00:00
committed by GitHub
parent 6ed76921dd
commit 593d659ec8

View File

@ -203,6 +203,8 @@ fatal() {
# If we have docker available and the "docker" template doesn't already # If we have docker available and the "docker" template doesn't already
# exist, then let's try to create a template! # exist, then let's try to create a template!
template_name="docker" template_name="docker"
# Determine the name of the default org with some jq hacks!
first_org_name=$("${CODER_DEV_SHIM}" organizations show me -o json | jq -r '.[] | select(.is_default) | .name')
if docker info >/dev/null 2>&1 && ! "${CODER_DEV_SHIM}" templates versions list "${template_name}" >/dev/null 2>&1; then if docker info >/dev/null 2>&1 && ! "${CODER_DEV_SHIM}" templates versions list "${template_name}" >/dev/null 2>&1; then
# sometimes terraform isn't installed yet when we go to create the # sometimes terraform isn't installed yet when we go to create the
# template # template
@ -212,12 +214,14 @@ fatal() {
echo "Initializing docker template..." echo "Initializing docker template..."
temp_template_dir="$(mktemp -d)" temp_template_dir="$(mktemp -d)"
"${CODER_DEV_SHIM}" templates init --id "${template_name}" "${temp_template_dir}" "${CODER_DEV_SHIM}" templates init --id "${template_name}" "${temp_template_dir}"
# Run terraform init so we get a terraform.lock.hcl
pushd "${temp_template_dir}" && terraform init && popd
DOCKER_HOST="$(docker context inspect --format '{{ .Endpoints.docker.Host }}')" DOCKER_HOST="$(docker context inspect --format '{{ .Endpoints.docker.Host }}')"
printf 'docker_arch: "%s"\ndocker_host: "%s"\n' "${GOARCH}" "${DOCKER_HOST}" >"${temp_template_dir}/params.yaml" printf 'docker_arch: "%s"\ndocker_host: "%s"\n' "${GOARCH}" "${DOCKER_HOST}" >"${temp_template_dir}/params.yaml"
( (
echo "Pushing docker template to 'first-organization'..." echo "Pushing docker template to '${first_org_name}'..."
"${CODER_DEV_SHIM}" templates push "${template_name}" --directory "${temp_template_dir}" --variables-file "${temp_template_dir}/params.yaml" --yes --org first-organization "${CODER_DEV_SHIM}" templates push "${template_name}" --directory "${temp_template_dir}" --variables-file "${temp_template_dir}/params.yaml" --yes --org "${first_org_name}"
if [ "${multi_org}" -gt "0" ]; then if [ "${multi_org}" -gt "0" ]; then
echo "Pushing docker template to '${another_org}'..." echo "Pushing docker template to '${another_org}'..."
"${CODER_DEV_SHIM}" templates push "${template_name}" --directory "${temp_template_dir}" --variables-file "${temp_template_dir}/params.yaml" --yes --org "${another_org}" "${CODER_DEV_SHIM}" templates push "${template_name}" --directory "${temp_template_dir}" --variables-file "${temp_template_dir}/params.yaml" --yes --org "${another_org}"