Skip to content

Commit c575b84

Browse files
committed
feat: create both docker and tasks-docker templates by default
Per Dean's feedback, remove the --with-tasks flag and always create both the docker and tasks-docker templates in develop.sh. This provides a better developer experience by making the tasks-docker template available without requiring a flag. Changes: - Remove --with-tasks flag and associated argument parsing - Always create both docker and tasks-docker templates when docker is available - Pull container image in background for tasks-docker to speed up workspace creation - Update dogfood template to remove --with-tasks usage (no longer needed)
1 parent c5f9e30 commit c575b84

File tree

2 files changed

+34
-42
lines changed

2 files changed

+34
-42
lines changed

dogfood/coder/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ resource "coder_script" "develop_sh" {
924924
echo "Waiting for agent startup script to finish... ($attempt/60)"
925925
sleep 10
926926
done
927-
cd "${local.repo_dir}" && screen -dmS develop_sh /bin/sh -c 'while true; do ./scripts/develop.sh --with-tasks --; echo "develop.sh exited with code $? restarting in 30s"; sleep 30; done'
927+
cd "${local.repo_dir}" && screen -dmS develop_sh /bin/sh -c 'while true; do ./scripts/develop.sh; echo "develop.sh exited with code $? restarting in 30s"; sleep 30; done'
928928
EOT
929929
}
930930

scripts/develop.sh

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#!/usr/bin/env bash
22

3-
# Usage: ./develop.sh [--agpl] [--with-tasks]
3+
# Usage: ./develop.sh [--agpl]
44
#
55
# If the --agpl parameter is specified, builds only the AGPL-licensed code (no
66
# Coder enterprise features).
7-
#
8-
# If the --with-tasks parameter is specified, creates the tasks-docker template
9-
# and pulls the container image in the background.
107

118
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
129
# shellcheck source=scripts/lib.sh
@@ -23,14 +20,13 @@ DEFAULT_PASSWORD="SomeSecurePassword!"
2320
password="${CODER_DEV_ADMIN_PASSWORD:-${DEFAULT_PASSWORD}}"
2421
use_proxy=0
2522
multi_org=0
26-
with_tasks=0
2723

2824
# Ensure that extant environment variables do not override
2925
# the config dir we use to override auth for dev.coder.com.
3026
unset CODER_SESSION_TOKEN
3127
unset CODER_URL
3228

33-
args="$(getopt -o "" -l access-url:,use-proxy,agpl,debug,password:,multi-organization,with-tasks -- "$@")"
29+
args="$(getopt -o "" -l access-url:,use-proxy,agpl,debug,password:,multi-organization -- "$@")"
3430
eval set -- "$args"
3531
while true; do
3632
case "$1" in
@@ -54,10 +50,6 @@ while true; do
5450
multi_org=1
5551
shift
5652
;;
57-
--with-tasks)
58-
with_tasks=1
59-
shift
60-
;;
6153
--debug)
6254
debug=1
6355
shift
@@ -84,11 +76,6 @@ if [ -n "${CODER_AGENT_URL:-}" ]; then
8476
DEVELOP_IN_CODER=1
8577
fi
8678

87-
# When using --with-tasks, use blank access URL to enable tunnel mode
88-
if [ "${with_tasks}" -gt "0" ]; then
89-
CODER_DEV_ACCESS_URL=""
90-
fi
91-
9279
# Preflight checks: ensure we have our required dependencies, and make sure nothing is listening on port 3000 or 8080
9380
dependencies curl git go jq make pnpm
9481

@@ -271,36 +258,41 @@ fatal() {
271258
) || echo "Failed to create a template. The template files are in ${temp_template_dir}"
272259
fi
273260

