Skip to content

Commit

Permalink
Add support for Cloud Run jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Apr 15, 2024
1 parent aafe258 commit 4c7478c
Show file tree
Hide file tree
Showing 9 changed files with 2,880 additions and 167 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,104 @@ jobs:
"run.googleapis.com/cloudsql-instances": "test-project:us-central1:my-test-instance"
}
REVISION_COUNT: 2

jobs:
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
runs-on: 'ubuntu-latest'

steps:
- uses: 'actions/checkout@v4'

- name: 'Compute job name'
run: |-
echo "JOB_NAME=${GITHUB_JOB}-job-${GITHUB_SHA::7}-${GITHUB_RUN_NUMBER}" >> ${GITHUB_ENV}
- uses: 'actions/setup-node@v4'
with:
node-version: '20.x'

- run: 'npm ci && npm run build'

- uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'

- id: 'deploy-cloudrun'
name: 'Deploy'
uses: './'
with:
image: 'gcr.io/cloudrun/hello'
job: '${{ env.JOB_NAME }}'
env_vars: |-
FOO=bar
ZIP=zap\,with|separators\,and&stuff
env_vars_file: './tests/fixtures/env_vars.txt'
secrets: |-
MY_SECRET=${{ vars.SECRET_NAME }}:latest
MY_SECOND_SECRET=${{ vars.SECRET_NAME }}:1
labels: |-
label1=value1
label2=value2
skip_default_labels: true
flags: '--cpu=2'

- name: 'Run initial deploy tests'
run: 'npm run e2e-tests'
env:
PROJECT_ID: ${{ vars.PROJECT_ID }}
JOB: '${{ env.JOB_NAME }}'
ENV: |-
{
"FOO": "bar",
"ZIP": "zap,with|separators,and&stuff",
"TEXT_FOO": "bar",
"TEXT_ZIP": "zap,with|separators,and&stuff"
}
SECRET_ENV: |-
{
"MY_SECRET": "${{ vars.SECRET_NAME }}:latest",
"MY_SECOND_SECRET": "${{ vars.SECRET_NAME }}:1"
}
LABELS: |-
{
"label1": "value1",
"label2": "value2"
}
- id: 'deploy-cloudrun-again'
name: 'Deploy again'
uses: './'
with:
image: 'gcr.io/cloudrun/hello'
job: '${{ env.JOB_NAME }}'
env_vars: |-
ABC=123
DEF=456
secrets: /api/secrets/my-secret=${{ vars.SECRET_NAME }}:latest

- name: 'Run re-deploy tests'
run: 'npm run e2e-tests'
env:
PROJECT_ID: ${{ vars.PROJECT_ID }}
JOB: '${{ env.JOB_NAME }}'
ENV: |-
{
"FOO": "bar",
"ZIP": "zap,with|separators,and&stuff",
"TEXT_FOO": "bar",
"TEXT_ZIP": "zap,with|separators,and&stuff",
"ABC": "123",
"DEF": "456"
}
SECRET_VOLUMES: |-
{
"/api/secrets/my-secret": "${{ vars.SECRET_NAME }}:latest"
}
LABELS: |-
{
"label1": "value1",
"label2": "value2",
"commit-sha": "${{ github.sha }}",
"managed-by": "github-actions"
}
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,14 @@ jobs:

## Inputs

- `service`: (Required, unless providing `metadata`) ID of the service or
fully-qualified identifier of the service.
- `service`: (Required, unless providing `metadata` or `job`) ID of the
service or fully-qualified identifier of the service.

- `job`: (Required, unless providing `metadata`, `service`, or `image`) ID of
the job or fully-qualified identifier of the job. If `job` and `service` are
specified then the `service` will be updated and the `job` will be ignored.
Note that the `job` must be created first. This will only update an existing
`job`, it will not deploy/create a new job.
- `job`: (Required, unless providing `metadata` or `service`) ID of
the job or fully-qualified identifier of the job.

- `image`: (Required, unless providing `metadata`, `source`, or `job`)
Fully-qualified name of the container image to deploy. For example:
- `image`: (Required, unless providing `metadata` or `source`) Fully-qualified
name of the container image to deploy. For example:

```text
gcr.io/cloudrun/hello:latest
Expand Down
10 changes: 5 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ description: |-
inputs:
service:
description: |-
(Required, unless providing `metadata`) ID of the service or
(Required, unless providing `metadata` or `job`) ID of the service or
fully-qualified identifier of the service.
required: false

image:
description: |-
(Required, unless providing `metadata`, `source`, or `job`)
Fully-qualified name of the container image to deploy. For example:
(Required, unless providing `metadata` or `source`) Fully-qualified name
of the container image to deploy. For example:
gcr.io/cloudrun/hello:latest
Expand All @@ -50,8 +50,8 @@ inputs:

job:
description: |-
(Required, unless providing `metadata`, `service`, or `image`) ID of the
job or fully-qualified identifier of the job. If `job` and `service` are
(Required, unless providing `metadata` or `service`) ID of the job or
fully-qualified identifier of the job. If `job` and `service` are
specified then the `service` will be updated and the `job` will be
ignored. Note that the `job` must be created first. This will only update
an existing `job`, it will not deploy/create a new job.
Expand Down
10 changes: 5 additions & 5 deletions dist/main/index.js

Large diffs are not rendered by default.

Loading

0 comments on commit 4c7478c

Please sign in to comment.