Skip to content

Commit 52da1a1

Browse files
committed
build: improve deploy scripts to be more automated
1 parent 27707a2 commit 52da1a1

File tree

6 files changed

+54
-45
lines changed

6 files changed

+54
-45
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### Container runtime ###
2+
# Set DOCKER_ALIAS=nerdctl if using containerd/nerdctl instead of Docker.
3+
# DOCKER_ALIAS=${DOCKER_ALIAS:-docker}
4+
# CONTAINERD_SNAPSHOTTER=${CONTAINERD_SNAPSHOTTER}
5+
16
### ODK Central ###
27
ODK_CENTRAL_URL=${ODK_CENTRAL_URL:-"http://central:8383"}
38
ODK_CENTRAL_USER=${ODK_CENTRAL_USER:-"admin@hotosm.org"}

deploy/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ Alternative production entry points:
3030

3131
```sh
3232
just start prod-with-odk
33-
just start prod-login
3433
```
34+
35+
> `just start prod` automatically includes the self-hosted Hanko login overlay
36+
> when `AUTH_PROVIDER=bundled` is set in `.env`.

deploy/compose.login.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#
2121
# IMPORTANT: This file uses ${FTM_DOMAIN} in bunkerweb env var KEY names,
2222
# which requires envsubst preprocessing - the same pipeline already used by
23-
# compose.sub.yaml. Use `just start prod-login` which handles this.
23+
# compose.sub.yaml. `just start prod` handles this automatically when
24+
# AUTH_PROVIDER=bundled is set in .env.
2425
#
2526
# For non-VM deployments see AUTH_PROVIDER=hotosm (centralised HOT login)
2627
# or AUTH_PROVIDER=custom (bring-your-own Hanko).

docs/dev/Production.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ The `setup` wizard configures these automatically, but you may want to review:
8383
- `custom`: Your own Hanko instance
8484
Deploy with `just start prod`
8585
- `bundled`: Self-hosted Hanko via the login overlay
86-
Deploy with `just start prod-login`
86+
Deploy with `just start prod` (login overlay is included automatically)
8787

8888
If you use `AUTH_PROVIDER=hotosm`, set:
8989

@@ -211,11 +211,10 @@ just start prod-with-odk
211211

212212
### Field-TM with self-hosted Hanko login
213213

214-
```bash
215-
just start prod-login
216-
```
214+
Set `AUTH_PROVIDER=bundled` in `.env` (or select it during `just config setup`),
215+
then run `just start prod` — the login overlay is included automatically.
217216

218-
All three commands will:
217+
All commands will:
219218

220219
1. Check for uncommitted changes (and refuse to proceed if dirty)
221220
2. Present a numbered list of available release versions

tasks/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ setup:
151151
echo ""
152152
just _echo-blue "Setup complete. Config written to .env"
153153
echo ""
154-
just _echo-yellow "Modify .env as needed, then run: just start prod (or just start prod-login)"
154+
just _echo-yellow "Modify .env as needed, then run: just start prod"
155155
echo ""
156156

157157
# For custom branding, place favicon.svg in the repo root, then run this

tasks/start

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,19 @@ _select-version:
6363
# Persist the chosen tag for the calling recipe
6464
echo "${chosen}" > /tmp/.ftm_deploy_tag
6565

66-
# Production deploy
66+
# Production deploy (auto-detects AUTH_PROVIDER from .env)
6767
[no-cd]
6868
prod:
69-
#!/usr/bin/env sh
69+
#!/usr/bin/env bash
7070
set -e
7171

72-
just start _select-version
73-
export GIT_BRANCH=$(cat /tmp/.ftm_deploy_tag)
74-
75-
# From deploy dir
76-
cd {{justfile_directory()}}/deploy
77-
78-
# Config
79-
just config generate-dotenv "${GIT_BRANCH}"
80-
just config custom-favicon
81-
82-
# Deploy core FieldTM
83-
../envsubst -no-unset -i compose.sub.yaml | \
84-
{{docker}} compose -f - up --detach \
85-
--remove-orphans --force-recreate
86-
87-
just _echo-blue "FieldTM ${GIT_BRANCH} started successfully"
72+
# Ensure PATH includes common binary locations (rootless docker, snap, etc.)
73+
export PATH="$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH"
8874

