feat: Add service.yaml and improve push_test script #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Push Testing for Cloud Run | |
on: | |
push: | |
branches: | |
- feat/cloud_run | |
env: | |
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true | |
PROJECT_ID: policyengine-api | |
SERVICE_NAME: policyengine-api-cloud-run-test | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
# Temporarily disable | |
# lint: | |
# runs-on: ubuntu-latest | |
# if: | | |
# (github.repository == 'PolicyEngine/policyengine-uk') | |
# && (github.event.head_commit.message == 'Update PolicyEngine API') | |
# steps: | |
# - name: Checkout repo | |
# uses: actions/checkout@v3 | |
# - name: Check formatting | |
# uses: "lgeiger/black-action@master" | |
# with: | |
# args: ". -l 79 --check" | |
# versioning: | |
# name: Update versioning | |
# if: | | |
# (github.repository == 'PolicyEngine/policyengine-api') | |
# && !(github.event.head_commit.message == 'Update PolicyEngine API') | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Checkout repo | |
# uses: actions/checkout@v3 | |
# with: | |
# repository: ${{ github.event.pull_request.head.repo.full_name }} | |
# ref: ${{ github.event.pull_request.head.ref }} | |
# token: ${{ secrets.POLICYENGINE_GITHUB }} | |
# - name: Setup Python | |
# uses: actions/setup-python@v5 | |
# with: | |
# python-version: "3.10" | |
# - name: Build changelog | |
# run: pip install yaml-changelog && make changelog | |
# - name: Preview changelog update | |
# run: ".github/get-changelog-diff.sh" | |
# - name: Update changelog | |
# uses: EndBug/add-and-commit@v9 | |
# with: | |
# add: "." | |
# committer_name: Github Actions[bot] | |
# author_name: Github Actions[bot] | |
# message: Update PolicyEngine API | |
deploy: | |
name: Deploy API to Cloud Run | |
runs-on: ubuntu-latest | |
if: | | |
(github.repository == 'PolicyEngine/policyengine-api') | |
&& (github.event.head_commit.message == 'Update PolicyEngine API') | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Log in to the Container registry | |
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Setup Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@v1 | |
with: | |
project_id: ${{ env.PROJECT_ID }} | |
service_account_key: ${{ secrets.GCP_SA_KEY }} | |
- name: Prepare service.yaml | |
run: | | |
sed -i 's|${SERVICE_NAME}|${{ env.SERVICE_NAME }}|g' service.yaml | |
sed -i 's|${REGISTRY}|${{ env.REGISTRY }}|g' service.yaml | |
sed -i 's|${IMAGE_NAME}|${{ env.IMAGE_NAME }}|g' service.yaml | |
sed -i 's|${IMAGE_TAG}|${{ github.sha }}|g' service.yaml | |
- name: Deploy to Cloud Run | |
run: | | |
gcloud run services replace service.yaml \ | |
--platform managed \ | |
--region us-central1 | |
- name: Set up secrets in Secret Manager | |
run: | | |
echo "${{ secrets.POLICYENGINE_DB_PASSWORD }}" | gcloud secrets create policyengine-db-password --data-file=- || gcloud secrets versions add policyengine-db-password --data-file=- | |
echo "${{ secrets.POLICYENGINE_GITHUB_MICRODATA_AUTH_TOKEN }}" | gcloud secrets create policyengine-github-microdata-auth-token --data-file=- || gcloud secrets versions add policyengine-github-microdata-auth-token --data-file=- | |
echo "${{ secrets.ANTHROPIC_API_KEY }}" | gcloud secrets create anthropic-api-key --data-file=- || gcloud secrets versions add anthropic-api-key --data-file=- | |
echo "${{ secrets.OPENAI_API_KEY }}" | gcloud secrets create openai-api-key --data-file=- || gcloud secrets versions add openai-api-key --data-file=- | |
# Temporary disable | |
# docker: | |
# name: Docker | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Checkout repo | |
# uses: actions/checkout@v3 | |
# - name: Log in to the Container registry | |
# uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | |
# with: | |
# registry: ghcr.io | |
# username: ${{ github.actor }} | |
# password: ${{ secrets.POLICYENGINE_DOCKER }} | |
# - name: Build container | |
# run: docker build -t ghcr.io/policyengine/policyengine docker | |
# - name: Push container | |
# run: docker push ghcr.io/policyengine/policyengine |