Skip to content

Commit 4efc0c6

Browse files
authored
Merge pull request #862 from PolicyEngine/fix/resolve-deploy-error
Various fixes to Dockerfile and GCP
2 parents 75359c1 + fd0af64 commit 4efc0c6

5 files changed

Lines changed: 51 additions & 43 deletions

File tree

.github/scripts/deploy-app-engine.sh

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,25 @@ echo "Image: $IMAGE_NAME:$IMAGE_TAG"
2323
echo "Version: $IMAGE_TAG"
2424
echo "Service Account: $SERVICE_ACCOUNT"
2525
echo "App YAML: $APP_YAML_PATH"
26-
# Define environment variables to set
27-
declare -A ENV_VARS=(
28-
["AUTH0_ADDRESS_NO_DOMAIN"]="$AUTH0_ADDRESS_NO_DOMAIN"
29-
["AUTH0_AUDIENCE_NO_DOMAIN"]="$AUTH0_AUDIENCE_NO_DOMAIN"
30-
["USER_ANALYTICS_DB_USERNAME"]="$USER_ANALYTICS_DB_USERNAME"
31-
["USER_ANALYTICS_DB_PASSWORD"]="$USER_ANALYTICS_DB_PASSWORD"
32-
["USER_ANALYTICS_DB_CONNECTION_NAME"]="$USER_ANALYTICS_DB_CONNECTION_NAME"
33-
["ANTHROPIC_API_KEY"]="$ANTHROPIC_API_KEY"
34-
)
35-
36-
# Deploy to App Engine using the pre-built image
37-
gcloud app deploy "$APP_YAML_PATH" \
26+
27+
# Check that Auth0 environment variables are set
28+
if [ -z "$AUTH0_ADDRESS_NO_DOMAIN" ] || [ -z "$AUTH0_AUDIENCE_NO_DOMAIN" ]; then
29+
echo "Error: Auth0 environment variables not set"
30+
exit 1
31+
fi
32+
33+
echo "Substituting environment variables in app.yaml..."
34+
TEMP_APP_YAML=$(mktemp)
35+
envsubst < "$APP_YAML_PATH" > "$TEMP_APP_YAML"
36+
37+
# Deploy to App Engine using the substituted app.yaml
38+
gcloud app deploy "$TEMP_APP_YAML" \
3839
--image-url="$IMAGE_NAME:$IMAGE_TAG" \
3940
--version="$IMAGE_TAG" \
4041
--service-account="$SERVICE_ACCOUNT" \
4142
--quiet
4243

43-
echo "App Engine deployment completed successfully"
44+
# Clean up
45+
rm "$TEMP_APP_YAML"
46+
47+
echo "App Engine deployment completed successfully"

changelog_entry.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- bump: patch
2+
changes:
3+
changed:
4+
- Made various fixes to Dockerfile and GCP deployment scripts.
Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
11
#----------------- Build stage -----------------
2-
# Stage used to compile code and install dependencies
3-
FROM python:3.12-slim AS builder
2+
FROM --platform=linux/amd64 python:3.12-slim AS builder
43
WORKDIR /build
54
COPY . .
6-
5+
76
# Install build dependencies
87
RUN apt-get update && apt-get install -y build-essential
98
RUN rm -rf /var/lib/apt/lists/*
10-
9+
1110
# Create virtual environment
1211
RUN python -m venv /opt/venv
1312
ENV PATH="/opt/venv/bin:$PATH"
14-
13+
1514
# Install Python dependencies
1615
RUN pip install --no-cache-dir --upgrade pip
1716
RUN pip install -e .
18-
17+
1918
#----------------- Production stage -----------------
20-
# Stage used to run the application
21-
FROM python:3.12-slim AS production
19+
FROM --platform=linux/amd64 python:3.12-slim AS production
2220
WORKDIR /app
23-
21+
2422
# Install runtime system dependencies
2523
RUN apt-get update && apt-get install -y --no-install-recommends curl
2624
RUN rm -rf /var/lib/apt/lists/*
27-
28-
# Create user and set permissions; don't run as root for security reasons
29-
RUN groupadd -r appuser && useradd -r -g appuser appuser
30-
31-
# Copy only the necessary artifacts from the build stage
25+
26+
# Copy artifacts from build stage
3227
COPY --from=builder /opt/venv /opt/venv
3328
COPY --from=builder /build/policyengine_household_api /app/policyengine_household_api
34-
35-
# Copy the startup script from the existing GCP configuration
29+
30+
# Copy startup script
3631
COPY ./gcp/policyengine_household_api/start.sh /app/start.sh
37-
38-
# Make startup script executable and set ownership
3932
RUN chmod +x /app/start.sh
40-
RUN chown -R appuser:appuser /app
41-
USER appuser
42-
43-
# Configure environment
33+
34+
# Configure environment (runs as root by default)
4435
ENV PATH="/opt/venv/bin:$PATH"
4536
EXPOSE 8080
46-
47-
# Use the startup script from the existing GCP configuration
37+
4838
CMD ["/app/start.sh"]

gcp/policyengine_household_api/app.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ automatic_scaling:
1010
cool_down_period_sec: 180
1111
cpu_utilization:
1212
target_utilization: 0.8
13+
readiness_check:
14+
app_start_timeout_sec: 1800 # Maximum allowed (30 minutes)
15+
check_interval_sec: 30
16+
timeout_sec: 10
17+
failure_threshold: 5
18+
success_threshold: 1
1319
liveness_check:
20+
initial_delay_sec: 300 # Give app time to fully start
1421
check_interval_sec: 30
15-
timeout_sec: 30
22+
timeout_sec: 10
1623
failure_threshold: 5
17-
success_threshold: 2
18-
readiness_check:
19-
path: "/readiness-check"
20-
app_start_timeout_sec: 600
24+
success_threshold: 1
2125
env_variables:
2226
AUTH0_ADDRESS_NO_DOMAIN: ${AUTH0_ADDRESS_NO_DOMAIN}
2327
AUTH0_AUDIENCE_NO_DOMAIN: ${AUTH0_AUDIENCE_NO_DOMAIN}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Set the port to use
5+
PORT=${PORT:-8080}
6+
17
# Start the API
2-
gunicorn -b :$PORT policyengine_household_api.api --timeout 300 --workers 2
8+
exec gunicorn -b :$PORT policyengine_household_api.api --timeout 300 --workers 2

0 commit comments

Comments
 (0)