Skip to content

Commit a75bdff

Browse files
Uarmagantyler-daneclaude
authored
refactor(ci): unify on selfhosted profile name (#1798)
* fix(ci): default self-host health checks to selfhost profile * refactor(ci): unify on selfhosted profile name Simplify by using "selfhosted" consistently everywhere instead of having two terms ("selfhost" for Docker Compose, "selfhosted" for scripts). This removes the need for translation logic in the health check script. - Rename Docker Compose profile: selfhost → selfhosted - Remove resolved_compose_profiles() and remote_compose_env_prefix() - Simplify remote_compose_prefix() to check PROFILE directly - Update all scripts, workflows, and docs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: export COMPOSE_PROFILES once instead of per-command Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * revert: remove unrelated import change from PR Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Tyler Dane <tyler@switchback.tech> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c83e952 commit a75bdff

7 files changed

Lines changed: 70 additions & 30 deletions

File tree

.github/scripts/deploy-health-check.sh

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,11 @@ ssh_remote() {
367367
}
368368

369369
remote_compose_prefix() {
370-
local profiles=${COMPOSE_PROFILES:-}
371-
372-
if [ -n "$profiles" ]; then
373-
printf "cd ~/compass && COMPOSE_PROFILES=%q docker compose --project-name compass -f compose.yaml" "$profiles"
374-
return
370+
if [ "${PROFILE:-}" = "selfhosted" ]; then
371+
printf 'cd ~/compass && COMPOSE_PROFILES=selfhosted docker compose --project-name compass -f compose.yaml'
372+
else
373+
printf 'cd ~/compass && docker compose --project-name compass -f compose.yaml'
375374
fi
376-
377-
printf 'cd ~/compass && docker compose --project-name compass -f compose.yaml'
378375
}
379376

380377
remote_check_stack() {
@@ -500,6 +497,7 @@ remote_check_selfhosted_data() {
500497
ssh_remote "bash -se" <<REMOTE
501498
set -euo pipefail
502499
cd ~/compass
500+
export COMPOSE_PROFILES=selfhosted
503501
504502
# Verify MongoDB is reachable and the replica set is healthy.
505503
docker compose --project-name compass -f compose.yaml exec -T mongo mongosh --quiet \
@@ -568,18 +566,24 @@ run_all_checks() {
568566
finish
569567
}
570568

571-
case "${1:-run}" in
572-
run)
573-
run_all_checks
574-
;;
575-
validate-frontend)
576-
validate_frontend
577-
;;
578-
validate-frontend-version)
579-
validate_frontend_version
580-
;;
581-
*)
582-
printf 'usage: %s [run|validate-frontend|validate-frontend-version]\n' "$0" >&2
583-
exit 2
584-
;;
585-
esac
569+
main() {
570+
case "${1:-run}" in
571+
run)
572+
run_all_checks
573+
;;
574+
validate-frontend)
575+
validate_frontend
576+
;;
577+
validate-frontend-version)
578+
validate_frontend_version
579+
;;
580+
*)
581+
printf 'usage: %s [run|validate-frontend|validate-frontend-version]\n' "$0" >&2
582+
exit 2
583+
;;
584+
esac
585+
}
586+
587+
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
588+
main "$@"
589+
fi

.github/workflows/_deploy-environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
fi
129129
ssh -i ~/.ssh/staging_key "$SSH_USER@$SSH_HOST" "curl -fsSL https://raw.githubusercontent.com/SwitchbackTech/compass/${COMPOSE_GIT_REF}/self-host/compose.yaml -o ~/compass/compose.yaml"
130130
ssh -i ~/.ssh/staging_key "$SSH_USER@$SSH_HOST" "curl -fsSL https://raw.githubusercontent.com/SwitchbackTech/compass/${COMPOSE_GIT_REF}/self-host/compass -o ~/compass/compass && chmod +x ~/compass/compass"
131-
ssh -i ~/.ssh/staging_key "$SSH_USER@$SSH_HOST" "cd ~/compass && COMPOSE_PROFILES=selfhost docker compose --project-name compass -f compose.yaml down 2>/dev/null || true"
131+
ssh -i ~/.ssh/staging_key "$SSH_USER@$SSH_HOST" "cd ~/compass && COMPOSE_PROFILES=selfhosted docker compose --project-name compass -f compose.yaml down 2>/dev/null || true"
132132
if [ -n "$COMPOSE_PROFILES" ]; then
133133
ssh -i ~/.ssh/staging_key "$SSH_USER@$SSH_HOST" "cd ~/compass && COMPOSE_PROFILES='${COMPOSE_PROFILES}' ./compass update"
134134
else

