|
| 1 | +name: Deploy |
| 2 | +description: Deploy to GCP |
| 3 | +inputs: |
| 4 | + project_id: |
| 5 | + description: "The GCP project ID" |
| 6 | + required: true |
| 7 | + identity_provider: |
| 8 | + description: "The identity provider for the workload identity" |
| 9 | + required: true |
| 10 | + service_account_email: |
| 11 | + description: "The service account email" |
| 12 | + required: true |
| 13 | + pause_schedule_job: |
| 14 | + description: "Pause the scheduler job" |
| 15 | + required: false |
| 16 | + default: "no" |
| 17 | + github_token: |
| 18 | + description: "The GitHub token" |
| 19 | + required: true |
| 20 | + |
| 21 | +runs: |
| 22 | + using: composite |
| 23 | + steps: |
| 24 | + - name: 🗝️ Authenticate to Google Cloud |
| 25 | + id: auth |
| 26 | + uses: google-github-actions/auth@v2 |
| 27 | + with: |
| 28 | + workload_identity_provider: ${{ inputs.identity_provider }} |
| 29 | + service_account: ${{ inputs.service_account_email }} |
| 30 | + token_format: "access_token" |
| 31 | + |
| 32 | + - name: 🐳 Set up Docker Buildx |
| 33 | + id: builder |
| 34 | + uses: docker/setup-buildx-action@v3 |
| 35 | + |
| 36 | + - name: 🗝️ Authenticate Docker to Google Cloud |
| 37 | + uses: docker/login-action@v3 |
| 38 | + with: |
| 39 | + registry: us-central1-docker.pkg.dev |
| 40 | + username: oauth2accesstoken |
| 41 | + password: ${{ steps.auth.outputs.access_token }} |
| 42 | + |
| 43 | + - name: 🏷️ Extract tags from GitHub |
| 44 | + id: meta |
| 45 | + uses: docker/metadata-action@v5 |
| 46 | + with: |
| 47 | + github-token: ${{ inputs.github_token }} |
| 48 | + images: us-central1-docker.pkg.dev/${{ inputs.project_id }}/images/job |
| 49 | + tags: | |
| 50 | + type=ref,suffix=-{{sha}},event=branch |
| 51 | + type=ref,prefix=pr-,suffix=-{{sha}},event=pr |
| 52 | + type=semver,pattern={{version}} |
| 53 | + latest |
| 54 | +
|
| 55 | + - name: 📦 Build and push image |
| 56 | + uses: docker/build-push-action@v6 |
| 57 | + with: |
| 58 | + builder: ${{ steps.builder.outputs.name }} |
| 59 | + tags: ${{ steps.meta.outputs.tags }} |
| 60 | + context: . |
| 61 | + file: ./Dockerfile |
| 62 | + push: true |
| 63 | + cache-from: type=gha |
| 64 | + cache-to: type=gha,mode=max |
| 65 | + provenance: false |
| 66 | + |
| 67 | + - name: ☁️ Set up Cloud SDK |
| 68 | + uses: google-github-actions/setup-gcloud@v2 |
| 69 | + |
| 70 | + - name: 🚀 Deploy Cloud Run Job |
| 71 | + uses: google-github-actions/deploy-cloudrun@v2 |
| 72 | + with: |
| 73 | + project_id: ${{ inputs.project_id }} |
| 74 | + region: us-central1 |
| 75 | + image: us-central1-docker.pkg.dev/${{ inputs.project_id }}/images/job:latest |
| 76 | + job: default |
| 77 | + secrets: /secrets/app/secrets.json=skid-secrets:latest |
| 78 | + secrets_update_strategy: overwrite |
| 79 | + timeout: 3h |
| 80 | + flags: | |
| 81 | + --memory=3Gi |
| 82 | + --task-timeout=3h |
| 83 | + --max-retries=0 |
| 84 | + --service-account=cloud-run-sa@${{ inputs.project_id }}.iam.gserviceaccount.com |
| 85 | +
|
| 86 | + - name: 🕰️ Create Cloud Scheduler |
| 87 | + shell: bash |
| 88 | + run: | |
| 89 | + for i in $(gcloud scheduler jobs list --location=us-central1 --uri); do |
| 90 | + gcloud scheduler jobs delete $i --quiet |
| 91 | + done |
| 92 | + gcloud scheduler jobs create http skinname-schedule \ |
| 93 | + --description="Trigger the skinname-skid bot once a week on saturday evening" \ |
| 94 | + --schedule="0 3 * * 1" \ |
| 95 | + --time-zone=America/Denver \ |
| 96 | + --location=us-central1 \ |
| 97 | + --uri="https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${{ inputs.project_id }}/jobs/default:run" \ |
| 98 | + --oauth-service-account-email=scheduler-sa@${{ inputs.project_id }}.iam.gserviceaccount.com |
| 99 | +
|
| 100 | + - name: 🙅 Pause Scheduler Job |
| 101 | + shell: bash |
| 102 | + if: inputs.pause_schedule_job != 'no' |
| 103 | + run: | |
| 104 | + gcloud scheduler jobs pause "skinname-schedule" --location=us-central1 --quiet |
0 commit comments