Skip to content

Commit d31fe15

Browse files
fix(deploy): only build shared image on api service to avoid BuildKit race
BuildKit has a race condition (moby/buildkit#6477) where parallel builds of the same image tag collide on Create. Only the api service now has the build config; app, chat, scheduler depend on api and reference the pre-built image by tag. Also removes the ineffective docker image rm workaround.
1 parent 2039c38 commit d31fe15

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

docker-compose.app.yml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
#
1010
# Required env vars: DEPLOY_COLOR (blue|green), plus all vars from .env
1111

12-
# Shared image build configuration - all Python services use the same image
13-
x-app-build: &app-build
12+
# Shared image reference - only the api service builds this image,
13+
# other services reference it by tag. This avoids a BuildKit race condition
14+
# where parallel builds of the same tag collide (moby/buildkit#6477).
15+
x-app-image: &app-image
1416
image: ichrisbirch:${DEPLOY_COLOR}
15-
build:
16-
context: .
17-
target: production
1817

1918
x-logging: &logging
2019
driver: "json-file"
@@ -23,9 +22,12 @@ x-logging: &logging
2322
max-file: "3"
2423

2524
services:
26-
# FastAPI Backend Service
25+
# FastAPI Backend Service — builds the shared Python image
2726
api:
28-
<<: *app-build
27+
<<: *app-image
28+
build:
29+
context: .
30+
target: production
2931
container_name: icb-${DEPLOY_COLOR}-api
3032
command: uvicorn ichrisbirch.wsgi_api:api --host 0.0.0.0 --port 8000 --workers 4 --no-access-log
3133
env_file: .env
@@ -91,8 +93,10 @@ services:
9193

9294
# Flask Frontend Service (legacy, lower priority)
9395
app:
94-
<<: *app-build
96+
<<: *app-image
9597
container_name: icb-${DEPLOY_COLOR}-app
98+
depends_on:
99+
- api
96100
command: gunicorn --bind 0.0.0.0:5000 --workers 4 --timeout 180 ichrisbirch.wsgi_app:app
97101
env_file: .env
98102
environment:
@@ -128,8 +132,10 @@ services:
128132

129133
# Chat Service (Streamlit)
130134
chat:
131-
<<: *app-build
135+
<<: *app-image
132136
container_name: icb-${DEPLOY_COLOR}-chat
137+
depends_on:
138+
- api
133139
command: streamlit run ichrisbirch/chat/app.py --server.address=0.0.0.0 --server.port=8505 --server.headless=true
134140
env_file: .env
135141
environment:
@@ -160,8 +166,10 @@ services:
160166

161167
# Scheduler Service (APScheduler background jobs)
162168
scheduler:
163-
<<: *app-build
169+
<<: *app-image
164170
container_name: icb-${DEPLOY_COLOR}-scheduler
171+
depends_on:
172+
- api
165173
command: python -m ichrisbirch.wsgi_scheduler
166174
env_file: .env
167175
environment:

scripts/deploy-homelab.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,6 @@ build_new_images() {
246246
log_info "build_started" "color" "$DEPLOY_COLOR" | tee -a "$LOG_FILE"
247247
cd "$INSTALL_DIR"
248248

249-
# Remove any stale images from a previous failed build to avoid
250-
# "image already exists" errors with BuildKit shared image builds
251-
docker image rm "ichrisbirch:${DEPLOY_COLOR}" 2>/dev/null || true
252-
docker image rm "ichrisbirch-vue:${DEPLOY_COLOR}" 2>/dev/null || true
253-
254249
local build_log="${LOG_DIR}/build-$(date +%Y%m%d-%H%M%S).log"
255250

256251
if ! compose_app "$DEPLOY_COLOR" build 2>&1 | tee "$build_log"; then

0 commit comments

Comments
 (0)