docs/self-hosting/backup-and-restore.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ When the rehearsal is done, remove only the temporary project:
311311
```bash
312312
cd "$CHECK_DIR"
313313
./compass stop
314-
COMPOSE_PROFILES=selfhost docker compose \
314+
COMPOSE_PROFILES=selfhosted docker compose \
315315
--project-name "$CHECK_PROJECT" \
316316
-f compose.yaml \
317317
down -v

self-host/compass

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ load_env_if_present() {
132132
set_compose_env() {
133133
load_env
134134
export COMPASS_CONFIG_FILE="$CONFIG_FILE"
135-
export COMPOSE_PROFILES="${COMPOSE_PROFILES-selfhost}"
135+
export COMPOSE_PROFILES="${COMPOSE_PROFILES-selfhosted}"
136136
export COMPASS_VERSION="$(strip_quotes "$(read_config_value runtime.version)")"
137137
export COMPASS_WEB_IMAGE="$(strip_quotes "$(read_config_value web.image)")"
138138
export WEB_PORT="$(strip_quotes "$(read_config_value web.port)")"

self-host/compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ services:
4848

4949
mongo:
5050
image: switchbacktech/compass-mongo:${COMPASS_VERSION:-latest}
51-
profiles: [selfhost]
51+
profiles: [selfhosted]
5252
environment:
5353
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME:-compass}
5454
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD:-change-me-mongo-password-32chars}
@@ -70,7 +70,7 @@ services:
7070

7171
supertokens:
7272
image: supertokens/supertokens-postgresql:11.0.2
73-
profiles: [selfhost]
73+
profiles: [selfhosted]
7474
depends_on:
7575
supertokens-db:
7676
condition: service_healthy
@@ -91,7 +91,7 @@ services:
9191

9292
supertokens-db:
9393
image: postgres:16-alpine
94-
profiles: [selfhost]
94+
profiles: [selfhosted]
9595
environment:
9696
POSTGRES_USER: ${SUPERTOKENS_POSTGRES_USER:-supertokens}
9797
POSTGRES_PASSWORD: ${SUPERTOKENS_POSTGRES_PASSWORD:-change-me-supertokens-postgres-pass-32}

self-host/docker-compose.test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@ async function runHealthScript(
3737
return { exitCode, stderr, stdout };
3838
}
3939

40+
async function runHealthScriptFunction(
41+
command: string,
42+
env: Record<string, string> = {},
43+
) {
44+
const proc = Bun.spawn(
45+
["bash", "-c", `. .github/scripts/deploy-health-check.sh; ${command}`],
46+
{
47+
cwd: repoRoot,
48+
env: {
49+
...process.env,
50+
...env,
51+
},
52+
stderr: "pipe",
53+
stdout: "pipe",
54+
},
55+
);
56+
57+
const [stdout, stderr, exitCode] = await Promise.all([
58+
new Response(proc.stdout).text(),
59+
new Response(proc.stderr).text(),
60+
proc.exited,
61+
]);
62+
63+
return { exitCode, stderr, stdout };
64+
}
65+
4066
function makeTempDir() {
4167
const dir = mkdtempSync(join(tmpdir(), "compass-health-check-"));
4268
tempDirs.push(dir);
@@ -100,7 +126,7 @@ describe("self-host helper", () => {
100126
const helper = readRepoFile("self-host/compass");
101127

102128
expect(helper).toContain(
103-
'COMPOSE_PROFILES="' + "$" + '{COMPOSE_PROFILES-selfhost}"',
129+
'COMPOSE_PROFILES="' + "$" + '{COMPOSE_PROFILES-selfhosted}"',
104130
);
105131
});
106132

@@ -267,4 +293,14 @@ describe("deploy health check script", () => {
267293
expect(result.stderr).toContain("frontend-version");
268294
expect(result.stderr).toContain("expected 0.5.27, got 0.5.26");
269295
});
296+
297+
it("uses selfhosted profile for selfhosted deployments", async () => {
298+
const result = await runHealthScriptFunction("remote_compose_prefix", {
299+
PROFILE: "selfhosted",
300+
});
301+
302+
expect(result.exitCode).toBe(0);
303+
expect(result.stdout).toContain("COMPOSE_PROFILES=selfhosted");
304+
expect(result.stdout).toContain("docker compose --project-name compass");
305+
});
270306
});

self-host/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ EOF
482482
set_compose_env() {
483483
[ -f "$CONFIG_FILE" ] || fail "Missing config file: $CONFIG_FILE."
484484
export COMPASS_CONFIG_FILE="$CONFIG_FILE"
485-
export COMPOSE_PROFILES="${COMPOSE_PROFILES-selfhost}"
485+
export COMPOSE_PROFILES="${COMPOSE_PROFILES-selfhosted}"
486486
export COMPASS_VERSION="$(strip_quotes "$(read_config_value runtime.version)")"
487487
export WEB_PORT="$(strip_quotes "$(read_config_value web.port)")"
488488
export PORT="$(strip_quotes "$(read_config_value backend.port)")"

0 commit comments

Comments
 (0)