Fix compose env var interpolation with --env-file flag

Docker Compose reads ${VAR} interpolation from .env by default,
not from the env_file directive (which only sets container vars).
Added --env-file .env.production to all docker compose commands
so POSTGRES_USER, POSTGRES_PASSWORD, etc. are available for
compose file interpolation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
JP Scott
2026-03-01 14:32:25 -07:00
parent 44c70e7825
commit 9212fd4acd

View File

@@ -17,6 +17,11 @@ NC='\033[0m' # No Color
COMPOSE_FILE="docker-compose.prod.yml" COMPOSE_FILE="docker-compose.prod.yml"
ENV_FILE=".env.production" ENV_FILE=".env.production"
# Helper: full docker compose command with env file
dc() {
${DOCKER_SUDO:-} docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" "$@"
}
# ─── Helpers ───────────────────────────────────────────────── # ─── Helpers ─────────────────────────────────────────────────
info() { echo -e "${BLUE}[INFO]${NC} $*"; } info() { echo -e "${BLUE}[INFO]${NC} $*"; }
@@ -294,13 +299,13 @@ echo ""
info "Building Docker images (this may take a few minutes on first run)..." info "Building Docker images (this may take a few minutes on first run)..."
echo "" echo ""
${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" build --no-cache dc build --no-cache
echo "" echo ""
info "Starting services..." info "Starting services..."
echo "" echo ""
${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" up -d dc up -d
# ─── Step 6: Health Check ─────────────────────────────────── # ─── Step 6: Health Check ───────────────────────────────────
@@ -313,11 +318,11 @@ INTERVAL=5
while [[ $ELAPSED -lt $MAX_WAIT ]]; do while [[ $ELAPSED -lt $MAX_WAIT ]]; do
# Check database # Check database
DB_HEALTHY=$(${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" ps --format json 2>/dev/null | \ DB_HEALTHY=$(dc ps --format json 2>/dev/null | \
grep -o '"db"[^}]*"healthy"' 2>/dev/null && echo "yes" || echo "no") grep -o '"db"[^}]*"healthy"' 2>/dev/null && echo "yes" || echo "no")
# Check app # Check app
APP_RUNNING=$(${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" ps --status running --format json 2>/dev/null | \ APP_RUNNING=$(dc ps --status running --format json 2>/dev/null | \
grep -o '"app"' 2>/dev/null && echo "yes" || echo "no") grep -o '"app"' 2>/dev/null && echo "yes" || echo "no")
if [[ "$DB_HEALTHY" == *"yes"* ]] && [[ "$APP_RUNNING" == *"yes"* ]]; then if [[ "$DB_HEALTHY" == *"yes"* ]] && [[ "$APP_RUNNING" == *"yes"* ]]; then
@@ -335,7 +340,7 @@ echo ""
SERVICES_UP=true SERVICES_UP=true
for service in db minio app; do for service in db minio app; do
STATUS=$(${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" ps "$service" --format "{{.Status}}" 2>/dev/null || echo "not found") STATUS=$(dc ps "$service" --format "{{.Status}}" 2>/dev/null || echo "not found")
if echo "$STATUS" | grep -qi "up\|running\|healthy"; then if echo "$STATUS" | grep -qi "up\|running\|healthy"; then
success "$service: $STATUS" success "$service: $STATUS"
else else
@@ -345,17 +350,17 @@ for service in db minio app; do
done done
# Check migrate completed # Check migrate completed
MIGRATE_STATUS=$(${DOCKER_SUDO} docker compose -f "$COMPOSE_FILE" ps migrate --format "{{.Status}}" 2>/dev/null || echo "not found") MIGRATE_STATUS=$(dc ps migrate --format "{{.Status}}" 2>/dev/null || echo "not found")
if echo "$MIGRATE_STATUS" | grep -qi "exited (0)\|completed"; then if echo "$MIGRATE_STATUS" | grep -qi "exited (0)\|completed"; then
success "migrate: completed successfully" success "migrate: completed successfully"
else else
warn "migrate: $MIGRATE_STATUS (check logs: ${DOCKER_SUDO} docker compose -f $COMPOSE_FILE logs migrate)" warn "migrate: $MIGRATE_STATUS (check logs: docker compose --env-file $ENV_FILE -f $COMPOSE_FILE logs migrate)"
fi fi
if [[ "$SERVICES_UP" == "false" ]]; then if [[ "$SERVICES_UP" == "false" ]]; then
echo "" echo ""
error "Some services failed to start. Check logs:" error "Some services failed to start. Check logs:"
echo " ${DOCKER_SUDO} docker compose -f $COMPOSE_FILE logs" echo " docker compose --env-file $ENV_FILE -f $COMPOSE_FILE logs"
exit 1 exit 1
fi fi
@@ -388,11 +393,12 @@ echo ""
echo -e " ${BOLD}App URL:${NC} ${APP_URL_CHECK}" echo -e " ${BOLD}App URL:${NC} ${APP_URL_CHECK}"
echo -e " ${BOLD}Config file:${NC} $(pwd)/$ENV_FILE" echo -e " ${BOLD}Config file:${NC} $(pwd)/$ENV_FILE"
echo "" echo ""
DC_CMD="docker compose --env-file $ENV_FILE -f $COMPOSE_FILE"
echo -e " ${BOLD}Useful commands:${NC}" echo -e " ${BOLD}Useful commands:${NC}"
echo " View logs: docker compose -f $COMPOSE_FILE logs -f" echo " View logs: $DC_CMD logs -f"
echo " Stop: docker compose -f $COMPOSE_FILE down" echo " Stop: $DC_CMD down"
echo " Restart: docker compose -f $COMPOSE_FILE restart" echo " Restart: $DC_CMD restart"
echo " Rebuild: docker compose -f $COMPOSE_FILE up -d --build" echo " Rebuild: $DC_CMD up -d --build"
echo "" echo ""
echo -e " ${BOLD}${YELLOW}Next steps:${NC}" echo -e " ${BOLD}${YELLOW}Next steps:${NC}"
echo " 1. Open ${APP_URL_CHECK} and create your account" echo " 1. Open ${APP_URL_CHECK} and create your account"