Skip to content

Commit af90b47

Browse files
author
Naresh Thotakuri
committed
changes related to lower environment
1 parent 6cc127a commit af90b47

File tree

7 files changed

+219
-0
lines changed

7 files changed

+219
-0
lines changed

.github/workflows/pr-qa.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: QA Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- qa # Trigger PRs into the QA branch
7+
8+
env:
9+
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
10+
11+
jobs:
12+
lint:
13+
name: Lint
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@v4
18+
- name: Setup Python
19+
uses: actions/setup-python@v5
20+
- name: Format with Black
21+
uses: psf/black@stable
22+
with:
23+
options: ". -l 79 --check"
24+
25+
test_container_builds:
26+
name: Docker
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout repo
30+
uses: actions/checkout@v4
31+
- name: Log in to the Container registry
32+
uses: docker/login-action@v2
33+
with:
34+
registry: ghcr.io
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.POLICYENGINE_DOCKER }}
37+
- name: Build container
38+
run: docker build -t ghcr.io/policyengine/policyengine-qa docker
39+
40+
test_env_vars:
41+
name: Test environment variables
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout repo
45+
uses: actions/checkout@v4
46+
- name: Set up Python
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: "3.11"
50+
- name: Auth
51+
uses: google-github-actions/auth@v2
52+
with:
53+
credentials_json: ${{ secrets.GCP_SA_KEY }}
54+
- name: Install dependencies
55+
run: make install
56+
- name: Run environment variable tests
57+
run: pytest tests/env_variables/test_environment_variables.py
58+
env:
59+
POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN: ${{ secrets.POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN }}
60+
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
61+
POLICYENGINE_DB_PASSWORD: ${{ secrets.POLICYENGINE_DB_PASSWORD_QA }}

.github/workflows/push-qa.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Push QA
2+
3+
on:
4+
push:
5+
branches:
6+
- qa
7+
8+
env:
9+
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
10+
11+
concurrency:
12+
group: deploy-qa
13+
14+
jobs:
15+
lint:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v4
20+
- name: Check formatting
21+
uses: lgeiger/black-action@master
22+
with:
23+
args: ". -l 79 --check"
24+
25+
deploy:
26+
name: Deploy QA API
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout repo
30+
uses: actions/checkout@v4
31+
- name: Setup Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: "3.11"
35+
- name: GCP authentication
36+
uses: google-github-actions/auth@v2
37+
with:
38+
credentials_json: "${{ secrets.GCP_SA_KEY_QA }}"
39+
- name: Set up GCloud
40+
uses: google-github-actions/setup-gcloud@v2
41+
with:
42+
project_id: policyengine-api-qa
43+
- name: Deploy to QA
44+
run: make deploy
45+
env:
46+
POLICYENGINE_DB_PASSWORD: ${{ secrets.POLICYENGINE_DB_PASSWORD_QA }}
47+
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_SA_KEY_QA }}
48+
POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN: ${{ secrets.POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN }}
49+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
50+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
51+
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
52+
53+
docker:
54+
name: Docker QA
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: Checkout repo
58+
uses: actions/checkout@v4
59+
- name: Log in to the Container registry
60+
uses: docker/login-action@v2
61+
with:
62+
registry: ghcr.io
63+
username: ${{ github.actor }}
64+
password: ${{ secrets.POLICYENGINE_DOCKER }}
65+
- name: Build QA container
66+
run: docker build -t ghcr.io/policyengine/policyengine-qa docker
67+
- name: Push QA container
68+
run: docker push ghcr.io/policyengine/policyengine-qa

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.venv
2+
/venv
3+
__pycache__
24
**/__pycache__
35
*.egg-info
46
.pytest_cache

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ deploy:
2828
rm .gac.json
2929
rm .dbpw
3030

31+
deploy-qa:
32+
python gcp/export.py
33+
gcloud config set project your-qa-project-id
34+
gcloud config set app/cloud_build_timeout 2400
35+
cp gcp/policyengine_api_qa/* .
36+
y | gcloud app deploy --service-account=github-deployment@policyengine-api.iam.gserviceaccount.com
37+
rm app.yaml
38+
rm Dockerfile
39+
rm .gac.json
40+
rm .dbpw
41+
42+
3143
changelog:
3244
build-changelog changelog.yaml --output changelog.yaml --update-last-date --start-from 0.1.0 --append-file changelog_entry.yaml
3345
build-changelog changelog.yaml --org PolicyEngine --repo policyengine-api --output CHANGELOG.md --template .github/changelog_template.md

gcp/policyengine_api_qa/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM policyengine/policyengine-api:latest
2+
3+
ENV GOOGLE_APPLICATION_CREDENTIALS .gac.json
4+
ENV POLICYENGINE_DB_PASSWORD .dbpw
5+
ENV POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN .github_microdata_token
6+
ENV ANTHROPIC_API_KEY .anthropic_api_key
7+
ENV OPENAI_API_KEY .openai_api_key
8+
ENV HUGGING_FACE_TOKEN .hugging_face_token
9+
ENV CREDENTIALS_JSON_API_V2 .credentials_json_api_v2
10+
11+
WORKDIR /app
12+
13+
# Copy application
14+
ADD . /app
15+
16+
# Make start.sh executable
17+
RUN chmod +x /app/start.sh
18+
19+
RUN cd /app && make install && make test
20+
21+
# Use full path to start.sh
22+
CMD ["/bin/sh", "/app/start.sh"]

gcp/policyengine_api_qa/app.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
runtime: custom
2+
env: flex
3+
resources:
4+
cpu: 2
5+
memory_gb: 12
6+
disk_size_gb: 16
7+
automatic_scaling:
8+
min_num_instances: 1
9+
max_num_instances: 1
10+
cool_down_period_sec: 180
11+
cpu_utilization:
12+
target_utilization: 0.8
13+
liveness_check:
14+
path: "/liveness-check"
15+
check_interval_sec: 30
16+
timeout_sec: 30
17+
failure_threshold: 5
18+
success_threshold: 2
19+
runtime_config:
20+
operating_system: "ubuntu22"
21+
runtime_version: "22"
22+
readiness_check:
23+
path: "/readiness-check"
24+
app_start_timeout_sec: 600

gcp/policyengine_api_qa/start.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
# Environment variables
3+
PORT="${PORT:-8080}"
4+
WORKER_COUNT="${WORKER_COUNT:-3}"
5+
REDIS_PORT="${REDIS_PORT:-6379}"
6+
7+
# Start the API
8+
gunicorn -b :"$PORT" policyengine_api.api --timeout 300 --workers 5 &
9+
10+
# Start Redis with configuration for multiple clients
11+
redis-server --protected-mode no \
12+
--maxclients 10000 \
13+
--timeout 0 &
14+
15+
# Wait for Redis to be ready
16+
sleep 2
17+
18+
# Start multiple workers using POSIX-compliant loop
19+
i=1
20+
while [ $i -le "$WORKER_COUNT" ]
21+
do
22+
echo "Starting worker $i..."
23+
python3 policyengine_api/worker.py &
24+
i=$((i + 1))
25+
done
26+
27+
# Keep the script running and handle shutdown gracefully
28+
trap "pkill -P $$; exit 1" INT TERM
29+
30+
wait

0 commit comments

Comments
 (0)