Skip to content

Commit 32334e9

Browse files
Add support for Cloud Run jobs (#506)
Closes #474 Closes #364 --------- Co-authored-by: stephanos.charalambous <[email protected]>
1 parent 57c0de3 commit 32334e9

File tree

9 files changed

+329
-129
lines changed

9 files changed

+329
-129
lines changed

.github/workflows/integration.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,104 @@ jobs:
225225
"run.googleapis.com/cloudsql-instances": "test-project:us-central1:my-test-instance"
226226
}
227227
REVISION_COUNT: 2
228+
229+
jobs:
230+
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
231+
runs-on: 'ubuntu-latest'
232+
233+
steps:
234+
- uses: 'actions/checkout@v4'
235+
236+
- name: 'Compute job name'
237+
run: |-
238+
echo "JOB_NAME=${GITHUB_JOB}-job-${GITHUB_SHA::7}-${GITHUB_RUN_NUMBER}" >> ${GITHUB_ENV}
239+
240+
- uses: 'actions/setup-node@v4'
241+
with:
242+
node-version: '20.x'
243+
244+
- run: 'npm ci && npm run build'
245+
246+
- uses: 'google-github-actions/auth@v2'
247+
with:
248+
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
249+
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
250+
251+
- id: 'deploy-cloudrun'
252+
name: 'Deploy'
253+
uses: './'
254+
with:
255+
image: 'gcr.io/cloudrun/hello'
256+
job: '${{ env.JOB_NAME }}'
257+
env_vars: |-
258+
FOO=bar
259+
ZIP=zap\,with|separators\,and&stuff
260+
env_vars_file: './tests/fixtures/env_vars.txt'
261+
secrets: |-
262+
MY_SECRET=${{ vars.SECRET_NAME }}:latest
263+
MY_SECOND_SECRET=${{ vars.SECRET_NAME }}:1
264+
labels: |-
265+
label1=value1
266+
label2=value2
267+
skip_default_labels: true
268+
flags: '--cpu=2'
269+
270+
- name: 'Run initial deploy tests'
271+
run: 'npm run e2e-tests'
272+
env:
273+
PROJECT_ID: ${{ vars.PROJECT_ID }}
274+
JOB: '${{ env.JOB_NAME }}'
275+
ENV: |-
276+
{
277+
"FOO": "bar",
278+
"ZIP": "zap,with|separators,and&stuff",
279+
"TEXT_FOO": "bar",
280+
"TEXT_ZIP": "zap,with|separators,and&stuff"
281+
}
282+
SECRET_ENV: |-
283+
{
284+
"MY_SECRET": "${{ vars.SECRET_NAME }}:latest",
285+
"MY_SECOND_SECRET": "${{ vars.SECRET_NAME }}:1"
286+
}
287+
LABELS: |-
288+
{
289+
"label1": "value1",
290+
"label2": "value2"
291+
}
292+
293+
- id: 'deploy-cloudrun-again'
294+
name: 'Deploy again'
295+
uses: './'
296+
with:
297+
image: 'gcr.io/cloudrun/hello'
298+
job: '${{ env.JOB_NAME }}'
299+
env_vars: |-
300+
ABC=123
301+
DEF=456
302+
secrets: /api/secrets/my-secret=${{ vars.SECRET_NAME }}:latest
303+
304+
- name: 'Run re-deploy tests'
305+
run: 'npm run e2e-tests'
306+
env:
307+
PROJECT_ID: ${{ vars.PROJECT_ID }}
308+
JOB: '${{ env.JOB_NAME }}'
309+
ENV: |-
310+
{
311+
"FOO": "bar",
312+
"ZIP": "zap,with|separators,and&stuff",
313+
"TEXT_FOO": "bar",
314+
"TEXT_ZIP": "zap,with|separators,and&stuff",
315+
"ABC": "123",
316+
"DEF": "456"
317+
}
318+
SECRET_VOLUMES: |-
319+
{
320+
"/api/secrets/my-secret": "${{ vars.SECRET_NAME }}:latest"
321+
}
322+
LABELS: |-
323+
{
324+
"label1": "value1",
325+
"label2": "value2",
326+
"commit-sha": "${{ github.sha }}",
327+
"managed-by": "github-actions"
328+
}

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ jobs:
5353
5454
## Inputs
5555
56-
- `service`: (Required, unless providing `metadata`) ID of the service or
57-
fully-qualified identifier of the service.
56+
- `service`: (Required, unless providing `metadata` or `job`) ID of the
57+
service or fully-qualified identifier of the service. Only one of `service`
58+
or `job` may be specified.
59+
60+
- `job`: (Required, unless providing `metadata` or `service`) ID of the job or
61+
fully-qualified identifier of the job. Only one of `service` or `job` may be
62+
specified.
5863

5964
- `image`: (Required, unless providing `metadata` or `source`) Fully-qualified
6065
name of the container image to deploy. For example:
@@ -69,9 +74,9 @@ jobs:
6974
us-docker.pkg.dev/my-project/my-container/image:1.2.3
7075
```
7176

72-
- `source`: (Required, unless providing `metadata` or `image`) Path to source
73-
to deploy. If specified, this will deploy the Cloud Run service from the
74-
code specified at the given source directory.
77+
- `source`: (Required, unless providing `metadata`, `image`, or `job`) Path to
78+
source to deploy. If specified, this will deploy the Cloud Run service from
79+
the code specified at the given source directory.
7580

7681
This requires the [Artifact Registry API][artifact-api] to be enabled.
7782
Furthermore, the deploying service account must have the `Cloud Build

action.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ description: |-
2020
inputs:
2121
service:
2222
description: |-
23-
(Required, unless providing `metadata`) ID of the service or
24-
fully-qualified identifier of the service.
23+
(Required, unless providing `metadata` or `job`) ID of the service or
24+
fully-qualified identifier of the service. Only one of `service` or `job`
25+
may be specified.
2526
required: false
2627

2728
image:
@@ -38,15 +39,20 @@ inputs:
3839

3940
source:
4041
description: |-
41-
(Required, unless providing `metadata` or `image`) Path to source to
42-
deploy. If specified, this will deploy the Cloud Run service from the code
43-
specified at the given source directory.
42+
(Required, unless providing `metadata`, `image`, or `job`) Path to source
43+
to deploy. If specified, this will deploy the Cloud Run service from the
44+
code specified at the given source directory.
45+
46+
This requires the Artifact Registry API to be enabled. Furthermore, the
47+
deploying service account must have the `Cloud Build Service Account`
48+
role. The initial deployment will create an Artifact Registry repository
49+
which requires the `Artifact Registry Admin` role.
50+
required: false
4451

45-
This requires the [Artifact Registry API][artifact-api] to be enabled.
46-
Furthermore, the deploying service account must have the `Cloud Build
47-
Service Account` role. The initial deployment will create an [Artifact
48-
Registry repository][repo] which requires the `Artifact Registry Admin`
49-
role.
52+
job:
53+
description: |-
54+
(Required, unless providing `metadata` or `service`) ID of the job or
55+
fully-qualified identifier of the job.
5056
required: false
5157

5258
suffix:

dist/main/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 46 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@google-github-actions/setup-cloud-sdk": "^1.1.6"
3737
},
3838
"devDependencies": {
39-
"@types/js-yaml": "^4.0.9",
4039
"@types/node": "^20.12.7",
4140
"@typescript-eslint/eslint-plugin": "^7.6.0",
4241
"@typescript-eslint/parser": "^7.6.0",
@@ -47,7 +46,6 @@
4746
"googleapis": "^134.0.0",
4847
"prettier": "^3.2.5",
4948
"ts-node": "^10.9.2",
50-
"typescript": "^5.4.5",
51-
"yaml": "^2.4.1"
49+
"typescript": "^5.4.5"
5250
}
5351
}

0 commit comments

Comments
 (0)