Skip to content

Commit a53ab54

Browse files
committed
refactor: replace hardcoded recipes with envsubst template
Single template (zerops-import.yml.tpl) + per-environment env files (env-dev.env, env-stage.env, env-prod.env). Lines with empty values are stripped automatically, so optional fields (corePackage, cpuMode, minContainers, envSecrets) only appear when the env file sets them. Removes the three separate zerops-import-{dev,stage,prod}.yml files.
1 parent 5565b92 commit a53ab54

9 files changed

Lines changed: 267 additions & 141 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ jobs:
8181
PROJECT_NAME="showcase-dev-${BRANCH_SLUG}"
8282
echo "Project: ${PROJECT_NAME}"
8383
84-
zerops_ensure_project "$ZEROPS_CLIENT_ID" "$PROJECT_NAME" \
85-
zerops/recipes/zerops-import-dev.yml 300
84+
zerops_render_template zerops/recipes/zerops-import.yml.tpl \
85+
zerops/recipes/env-dev.env "$PROJECT_NAME"
86+
zerops_ensure_project "$ZEROPS_CLIENT_ID" "$PROJECT_NAME" "" 300
8687
8788
zerops_find_service "$PROJECT_ID" "$APP_SERVICE_NAME"
8889
zerops_deploy_service "$SERVICE_FOUND_ID" ./app ./app/zerops.yml "$ZEROPS_YAML_SETUP"
@@ -141,8 +142,9 @@ jobs:
141142
PROJECT_NAME="showcase-prod"
142143
echo "Project: ${PROJECT_NAME}"
143144
144-
zerops_ensure_project "$ZEROPS_CLIENT_ID" "$PROJECT_NAME" \
145-
zerops/recipes/zerops-import-prod.yml 300
145+
zerops_render_template zerops/recipes/zerops-import.yml.tpl \
146+
zerops/recipes/env-prod.env "$PROJECT_NAME"
147+
zerops_ensure_project "$ZEROPS_CLIENT_ID" "$PROJECT_NAME" "" 300
146148
147149
zerops_find_service "$PROJECT_ID" "$APP_SERVICE_NAME"
148150
zerops_deploy_service "$SERVICE_FOUND_ID" ./app ./app/zerops.yml "$ZEROPS_YAML_SETUP"
@@ -203,8 +205,9 @@ jobs:
203205
PROJECT_NAME="showcase-mr-${PR_NUMBER}"
204206
echo "Project: ${PROJECT_NAME}"
205207
206-
zerops_ensure_project "$ZEROPS_CLIENT_ID" "$PROJECT_NAME" \
207-
zerops/recipes/zerops-import-stage.yml 300
208+
zerops_render_template zerops/recipes/zerops-import.yml.tpl \
209+
zerops/recipes/env-stage.env "$PROJECT_NAME"
210+
zerops_ensure_project "$ZEROPS_CLIENT_ID" "$PROJECT_NAME" "" 300
208211
209212
zerops_find_service "$PROJECT_ID" "$APP_SERVICE_NAME"
210213
zerops_deploy_service "$SERVICE_FOUND_ID" ./app ./app/zerops.yml "$ZEROPS_YAML_SETUP"
@@ -299,8 +302,9 @@ jobs:
299302
PROJECT_NAME="showcase-stage"
300303
echo "Project: ${PROJECT_NAME}"
301304
302-
zerops_ensure_project "$ZEROPS_CLIENT_ID" "$PROJECT_NAME" \
303-
zerops/recipes/zerops-import-stage.yml 300
305+
zerops_render_template zerops/recipes/zerops-import.yml.tpl \
306+
zerops/recipes/env-stage.env "$PROJECT_NAME"
307+
zerops_ensure_project "$ZEROPS_CLIENT_ID" "$PROJECT_NAME" "" 300
304308
305309
zerops_find_service "$PROJECT_ID" "$APP_SERVICE_NAME"
306310
zerops_deploy_service "$SERVICE_FOUND_ID" ./app ./app/zerops.yml "$ZEROPS_YAML_SETUP"

zerops/recipes/env-dev.env

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Environment: dev — lightweight, single-instance, shared CPU
2+
# Used for feature-branch environments (showcase-dev-*)
3+
4+
# Project
5+
CORE_PACKAGE=
6+
7+
# App service
8+
APP_TYPE=bun@1.2
9+
APP_CORE_MODE=
10+
APP_MIN_CONTAINERS=
11+
APP_MAX_CONTAINERS=
12+
APP_CPU_MODE=
13+
APP_MIN_RAM=0.5
14+
APP_MIN_FREE_RAM=0.25
15+
16+
# Worker service
17+
WORKER_TYPE=python@3.12
18+
WORKER_MIN_CONTAINERS=
19+
WORKER_MAX_CONTAINERS=
20+
WORKER_CPU_MODE=
21+
WORKER_MIN_RAM=0.5
22+
WORKER_MIN_FREE_RAM=
23+
24+
# Database
25+
DB_TYPE=postgresql@17
26+
DB_MODE=NON_HA
27+
DB_CPU_MODE=
28+
DB_MIN_RAM=
29+
DB_MIN_FREE_RAM=
30+
31+
# Redis / Valkey
32+
REDIS_TYPE=valkey@7.2
33+
REDIS_MODE=NON_HA
34+
35+
# Message queue
36+
QUEUE_TYPE=nats@2.12
37+
QUEUE_MODE=NON_HA
38+
39+
# Object storage
40+
STORAGE_SIZE=2
41+
STORAGE_POLICY=public-read

