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
118SCRIPT_DIR=$( dirname " ${BASH_SOURCE[0]} " )
129# shellcheck source=scripts/lib.sh
@@ -23,14 +20,13 @@ DEFAULT_PASSWORD="SomeSecurePassword!"
2320password=" ${CODER_DEV_ADMIN_PASSWORD:- ${DEFAULT_PASSWORD} } "
2421use_proxy=0
2522multi_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.
3026unset CODER_SESSION_TOKEN
3127unset 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 -- " $@ " ) "
3430eval set -- " $args "
3531while 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
8577fi
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
9380dependencies 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