|
34 | 34 | # to kill both at the same time. For more details, see:
|
35 | 35 | # https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
|
36 | 36 | (
|
37 |
| - SCRIPT_PID=$$ |
| 37 | + # If something goes wrong, just bail and tear everything down |
| 38 | + # rather than leaving things in an inconsistent state. |
| 39 | + trap 'kill -INT -$$' ERR |
38 | 40 | cdroot
|
39 |
| - CODERV2_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev || kill -INT -${SCRIPT_PID} & |
40 |
| - go run -tags embed cmd/coder/main.go server --address 127.0.0.1:3000 --in-memory --tunnel || kill -INT -${SCRIPT_PID} & |
| 41 | + CODER_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev || kill -INT -$$ & |
| 42 | + go run -tags embed cmd/coder/main.go server --address 127.0.0.1:3000 --in-memory --tunnel || kill -INT -$$ & |
41 | 43 |
|
42 | 44 | echo '== Waiting for Coder to become ready'
|
43 | 45 | timeout 60s bash -c 'until curl -s --fail http://localhost:3000 > /dev/null 2>&1; do sleep 0.5; done'
|
|
49 | 51 | # || true to always exit code 0. If this fails, whelp.
|
50 | 52 | go run cmd/coder/main.go users create --email=member@coder.com --username=member --password="${CODER_DEV_ADMIN_PASSWORD}" ||
|
51 | 53 | echo 'Failed to create regular user. To troubleshoot, try running this command manually.'
|
| 54 | + |
| 55 | + # If we have docker available, then let's try to create a template! |
| 56 | + template_name="" |
| 57 | + if docker info >/dev/null 2>&1; then |
| 58 | + temp_template_dir=$(mktemp -d) |
| 59 | + echo code-server | go run "${PROJECT_ROOT}/cmd/coder/main.go" templates init "${temp_template_dir}" |
| 60 | + # shellcheck disable=SC1090 |
| 61 | + source <(go env | grep GOARCH) |
| 62 | + DOCKER_HOST=$(docker context inspect --format '{{.Endpoints.docker.Host}}') |
| 63 | + printf 'docker_arch: "%s"\ndocker_host: "%s"\n' "${GOARCH}" "${DOCKER_HOST}" | tee "${temp_template_dir}/params.yaml" |
| 64 | + template_name="docker-${GOARCH}" |
| 65 | + go run "${PROJECT_ROOT}/cmd/coder/main.go" templates create "${template_name}" --directory "${temp_template_dir}" --parameter-file "${temp_template_dir}/params.yaml" --yes |
| 66 | + rm -rfv "${temp_template_dir}" |
| 67 | + fi |
| 68 | + |
| 69 | + log |
| 70 | + log "=======================================================================" |
| 71 | + log "== ==" |
| 72 | + log "== Coder is now running in development mode. ==" |
| 73 | + log "== API : http://localhost:3000 ==" |
| 74 | + log "== Web UI: http://localhost:8080 ==" |
| 75 | + if [[ -n "${template_name}" ]]; then |
| 76 | + log "== ==" |
| 77 | + log "== Docker template ${template_name} is ready to use! ==" |
| 78 | + log "== ==" |
| 79 | + fi |
| 80 | + log "=======================================================================" |
| 81 | + log |
| 82 | + # Wait for both frontend and backend to exit. |
52 | 83 | wait
|
53 | 84 | )
|
0 commit comments