zerops/recipes/env-prod.env

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Environment: prod — full HA, dedicated CPU, auto-scaling
2+
# Used for the production environment (showcase-prod)
3+
4+
# Project
5+
CORE_PACKAGE=SERIOUS
6+
7+
# App service
8+
APP_TYPE=bun@1.2
9+
APP_CORE_MODE=serious
10+
APP_MIN_CONTAINERS=2
11+
APP_MAX_CONTAINERS=6
12+
APP_CPU_MODE=DEDICATED
13+
APP_MIN_RAM=1
14+
APP_MIN_FREE_RAM=0.5
15+
16+
# Worker service
17+
WORKER_TYPE=python@3.12
18+
WORKER_MIN_CONTAINERS=2
19+
WORKER_MAX_CONTAINERS=6
20+
WORKER_CPU_MODE=DEDICATED
21+
WORKER_MIN_RAM=1
22+
WORKER_MIN_FREE_RAM=0.5
23+
24+
# Database
25+
DB_TYPE=postgresql@17
26+
DB_MODE=HA
27+
DB_CPU_MODE=DEDICATED
28+
DB_MIN_RAM=2
29+
DB_MIN_FREE_RAM=1
30+
31+
# Redis / Valkey
32+
REDIS_TYPE=valkey@7.2
33+
REDIS_MODE=HA
34+
35+
# Message queue
36+
QUEUE_TYPE=nats@2.12
37+
QUEUE_MODE=HA
38+
39+
# Object storage
40+
STORAGE_SIZE=10
41+
STORAGE_POLICY=public-read

zerops/recipes/env-stage.env

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Environment: stage — mid-tier, single-instance, shared CPU
2+
# Used for the shared staging environment (showcase-stage, showcase-mr-*)
3+
4+
# Project
5+
CORE_PACKAGE=
6+
7+
# App service
8+
APP_TYPE=bun@1.2
9+
APP_CORE_MODE=serious
10+
APP_MIN_CONTAINERS=
11+
APP_MAX_CONTAINERS=
12+
APP_CPU_MODE=
13+
APP_MIN_RAM=0.5
14+
APP_MIN_FREE_RAM=0.25
15+
16+
# Worker service
17+
WORKER_TYPE=python@3.12
18+
WORKER_MIN_CONTAINERS=
19+
WORKER_MAX_CONTAINERS=
20+
WORKER_CPU_MODE=
21+
WORKER_MIN_RAM=0.5
22+
WORKER_MIN_FREE_RAM=
23+
24+
# Database
25+
DB_TYPE=postgresql@17
26+
DB_MODE=NON_HA
27+
DB_CPU_MODE=
28+
DB_MIN_RAM=
29+
DB_MIN_FREE_RAM=
30+
31+
# Redis / Valkey
32+
REDIS_TYPE=valkey@7.2
33+
REDIS_MODE=NON_HA
34+
35+
# Message queue
36+
QUEUE_TYPE=nats@2.12
37+
QUEUE_MODE=NON_HA
38+
39+
# Object storage
40+
STORAGE_SIZE=2
41+
STORAGE_POLICY=public-read

zerops/recipes/zerops-import-dev.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

zerops/recipes/zerops-import-prod.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

zerops/recipes/zerops-import-stage.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
project:
2+
name: ${PROJECT_NAME}
3+
corePackage: ${CORE_PACKAGE}
4+
5+
services:
6+
- hostname: app
7+
type: ${APP_TYPE}
8+
enableSubdomainAccess: true
9+
envSecrets:
10+
CORE_MODE: ${APP_CORE_MODE}
11+
minContainers: ${APP_MIN_CONTAINERS}
12+
maxContainers: ${APP_MAX_CONTAINERS}
13+
verticalAutoscaling:
14+
cpuMode: ${APP_CPU_MODE}
15+
minRam: ${APP_MIN_RAM}
16+
minFreeRamGB: ${APP_MIN_FREE_RAM}
17+
18+
- hostname: worker
19+
type: ${WORKER_TYPE}
20+
minContainers: ${WORKER_MIN_CONTAINERS}
21+
maxContainers: ${WORKER_MAX_CONTAINERS}
22+
verticalAutoscaling:
23+
cpuMode: ${WORKER_CPU_MODE}
24+
minRam: ${WORKER_MIN_RAM}
25+
minFreeRamGB: ${WORKER_MIN_FREE_RAM}
26+
27+
- hostname: db
28+
type: ${DB_TYPE}
29+
mode: ${DB_MODE}
30+
priority: 10
31+
verticalAutoscaling:
32+
cpuMode: ${DB_CPU_MODE}
33+
minRam: ${DB_MIN_RAM}
34+
minFreeRamGB: ${DB_MIN_FREE_RAM}
35+
36+
- hostname: redis
37+
type: ${REDIS_TYPE}
38+
mode: ${REDIS_MODE}
39+
priority: 10
40+
41+
- hostname: queue
42+
type: ${QUEUE_TYPE}
43+
mode: ${QUEUE_MODE}
44+
priority: 10
45+
46+
- hostname: storage
47+
type: object-storage
48+
objectStorageSize: ${STORAGE_SIZE}
49+
objectStoragePolicy: ${STORAGE_POLICY}
50+
priority: 10

0 commit comments

Comments
 (0)