mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
chore: parallel makefile attempt 3 (#3926)
* Revert "chore: Revert parallel Makefile builds (#3918)"
This reverts commit b077f71015
.
* fix: fix release workflow with parallel makefile
* fix: mark generated files as fresh during releases
This commit is contained in:
@ -5,19 +5,28 @@
|
||||
# If the --agpl parameter is specified, builds only the AGPL-licensed code (no
|
||||
# Coder enterprise features).
|
||||
|
||||
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
|
||||
# shellcheck disable=SC1091,SC1090
|
||||
source "${SCRIPT_DIR}/lib.sh"
|
||||
|
||||
# Allow toggling verbose output
|
||||
[[ -n ${VERBOSE:-""} ]] && set -x
|
||||
[[ -n ${VERBOSE:-} ]] && set -x
|
||||
set -euo pipefail
|
||||
|
||||
agpl="${CODER_BUILD_AGPL:-0}"
|
||||
args="$(getopt -o "" -l agpl -- "$@")"
|
||||
password="${CODER_DEV_ADMIN_PASSWORD:-password}"
|
||||
|
||||
args="$(getopt -o "" -l agpl,password: -- "$@")"
|
||||
eval set -- "$args"
|
||||
while true; do
|
||||
case "$1" in
|
||||
--agpl)
|
||||
agpl=1
|
||||
export CODER_BUILD_AGPL=1
|
||||
shift
|
||||
;;
|
||||
--password)
|
||||
password="$2"
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
@ -28,43 +37,20 @@ while true; do
|
||||
esac
|
||||
done
|
||||
|
||||
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
|
||||
# shellcheck disable=SC1091,SC1090
|
||||
source "${SCRIPT_DIR}/lib.sh"
|
||||
PROJECT_ROOT=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel)
|
||||
CODER_DEV_BIN="${PROJECT_ROOT}/.coderv2/coder"
|
||||
set +u
|
||||
CODER_DEV_ADMIN_PASSWORD="${CODER_DEV_ADMIN_PASSWORD:-password}"
|
||||
set -u
|
||||
|
||||
# Preflight checks: ensure we have our required dependencies, and make sure nothing is listening on port 3000 or 8080
|
||||
dependencies curl git go make yarn
|
||||
curl --fail http://127.0.0.1:3000 >/dev/null 2>&1 && echo '== ERROR: something is listening on port 3000. Kill it and re-run this script.' && exit 1
|
||||
curl --fail http://127.0.0.1:8080 >/dev/null 2>&1 && echo '== ERROR: something is listening on port 8080. Kill it and re-run this script.' && exit 1
|
||||
|
||||
if [[ ! -e ./site/out/bin/coder.sha1 && ! -e ./site/out/bin/coder.tar.zst ]]; then
|
||||
log
|
||||
log "======================================================================="
|
||||
log "== Run 'make bin' before running this command to build binaries. =="
|
||||
log "== Without these binaries, workspaces will fail to start! =="
|
||||
log "======================================================================="
|
||||
log
|
||||
exit 1
|
||||
fi
|
||||
# Compile the CLI binary. This should also compile the frontend and refresh
|
||||
# node_modules if necessary.
|
||||
GOOS="$(go env GOOS)"
|
||||
GOARCH="$(go env GOARCH)"
|
||||
make "build/coder_${GOOS}_${GOARCH}"
|
||||
|
||||
cmd_path="enterprise/cmd/coder"
|
||||
if [[ "$agpl" == 1 ]]; then
|
||||
cmd_path="cmd/coder"
|
||||
fi
|
||||
|
||||
# Compile the CLI binary once just so we don't waste time compiling things multiple times
|
||||
go build -tags embed -o "${CODER_DEV_BIN}" "${PROJECT_ROOT}/${cmd_path}"
|
||||
# Use the coder dev shim so we don't overwrite the user's existing Coder config.
|
||||
CODER_DEV_SHIM="${PROJECT_ROOT}/scripts/coder-dev.sh"
|
||||
|
||||
# Run yarn install, to make sure node_modules are ready to go
|
||||
"$PROJECT_ROOT/scripts/yarn_install.sh"
|
||||
|
||||
# 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:
|
||||
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
|
||||
@ -73,51 +59,49 @@ CODER_DEV_SHIM="${PROJECT_ROOT}/scripts/coder-dev.sh"
|
||||
# rather than leaving things in an inconsistent state.
|
||||
trap 'kill -TERM -$$' ERR
|
||||
cdroot
|
||||
"${CODER_DEV_SHIM}" server --address 127.0.0.1:3000 --in-memory --tunnel || kill -INT -$$ &
|
||||
"${CODER_DEV_SHIM}" server --address 127.0.0.1:3000 --tunnel || kill -INT -$$ &
|
||||
|
||||
echo '== Waiting for Coder to become ready'
|
||||
timeout 60s bash -c 'until curl -s --fail http://localhost:3000 > /dev/null 2>&1; do sleep 0.5; done'
|
||||
|
||||
# create the first user, the admin
|
||||
"${CODER_DEV_SHIM}" login http://127.0.0.1:3000 --username=admin --email=admin@coder.com --password="${CODER_DEV_ADMIN_PASSWORD}" ||
|
||||
# Try to create the initial admin user.
|
||||
"${CODER_DEV_SHIM}" login http://127.0.0.1:3000 --username=admin --email=admin@coder.com --password="${password}" ||
|
||||
echo 'Failed to create admin user. To troubleshoot, try running this command manually.'
|
||||
|
||||
# || true to always exit code 0. If this fails, whelp.
|
||||
"${CODER_DEV_SHIM}" users create --email=member@coder.com --username=member --password="${CODER_DEV_ADMIN_PASSWORD}" ||
|
||||
# Try to create a regular user.
|
||||
"${CODER_DEV_SHIM}" users create --email=member@coder.com --username=member --password="${password}" ||
|
||||
echo 'Failed to create regular user. To troubleshoot, try running this command manually.'
|
||||
|
||||
# If we have docker available, then let's try to create a template!
|
||||
template_name=""
|
||||
if docker info >/dev/null 2>&1; then
|
||||
temp_template_dir=$(mktemp -d)
|
||||
echo code-server | "${CODER_DEV_SHIM}" templates init "${temp_template_dir}"
|
||||
# shellcheck disable=SC1090
|
||||
source <(go env | grep GOARCH)
|
||||
DOCKER_HOST=$(docker context inspect --format '{{.Endpoints.docker.Host}}')
|
||||
printf 'docker_arch: "%s"\ndocker_host: "%s"\n' "${GOARCH}" "${DOCKER_HOST}" | tee "${temp_template_dir}/params.yaml"
|
||||
template_name="docker-${GOARCH}"
|
||||
# If we have docker available and the "docker" template doesn't already
|
||||
# exist, then let's try to create a template!
|
||||
example_template="code-server"
|
||||
template_name="docker"
|
||||
if docker info >/dev/null 2>&1 && ! "${CODER_DEV_SHIM}" templates versions list "${template_name}"; then
|
||||
temp_template_dir="$(mktemp -d)"
|
||||
echo "${example_template}" | "${CODER_DEV_SHIM}" templates init "${temp_template_dir}"
|
||||
|
||||
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"
|
||||
(
|
||||
"${CODER_DEV_SHIM}" templates create "${template_name}" --directory "${temp_template_dir}" --parameter-file "${temp_template_dir}/params.yaml" --yes &&
|
||||
rm -rfv "${temp_template_dir}" # Only delete template dir if template creation succeeds
|
||||
"${CODER_DEV_SHIM}" templates create "${template_name}" --directory "${temp_template_dir}" --parameter-file "${temp_template_dir}/params.yaml" --yes
|
||||
rm -rfv "${temp_template_dir}" # Only delete template dir if template creation succeeds
|
||||
) || echo "Failed to create a template. The template files are in ${temp_template_dir}"
|
||||
fi
|
||||
|
||||
# Start the frontend once we have a template up and running
|
||||
CODER_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev || kill -INT -$$ &
|
||||
|
||||
log
|
||||
log "======================================================================="
|
||||
log "== =="
|
||||
log "== Coder is now running in development mode. =="
|
||||
log "== API : http://localhost:3000 =="
|
||||
log "== Web UI: http://localhost:8080 =="
|
||||
if [[ -n "${template_name}" ]]; then
|
||||
log "== =="
|
||||
log "== Docker template ${template_name} is ready to use! =="
|
||||
log "== Use ./scripts/coder-dev.sh to talk to this instance! =="
|
||||
log "== =="
|
||||
fi
|
||||
log "======================================================================="
|
||||
log "===================================================================="
|
||||
log "== =="
|
||||
log "== Coder is now running in development mode. =="
|
||||
log "== API: http://localhost:3000 =="
|
||||
log "== Web UI: http://localhost:8080 =="
|
||||
log "== =="
|
||||
log "== Use ./scripts/coder-dev.sh to talk to this instance! =="
|
||||
log "===================================================================="
|
||||
log
|
||||
|
||||
# Wait for both frontend and backend to exit.
|
||||
wait
|
||||
)
|
||||
|
Reference in New Issue
Block a user