89-
# Production deploy with self-hosted Hanko auth (contrib/login)
90-
[no-cd]
91-
prod-login:
92-
#!/usr/bin/env sh
93-
set -e
75+
if ! command -v {{docker}} >/dev/null 2>&1; then
76+
just _echo-red "'{{docker}}' not found. If using nerdctl, set DOCKER_ALIAS=nerdctl in .env"
77+
exit 1
78+
fi
9479

9580
just start _select-version
9681
export GIT_BRANCH=$(cat /tmp/.ftm_deploy_tag)
@@ -100,26 +85,44 @@ prod-login:
10085

10186
# Config
10287
just config generate-dotenv "${GIT_BRANCH}"
103-
just config custom-favicon
104-
105-
# Both compose files use ${FTM_DOMAIN} in bunkerweb env var KEY names, which
106-
# requires envsubst preprocessing. Process to temp files then compose together.
107-
tmp_main=$(mktemp)
108-
tmp_login=$(mktemp)
109-
../envsubst -no-unset -i compose.sub.yaml > "$tmp_main"
110-
../envsubst -no-unset -i compose.login.yaml > "$tmp_login"
111-
{{docker}} compose -f "$tmp_main" -f "$tmp_login" up --detach \
112-
--remove-orphans --force-recreate
113-
rm -f "$tmp_main" "$tmp_login"
11488

115-
just _echo-blue "FieldTM ${GIT_BRANCH} + self-hosted Hanko started successfully"
89+
# Read AUTH_PROVIDER from .env
90+
auth_provider=$(grep -E '^AUTH_PROVIDER=' ../.env | cut -d= -f2 | tr -d '"' || echo "")
91+
92+
if [ "$auth_provider" = "bundled" ]; then
93+
just _echo-blue "AUTH_PROVIDER=bundled detected, deploying with self-hosted Hanko..."
94+
# Both compose files use ${FTM_DOMAIN} in bunkerweb env var KEY names, which
95+
# requires envsubst preprocessing. Process to temp files then compose together.
96+
tmp_main=$(mktemp)
97+
tmp_login=$(mktemp)
98+
../envsubst -no-unset -i compose.sub.yaml > "$tmp_main"
99+
../envsubst -no-unset -i compose.login.yaml > "$tmp_login"
100+
{{docker}} compose -f "$tmp_main" -f "$tmp_login" up --detach \
101+
--remove-orphans --force-recreate
102+
rm -f "$tmp_main" "$tmp_login"
103+
just _echo-blue "FieldTM ${GIT_BRANCH} + self-hosted Hanko started successfully"
104+
else
105+
just _echo-blue "AUTH_PROVIDER=${auth_provider} detected, deploying without bundled login..."
106+
../envsubst -no-unset -i compose.sub.yaml | \
107+
{{docker}} compose -f - up --detach \
108+
--remove-orphans --force-recreate
109+
just _echo-blue "FieldTM ${GIT_BRANCH} started successfully"
110+
fi
116111

117112
# Production deploy with self-hosted ODK Central
118113
[no-cd]
119114
prod-with-odk:
120-
#!/usr/bin/env sh
115+
#!/usr/bin/env bash
121116
set -e
122117

118+
# Ensure PATH includes common binary locations (rootless docker, snap, etc.)
119+
export PATH="$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH"
120+
121+
if ! command -v {{docker}} >/dev/null 2>&1; then
122+
just _echo-red "'{{docker}}' not found. If using nerdctl, set DOCKER_ALIAS=nerdctl in .env"
123+
exit 1
124+
fi
125+
123126
just start _select-version
124127
export GIT_BRANCH=$(cat /tmp/.ftm_deploy_tag)
125128

@@ -128,7 +131,6 @@ prod-with-odk:
128131

129132
# Config
130133
just config generate-dotenv "${GIT_BRANCH}"
131-
just config custom-favicon
132134

133135
# Deploy core FieldTM + ODK Central addon
134136
../envsubst -no-unset -i compose.sub.yaml | \

0 commit comments

Comments
 (0)