Skip to content

Commit b16e786

Browse files
committed
improve: Enhance fly.io deployment cache busting reliability
- Add stronger cache busting in deploy_fly.sh with timestamp+random values - Make Dockerfile actually use CACHEBUST argument to invalidate Docker layers - Improve Makefile fresh deployment targets to clear builder cache - Add explicit dockerfile paths to avoid build confusion These changes ensure --force-rebuild actually forces a complete rebuild, preventing cached layers from causing deployment issues like we experienced with the Dagster config fix.
1 parent bdd2dda commit b16e786

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,24 @@ fly-deploy-development:
216216
fly-deploy-demo-fresh:
217217
@echo "🧹 Cleaning local Docker cache to ensure fresh build..."
218218
docker system prune -f --filter "until=1h"
219+
@echo "🧹 Cleaning Docker builder cache..."
220+
docker builder prune -f 2>/dev/null || true
219221
./scripts/deployment/deploy_fly.sh --profile demo --force-rebuild
220222

221223
# deploy with fresh build (clears local Docker cache first) - production profile
222224
fly-deploy-production-fresh:
223225
@echo "🧹 Cleaning local Docker cache to ensure fresh build..."
224226
docker system prune -f --filter "until=1h"
227+
@echo "🧹 Cleaning Docker builder cache..."
228+
docker builder prune -f 2>/dev/null || true
225229
./scripts/deployment/deploy_fly.sh --profile production --force-rebuild
226230

227231
# deploy with fresh build (clears local Docker cache first) - development profile
228232
fly-deploy-development-fresh:
229233
@echo "🧹 Cleaning local Docker cache to ensure fresh build..."
230234
docker system prune -f --filter "until=1h"
235+
@echo "🧹 Cleaning Docker builder cache..."
236+
docker builder prune -f 2>/dev/null || true
231237
./scripts/deployment/deploy_fly.sh --profile development --force-rebuild
232238

233239
# test fly.io build locally before deploying (helps catch issues early)

docker/Dockerfile.fly

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ FROM python:3.12-slim
33
# Cache busting argument (set during build to force fresh layers)
44
ARG CACHEBUST=1
55

6+
# Use CACHEBUST to invalidate cache when needed (this layer changes when CACHEBUST changes)
7+
RUN echo "Cache bust: $CACHEBUST" > /tmp/cachebust
8+
69
# Install system dependencies including nginx
710
RUN apt-get update && apt-get install -y --no-install-recommends \
811
git \

scripts/deployment/deploy_fly.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,23 @@ rm fly.toml.bak
235235
echo "🚀 Deploying application..."
236236

237237
if [[ "$FORCE_REBUILD" == "true" ]]; then
238+
# Generate unique cache busting value with timestamp + random
239+
CACHEBUST_VALUE="$(date +%s)-$(openssl rand -hex 4 2>/dev/null || echo $RANDOM)"
238240
echo "🔄 Force rebuild enabled - using aggressive cache busting..."
239-
fly deploy --no-cache --build-arg CACHEBUST="$(date +%s)" -a "$APP_NAME"
241+
echo "🎯 Cache bust value: $CACHEBUST_VALUE"
242+
243+
# Use multiple cache busting strategies:
244+
# 1. --no-cache: Skip Docker layer cache
245+
# 2. CACHEBUST build arg: Force rebuild of layers that use it
246+
# 3. --dockerfile: Explicit dockerfile path to avoid confusion
247+
fly deploy \
248+
--no-cache \
249+
--build-arg CACHEBUST="$CACHEBUST_VALUE" \
250+
--dockerfile docker/Dockerfile.fly \
251+
-a "$APP_NAME"
240252
else
241-
fly deploy --no-cache -a "$APP_NAME"
253+
echo "⚡ Standard deployment (with caching)..."
254+
fly deploy --dockerfile docker/Dockerfile.fly -a "$APP_NAME"
242255
fi
243256

244257
# Show the status

0 commit comments

Comments
 (0)