-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add cloudrun deploy job #29
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
Changes from all commits
dd9dcf7
9666519
e606a4d
6a4dad1
de7e13d
ab029e3
0c2369b
4887ad5
39572c8
94051b3
33c8e62
64bdf69
80e6d85
ac94dcf
8996ff3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| name: 'Reusable gcp cloudrun deploy workflow' | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| job-name: | ||
| description: 'Cloud Run Job name (at least one of job-name or service-name required)' | ||
| required: false | ||
| type: string | ||
| service-name: | ||
| description: 'Cloud Run Service name (at least one of job-name or service-name required)' | ||
| required: false | ||
| type: string | ||
| registry: | ||
| description: 'Container registry URL (e.g., gcr.io, europe-west3-docker.pkg.dev)' | ||
| required: true | ||
| type: string | ||
| artifact-repository: | ||
| description: 'Image repository name without registry prefix (e.g., my-image)' | ||
| required: true | ||
| type: string | ||
| artifact-tag: | ||
| description: 'Image tag of the container image to deploy' | ||
| required: true | ||
| type: string | ||
| region: | ||
| description: 'GCP region for Cloud Run deployment (e.g., europe-west3)' | ||
| required: true | ||
| type: string | ||
| flags: | ||
| description: 'Additional flags to pass to the gcloud deploy command' | ||
| type: string | ||
| container: | ||
| description: 'Container name for multi-container deployments' | ||
| type: string | ||
| workload-identity-provider: | ||
| description: 'GCP Workload Identity Provider resource name' | ||
| required: true | ||
| type: string | ||
| workload-identity-service-account-mail: | ||
| description: 'GCP service account email for workload identity OIDC authentication' | ||
| required: true | ||
| type: string | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| jobs: | ||
| deploy_cloudrun: | ||
| name: Deployment job | ||
| permissions: | ||
| contents: 'read' | ||
| id-token: 'write' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Validate inputs | ||
| run: | | ||
| if [[ -z "${{ inputs.job-name }}" && -z "${{ inputs.service-name }}" ]]; then | ||
| echo "::error::At least one of 'job-name' or 'service-name' must be provided" | ||
| exit 1 | ||
| fi | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - uses: 'google-github-actions/auth@v3' | ||
| with: | ||
| service_account: ${{ inputs.workload-identity-service-account-mail }} | ||
| workload_identity_provider: ${{ inputs.workload-identity-provider }} | ||
| - name: 'Set up gcloud CLI' | ||
| uses: 'google-github-actions/setup-gcloud@v3' | ||
| with: | ||
| install_components: 'beta' | ||
|
|
||
| # we cannot use google-github-actions/deploy-cloudrun here due to: | ||
| # https://github.com/google-github-actions/deploy-cloudrun/issues/558 | ||
| - name: 'deploy cloudrun' | ||
| env: | ||
| CONTAINER: ${{ inputs.container }} | ||
| run: | | ||
| if [ -n "$CONTAINER" ]; then | ||
| CONTAINER_FLAG="--container $CONTAINER" | ||
| else | ||
| CONTAINER_FLAG="" | ||
| fi | ||
| IMAGE="${{ inputs.registry }}/${{ inputs.artifact-repository }}:${{ inputs.artifact-tag }}" | ||
| EXTRA_FLAGS="${{ inputs.flags }}" | ||
| gcloud config set run/region "${{ inputs.region }}" | ||
| if [ -n "${{ inputs.job-name }}" ]; then | ||
| gcloud beta run jobs deploy "${{ inputs.job-name }}" \ | ||
| ${CONTAINER_FLAG} \ | ||
| --image "$IMAGE" \ | ||
| ${EXTRA_FLAGS} | ||
| else | ||
| gcloud run deploy "${{ inputs.service-name }}" \ | ||
| ${CONTAINER_FLAG} \ | ||
| --image "$IMAGE" \ | ||
| ${EXTRA_FLAGS} | ||
|
Comment on lines
+71
to
+91
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Improve shell robustness: quote variable assignments to prevent word-splitting issues. The deployment step constructs flag strings that could be vulnerable to word-splitting if inputs contain spaces or special characters. While container names and flags typically don't have such characters in practice, shell best practices suggest explicit quoting. Current approach: CONTAINER_FLAG="--container $CONTAINER"
# Later used as: ${CONTAINER_FLAG}If Consider refactoring to apply the env var directly and quote the variable value: env:
CONTAINER: ${{ inputs.container }}
run: |
if [ -n "$CONTAINER" ]; then
- CONTAINER_FLAG="--container $CONTAINER"
+ CONTAINER_FLAG="--container \"$CONTAINER\""
else
CONTAINER_FLAG=""
fi
IMAGE="${{ inputs.registry }}/${{ inputs.artifact-repository }}:${{ inputs.artifact-tag }}"
- EXTRA_FLAGS="${{ inputs.flags }}"
+ EXTRA_FLAGS="${{ inputs.flags }}"Alternatively, conditionally inject the flag directly into the gcloud command to avoid intermediate variable construction. This aligns with the previous review suggestion to guard against weird characters in inputs. 🤖 Prompt for AI Agents
smelchior marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
Uh oh!
There was an error while loading. Please reload this page.