Skip to content
Open
Changes from all commits
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
55 changes: 48 additions & 7 deletions scripts/develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,26 @@ fatal() {
echo "== FAIL: $*" >&2
kill -INT $ppid >/dev/null 2>&1
}
push_template() {
local template_name=$1
local temp_template_dir=$2
local first_org_name=$3
local another_org=$4
local params_file="${temp_template_dir}/params.yaml"

local push_args="--directory ${temp_template_dir}"
if [ -f "${params_file}" ]; then
push_args="${push_args} --variables-file ${params_file}"
fi

echo "Pushing ${template_name} template to '${first_org_name}'..."
"${CODER_DEV_SHIM}" templates push "${template_name}" ${push_args} --yes --org "${first_org_name}"
if [ "${multi_org}" -gt "0" ]; then
echo "Pushing ${template_name} template to '${another_org}'..."
"${CODER_DEV_SHIM}" templates push "${template_name}" ${push_args} --yes --org "${another_org}"
fi
rm -rfv "${temp_template_dir}" # Only delete template dir if template creation succeeds
}

# This is a way to run multiple processes in parallel, and have Ctrl-C work correctly
# to kill both at the same time. For more details, see:
Expand Down Expand Up @@ -248,16 +268,37 @@ fatal() {
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"
(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal but the parenthesis are not required anymore.

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_org_name}"
if [ "${multi_org}" -gt "0" ]; then
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}"
fi
rm -rfv "${temp_template_dir}" # Only delete template dir if template creation succeeds
push_template "${template_name}" "${temp_template_dir}" "${first_org_name}" "${another_org}"
) || echo "Failed to create a template. The template files are in ${temp_template_dir}"
fi

# Also create the tasks-docker template if docker is available
template_name="tasks-docker"
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
# template
echo "Waiting for terraform to be installed..."
sleep 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a (bounded) loop with command -v terraform or something to test for it being installed rather than a sleep


echo "Initializing tasks-docker template..."

# Pull the container image in the background to speed up workspace creation
container_image="codercom/example-universal:ubuntu"
echo "Pulling container image ${container_image} in background..."
docker pull "${container_image}" >/dev/null 2>&1 &

# Create template from the examples directory
temp_template_dir="$(mktemp -d)"
cp -r "${PROJECT_ROOT}/examples/templates/tasks-docker/"* "${temp_template_dir}/"

# Run terraform init so we get a terraform.lock.hcl
pushd "${temp_template_dir}" && terraform init && popd

(
push_template "${template_name}" "${temp_template_dir}" "${first_org_name}" "${another_org}"
) || echo "Failed to create tasks-docker template. The template files are in ${temp_template_dir}"
fi
Comment on lines +277 to +300
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not make the regular docker template the same as this? It's missing the terraform check, the background pulling, the terraform init. It'd be nice if these could just be identical and just be ~two lines


if [ "${use_proxy}" -gt "0" ]; then
log "Using external workspace proxy"
(
Expand Down
Loading