Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Cloud Run jobs #506

Merged
merged 10 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ 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. Only one of `service`
or `job` may be specified.

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

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

- `source`: (Required, unless providing `metadata` or `image`) Path to source
to deploy. If specified, this will deploy the Cloud Run service from the
code specified at the given source directory.
- `source`: (Required, unless providing `metadata`, `image`, or `job`) Path to
source to deploy. If specified, this will deploy the Cloud Run service from
the code specified at the given source directory.
sethvargo marked this conversation as resolved.
Show resolved Hide resolved

This requires the [Artifact Registry API][artifact-api] to be enabled.
Furthermore, the deploying service account must have the `Cloud Build
Expand Down
26 changes: 16 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ description: |-
inputs:
service:
description: |-
(Required, unless providing `metadata`) ID of the service or
fully-qualified identifier of the service.
(Required, unless providing `metadata` or `job`) ID of the service or
sethvargo marked this conversation as resolved.
Show resolved Hide resolved
fully-qualified identifier of the service. Only one of `service` or `job`
may be specified.
required: false

image:
Expand All @@ -38,15 +39,20 @@ inputs:

source:
description: |-
(Required, unless providing `metadata` or `image`) Path to source to
deploy. If specified, this will deploy the Cloud Run service from the code
specified at the given source directory.
(Required, unless providing `metadata`, `image`, or `job`) Path to source
to deploy. If specified, this will deploy the Cloud Run service from the
code specified at the given source directory.
sethvargo marked this conversation as resolved.
Show resolved Hide resolved

This requires the Artifact Registry API to be enabled. Furthermore, the
deploying service account must have the `Cloud Build Service Account`
role. The initial deployment will create an Artifact Registry repository
which requires the `Artifact Registry Admin` role.
required: false

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

suffix:
Expand Down
4 changes: 2 additions & 2 deletions dist/main/index.js

Large diffs are not rendered by default.

100 changes: 46 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@google-github-actions/setup-cloud-sdk": "^1.1.6"
},
"devDependencies": {
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
Expand All @@ -47,7 +46,6 @@
"googleapis": "^134.0.0",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"yaml": "^2.4.1"
"typescript": "^5.4.5"
}
}
Loading
Loading