forked from CoinFabrik/geppetto
-
Notifications
You must be signed in to change notification settings - Fork 15
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
1 parent
30bc760
commit 488c8db
Showing
1 changed file
with
69 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Build and Deploy to Cloud Run | ||
|
||
on: | ||
push: | ||
branches: [ "staging" ] | ||
|
||
env: | ||
PROJECT_ID: ${{ secrets.GKE_PROJECT }} | ||
GAR_LOCATION: us-central1 | ||
SERVICE_NAME: cloud-run-service | ||
REPOSITORY: docker-repository | ||
IMAGE: geppetto | ||
|
||
jobs: | ||
setup-build-publish-deploy: | ||
name: Setup, Build, Publish, and Deploy | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
# Configurar gcloud CLI | ||
- name: Setup gcloud CLI | ||
uses: google-github-actions/setup-gcloud@v1 | ||
with: | ||
version: 'latest' | ||
service_account_key: '${{ secrets.GCLOUD_KEY_JSON }}' | ||
|
||
# Autenticar en Google Cloud | ||
- id: 'auth' | ||
name: 'Authenticate to Google Cloud' | ||
uses: 'google-github-actions/auth@v2' | ||
with: | ||
credentials_json: '${{ secrets.GCLOUD_KEY_JSON }}' | ||
token_format: 'access_token' | ||
|
||
- name: Docker configuration | ||
env: | ||
ACCESS_TOKEN: ${{ steps.auth.outputs.access_token }} | ||
run: echo $ACCESS_TOKEN | docker login -u oauth2accesstoken --password-stdin https://us-central1-docker.pkg.dev | ||
|
||
- name: Log access token | ||
run: echo "Access Token:${{ steps.auth.outputs.access_token }}" | ||
|
||
- name: Build | ||
run: | | ||
docker build \ | ||
--tag "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ github.sha }}" \ | ||
--build-arg GITHUB_SHA="${{ github.sha }}" \ | ||
--build-arg GITHUB_REF="${{ github.ref }}" \ | ||
. | ||
- name: Publish | ||
run: | | ||
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ github.sha }}" | ||
- name: Deploy to Cloud Run | ||
run: | | ||
gcloud run deploy ${{ env.SERVICE_NAME }} \ | ||
--image=${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ github.sha }} \ | ||
--region=${{ env.GAR_LOCATION }} \ | ||
--platform=managed \ | ||
--allow-unauthenticated |