274-
# If --with-tasks flag is set and docker is available, create the tasks-docker template
275-
if [ "${with_tasks}" -gt "0" ]; then
276-
template_name="tasks-docker"
277-
if docker info >/dev/null 2>&1 && ! "${CODER_DEV_SHIM}" templates versions list "${template_name}" >/dev/null 2>&1; then
278-
echo "Initializing tasks-docker template..."
261+
# Also create the tasks-docker template if docker is available
262+
template_name="tasks-docker"
263+
# Determine the name of the default org with some jq hacks!
264+
first_org_name=$("${CODER_DEV_SHIM}" organizations show me -o json | jq -r '.[] | select(.is_default) | .name')
265+
if docker info >/dev/null 2>&1 && ! "${CODER_DEV_SHIM}" templates versions list "${template_name}" >/dev/null 2>&1; then
266+
# sometimes terraform isn't installed yet when we go to create the
267+
# template
268+
echo "Waiting for terraform to be installed..."
269+
sleep 5
279270

280-
# Pull the container image in the background to speed up workspace creation
281-
container_image="codercom/example-universal:ubuntu"
282-
echo "Pulling container image ${container_image} in background..."
283-
docker pull "${container_image}" >/dev/null 2>&1 &
271+
echo "Initializing tasks-docker template..."
284272

285-
# Create template from the examples directory
286-
temp_template_dir="$(mktemp -d)"
287-
cp -r "${PROJECT_ROOT}/examples/templates/tasks-docker/"* "${temp_template_dir}/"
273+
# Pull the container image in the background to speed up workspace creation
274+
container_image="codercom/example-universal:ubuntu"
275+
echo "Pulling container image ${container_image} in background..."
276+
docker pull "${container_image}" >/dev/null 2>&1 &
288277

289-
# Run terraform init
290-
pushd "${temp_template_dir}" && terraform init && popd
278+
# Create template from the examples directory
279+
temp_template_dir="$(mktemp -d)"
280+
cp -r "${PROJECT_ROOT}/examples/templates/tasks-docker/"* "${temp_template_dir}/"
291281

292-
DOCKER_HOST="$(docker context inspect --format '{{ .Endpoints.docker.Host }}')"
293-
printf 'docker_socket: "%s"\n' "${DOCKER_HOST}" >"${temp_template_dir}/params.yaml"
294-
(
295-
echo "Pushing tasks-docker template to '${first_org_name}'..."
296-
"${CODER_DEV_SHIM}" templates push "${template_name}" --directory "${temp_template_dir}" --variables-file "${temp_template_dir}/params.yaml" --yes --org "${first_org_name}"
297-
if [ "${multi_org}" -gt "0" ]; then
298-
echo "Pushing tasks-docker template to '${another_org}'..."
299-
"${CODER_DEV_SHIM}" templates push "${template_name}" --directory "${temp_template_dir}" --variables-file "${temp_template_dir}/params.yaml" --yes --org "${another_org}"
300-
fi
301-
rm -rfv "${temp_template_dir}" # Only delete template dir if template creation succeeds
302-
) || echo "Failed to create tasks-docker template. The template files are in ${temp_template_dir}"
303-
fi
282+
# Run terraform init so we get a terraform.lock.hcl
283+
pushd "${temp_template_dir}" && terraform init && popd
284+
285+
DOCKER_HOST="$(docker context inspect --format '{{ .Endpoints.docker.Host }}')"
286+
printf 'docker_socket: "%s"\n' "${DOCKER_HOST}" >"${temp_template_dir}/params.yaml"
287+
(
288+
echo "Pushing tasks-docker template to '${first_org_name}'..."
289+
"${CODER_DEV_SHIM}" templates push "${template_name}" --directory "${temp_template_dir}" --variables-file "${temp_template_dir}/params.yaml" --yes --org "${first_org_name}"
290+
if [ "${multi_org}" -gt "0" ]; then
291+
echo "Pushing tasks-docker template to '${another_org}'..."
292+
"${CODER_DEV_SHIM}" templates push "${template_name}" --directory "${temp_template_dir}" --variables-file "${temp_template_dir}/params.yaml" --yes --org "${another_org}"
293+
fi
294+
rm -rfv "${temp_template_dir}" # Only delete template dir if template creation succeeds
295+
) || echo "Failed to create tasks-docker template. The template files are in ${temp_template_dir}"
304296
fi
305297

306298
if [ "${use_proxy}" -gt "0" ]; then

0 commit comments

Comments
 (0)