Skip to content

Commit 2d937db

Browse files
committed
Separate deploy image build from push-time tests
1 parent 1112996 commit 2d937db

9 files changed

Lines changed: 63 additions & 10 deletions

File tree

.env.example

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Path to the Google_Application_Credentials file
2-
# Required to run the simulation API
3-
GOOGLE_APPLICATION_CREDENTIALS=/path/to/policyengine_gcp_credentials.json
1+
# For local development only, uncomment this if you need to point ADC at a
2+
# specific credential file. The deployed App Engine service uses its attached
3+
# service account instead.
4+
# GOOGLE_APPLICATION_CREDENTIALS=/path/to/policyengine_gcp_credentials.json
45

56
# Password for connecting to the PolicyEngine database
67
POLICYENGINE_DB_PASSWORD=policyengine_db_password
@@ -15,4 +16,4 @@ ANTHROPIC_API_KEY=policyengine_anthropic_api_key
1516
OPENAI_API_KEY=policyengine_openai_api_key
1617

1718
# Token for Hugging Face models
18-
HUGGING_FACE_TOKEN=policyengine_huggingface_token
19+
HUGGING_FACE_TOKEN=policyengine_huggingface_token
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
APP_ENGINE_IMAGE_TAG="${APP_ENGINE_IMAGE_TAG:-policyengine-api-app-engine:test}"
6+
7+
cleanup() {
8+
rm -f app.yaml Dockerfile start.sh .dbpw
9+
}
10+
11+
trap cleanup EXIT
12+
13+
bash .github/scripts/prepare_app_engine_bundle.sh
14+
15+
docker build -t "${APP_ENGINE_IMAGE_TAG}" .

.github/scripts/deploy_app_engine_version.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ APP_ENGINE_PROMOTE="${APP_ENGINE_PROMOTE:-0}"
88
APP_ENGINE_SERVICE_ACCOUNT="${APP_ENGINE_SERVICE_ACCOUNT:-github-deployment@policyengine-api.iam.gserviceaccount.com}"
99

1010
cleanup() {
11-
rm -f app.yaml Dockerfile start.sh .gac.json .dbpw
11+
rm -f app.yaml Dockerfile start.sh .dbpw
1212
}
1313

1414
trap cleanup EXIT
1515

16-
python gcp/export.py
17-
cp gcp/policyengine_api/app.yaml .
18-
cp gcp/policyengine_api/Dockerfile .
19-
cp gcp/policyengine_api/start.sh .
16+
bash .github/scripts/prepare_app_engine_bundle.sh
2017

2118
gcloud config set app/cloud_build_timeout 2400
2219

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
python gcp/export.py
6+
cp gcp/policyengine_api/app.yaml .
7+
cp gcp/policyengine_api/Dockerfile .
8+
cp gcp/policyengine_api/start.sh .

.github/workflows/push.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ jobs:
128128
uses: actions/setup-python@v5
129129
with:
130130
python-version: "3.12"
131+
- name: Install system dependencies
132+
run: sudo apt-get update && sudo apt-get install -y redis-server
133+
- name: Start Redis
134+
run: sudo systemctl start redis-server
131135
- name: Compute staging version name
132136
id: version
133137
run: |
@@ -139,6 +143,16 @@ jobs:
139143
service_account: "${{ secrets.GCP_DEPLOY_SERVICE_ACCOUNT }}"
140144
- name: Set up GCloud
141145
uses: "google-github-actions/setup-gcloud@v2"
146+
- name: Install dependencies
147+
run: make install
148+
- name: Run push-time tests
149+
run: make test
150+
env:
151+
POLICYENGINE_DB_PASSWORD: ${{ secrets.POLICYENGINE_DB_PASSWORD }}
152+
POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN: ${{ secrets.POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN }}
153+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
154+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
155+
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
142156
- name: Validate App Engine deployment configuration
143157
run: bash .github/scripts/validate_app_engine_deploy_env.sh
144158
env:
@@ -147,6 +161,20 @@ jobs:
147161
GATEWAY_AUTH_AUDIENCE: ${{ secrets.GATEWAY_AUTH_AUDIENCE }}
148162
GATEWAY_AUTH_CLIENT_ID: ${{ secrets.GATEWAY_AUTH_CLIENT_ID }}
149163
GATEWAY_AUTH_CLIENT_SECRET_RESOURCE: ${{ secrets.GATEWAY_AUTH_CLIENT_SECRET_RESOURCE }}
164+
- name: Build staging deploy image
165+
run: bash .github/scripts/build_app_engine_image.sh
166+
env:
167+
APP_ENGINE_IMAGE_TAG: policyengine-api:staging-${{ steps.version.outputs.version }}
168+
POLICYENGINE_DB_PASSWORD: ${{ secrets.POLICYENGINE_DB_PASSWORD }}
169+
POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN: ${{ secrets.POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN }}
170+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
171+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
172+
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
173+
SIMULATION_API_URL: ${{ secrets.SIMULATION_API_URL }}
174+
GATEWAY_AUTH_ISSUER: ${{ secrets.GATEWAY_AUTH_ISSUER }}
175+
GATEWAY_AUTH_AUDIENCE: ${{ secrets.GATEWAY_AUTH_AUDIENCE }}
176+
GATEWAY_AUTH_CLIENT_ID: ${{ secrets.GATEWAY_AUTH_CLIENT_ID }}
177+
GATEWAY_AUTH_CLIENT_SECRET_RESOURCE: ${{ secrets.GATEWAY_AUTH_CLIENT_SECRET_RESOURCE }}
150178
- name: Deploy staging version
151179
run: bash .github/scripts/deploy_app_engine_version.sh
152180
env:

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
install:
22
pip install -e ".[dev]"
3+
4+
setup-env:
35
bash .github/setup_env.sh
46

57
debug:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ To contribute, clone the repository instead of forking it and then request to be
3232

3333
```
3434
make install
35+
make setup-env
3536
```
3637

3738
### 4. Start a server on localhost to see your changes
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move push-time API tests out of the App Engine Docker build and run them in sequence within the staging deploy workflow before the actual deploy.

gcp/policyengine_api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ADD . /app
2323
# Make start.sh executable
2424
RUN chmod +x /app/start.sh
2525

26-
RUN cd /app && make install && make test
26+
RUN cd /app && make install
2727

2828
# Use full path to start.sh
2929
CMD ["/bin/sh", "/app/start.sh"]

0 commit comments

Comments
 (0)