Skip to content

Commit

Permalink
ci(palletjack): switch to cloud run job
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Oct 3, 2024
1 parent 58b4ce3 commit 81912a8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 44 deletions.
89 changes: 49 additions & 40 deletions .github/actions/palletjack/deploy/action.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,84 @@
name: Deploy Palletjack Skid to GCF
description: Deploy Palletjack Skid to Google Cloud Function and Cloud Scheduler
inputs:
schedule:
description: Cloud Scheduler cron schedule
project_id:
description: 'The GCP project ID'
required: true
identity_provider:
description: gcp federation identity provider
description: 'The identity provider for the workload identity'
required: true
service_account_email:
description: gcp service account email
required: true
project_id:
description: gcp project id
description: 'The service account email'
required: true
pause_schedule_job:
description: 'Pause the scheduler job'
required: false
default: 'no'

runs:
using: composite
steps:
- name: Set globals
id: globals
shell: bash
run: |
echo "TOPIC_NAME=palletjack-topic" >> "${GITHUB_OUTPUT}"
echo "CRON=0 6,12,18,0 * * *" >> "${GITHUB_OUTPUT}"
echo "JOB_NAME=palletjack" >> "${GITHUB_OUTPUT}"
echo "JOB_DESCRIPTION=Trigger palletjack cloud run job" >> "${GITHUB_OUTPUT}"
- name: 🗝️ Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
create_credentials_file: true
token_format: access_token
workload_identity_provider: ${{ inputs.identity_provider }}
service_account: ${{ inputs.service_account_email }}

- name: 🚀 Deploy to Cloud Function
- name: 🚀 Deploy Main Cloud Run Job
id: deploy
uses: google-github-actions/deploy-cloud-functions@v3
uses: google-github-actions/deploy-cloudrun@v2
with:
name: roadkill-skid
runtime: python39
entry_point: main
source_dir: src/palletjack/src/roadkill
service_account: cloud-function-sa@${{ inputs.project_id }}.iam.gserviceaccount.com
event_trigger_type: providers/cloud.pubsub/eventTypes/topic.publish
event_trigger_pubsub_topic: projects/${{ inputs.project_id }}/topics/palletjack-topic
deploy_timeout: 600
memory: 4G
service_timeout: 10m
job: ${{ steps.globals.outputs.JOB_NAME }}
source: src/palletjack/src/roadkill
timeout: 20m
secrets: |
/secrets/app/secrets.json=${{inputs.project_id}}/skid-secrets
environment_variables: PROJECT_ID=${{ inputs.project_id }}
secrets_update_strategy: overwrite
env_vars: |-
PROJECT_ID=${{ inputs.project_id }}
flags: |
--memory=4G
--service-account=palletjack-sa@${{ inputs.project_id }}.iam.gserviceaccount.com
--max-retries=1
--task-timeout=60m
--parallelism=1
- name: 📥 Create PubSub topic
- name: 🕰️ Create Main Cloud Scheduler
shell: bash
run: |
if [ ! "$(gcloud pubsub topics list | grep palletjack-topic)" ]; then
gcloud pubsub topics create palletjack-topic --quiet
fi
- name: 🕰️ Create Cloud Scheduler
shell: bash
run: |
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep palletjack)" ]; then
gcloud scheduler jobs create pubsub palletjack \
--description="Trigger palletjack twice per day" \
--schedule="${{ inputs.schedule }}" \
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep ${{ steps.globals.outputs.JOB_NAME }})" ]; then
gcloud scheduler jobs create http "${{ steps.globals.outputs.JOB_NAME }}" \
--description="${{ steps.globals.outputs.JOB_DESCRIPTION }}" \
--schedule="${{ steps.globals.outputs.CRON }}" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=palletjack-topic \
--message-body='{"run": "now"}' \
--uri="https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${{ inputs.project_id }}/jobs/${{ steps.globals.outputs.JOB_NAME }}:run" \
--oauth-service-account-email=scheduler-sa@${{ inputs.project_id }}.iam.gserviceaccount.com \
--quiet
else
gcloud scheduler jobs update pubsub palletjack \
--description="Trigger palletjack twice per day" \
--schedule="${{ inputs.schedule }}" \
gcloud scheduler jobs update http "${{ steps.globals.outputs.JOB_NAME }}" \
--description="${{ steps.globals.outputs.JOB_DESCRIPTION }}" \
--schedule="${{ steps.globals.outputs.CRON }}" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=palletjack-topic \
--message-body='{"run": "now"}' \
--uri="https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${{ inputs.project_id }}/jobs/${{ steps.globals.outputs.JOB_NAME }}:run" \
--oauth-service-account-email=scheduler-sa@${{ inputs.project_id }}.iam.gserviceaccount.com \
--quiet
fi
- name: 🙅 Pause Scheduler Job
shell: bash
if: inputs.pause_schedule_job != 'no'
run: |
gcloud scheduler jobs pause "${{ steps.globals.outputs.JOB_NAME }}" --location=us-central1 --quiet
7 changes: 3 additions & 4 deletions .github/workflows/palletjack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ jobs:
- name: 🚀 Deploy
uses: ./.github/actions/palletjack/deploy
with:
project_id: ${{ secrets.PROJECT_ID }}
identity_provider: ${{ secrets.IDENTITY_PROVIDER }}
service_account_email: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
project_id: ${{ secrets.PROJECT_ID }}
schedule: 0 6 * * *
pause_schedule_job: 'yes'

deploy-prod:
name: Deploy Production to GCF
Expand All @@ -78,7 +78,6 @@ jobs:
- name: 🚀 Deploy
uses: ./.github/actions/palletjack/deploy
with:
project_id: ${{ secrets.PROJECT_ID }}
identity_provider: ${{ secrets.IDENTITY_PROVIDER }}
service_account_email: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
project_id: ${{ secrets.PROJECT_ID }}
schedule: 0 6,12,18,0 * * *
1 change: 1 addition & 0 deletions src/palletjack/src/roadkill/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9

0 comments on commit 81912a8

Please sign in to comment.