-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,62 @@ | ||
name: 'Build and Deploy to Cloud Run' | ||
name: Build and Deploy to Cloud Run | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
env: | ||
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | ||
REGION: ${{ secrets.GCP_REGION }} | ||
SERVICE: ${{ secrets.GCP_SERVICE_NAME }} | ||
WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} | ||
|
||
jobs: | ||
deploy: | ||
runs-on: 'ubuntu-latest' | ||
|
||
# Add 'id-token' with the intended permissions for workload identity federation | ||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
runs-on: ubuntu-latest | ||
environment: GCR | ||
env: | ||
PROJECT_ID: ${{secrets.PROJECT_ID}} | ||
GAR_LOCATION: ${{secrets.GAR_LOCATION}} # TODO: update Artifact Registry location | ||
REPOSITORY: ${{secrets.REPOSITORY}} # TODO: update Artifact Registry repository name | ||
SERVICE: image-converter # TODO: update Cloud Run service name | ||
REGION: ${{secrets.GAR_LOCATION}} # TODO: update Cloud Run service region | ||
|
||
steps: | ||
- name: 'Checkout' | ||
uses: 'actions/checkout@v4' | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
# Configure Workload Identity Federation and generate an access token. | ||
- id: 'auth' | ||
name: 'Authenticate to Google Cloud' | ||
- name: Google Auth | ||
id: auth | ||
uses: 'google-github-actions/auth@v2' | ||
with: | ||
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }} | ||
credentials_json: '${{ secrets.GCP_CREDENTIALS }}' | ||
token_format: 'access_token' | ||
|
||
# Docker authentication and build | ||
- name: 'Docker Auth' | ||
uses: 'docker/login-action@v3' | ||
with: | ||
username: 'oauth2accesstoken' | ||
password: '${{ steps.auth.outputs.auth_token }}' | ||
registry: '${{ env.REGION }}-docker.pkg.dev' | ||
# BEGIN - Docker auth and build (NOTE: If you already have a container image, these Docker steps can be omitted) | ||
|
||
- name: 'Build and Push Container' | ||
# Authenticate Docker to Google Cloud Artifact Registry | ||
- name: Docker Auth | ||
run: |- | ||
DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}" | ||
docker build --tag "${DOCKER_TAG}" . | ||
docker push "${DOCKER_TAG}" | ||
gcloud auth configure-docker "${{ env.GAR_LOCATION }}-docker.pkg.dev" | ||
- name: 'Deploy to Cloud Run' | ||
uses: 'google-github-actions/deploy-cloudrun@v2' | ||
- name: Build and Push Container | ||
run: |- | ||
docker build -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}" ./ | ||
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}" | ||
# END - Docker auth and build | ||
|
||
- name: Deploy to Cloud Run | ||
id: deploy | ||
uses: google-github-actions/deploy-cloudrun@v2 | ||
with: | ||
service: ${{ env.SERVICE }} | ||
region: ${{ env.REGION }} | ||
image: '${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}' | ||
# NOTE: If using a pre-built image, update the image name here | ||
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }} | ||
|
||
|
||
- name: 'Show output' | ||
run: |- | ||
echo ${{ steps.deploy.outputs.url }} | ||
# If required, use the Cloud Run url output in later steps | ||
- name: Show Output | ||
run: echo ${{ steps.deploy.outputs.url }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters