-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(palletjack): switch to cloud run job
- Loading branch information
Showing
3 changed files
with
53 additions
and
44 deletions.
There are no files selected for viewing
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
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 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.9 |