-
Notifications
You must be signed in to change notification settings - Fork 19
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
4 changed files
with
172 additions
and
46 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,70 @@ | ||
|
||
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 "us-central1-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 "us-central1-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=us-central1-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ github.sha }} \ | ||
--region=${{ env.GAR_LOCATION }} \ | ||
--platform=managed \ | ||
--allow-unauthenticated |
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,47 @@ | ||
name: Build and Deploy Locally | ||
|
||
on: | ||
push: | ||
branches: [ "staging" ] | ||
|
||
env: | ||
IMAGE: geppetto | ||
SERVICE_NAME: cloud-run-service | ||
|
||
jobs: | ||
setup-build-publish-deploy: | ||
name: Setup, Build, Publish, and Deploy | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
permissions: | ||
contents: 'read' | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Log in to Docker Hub | ||
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin | ||
|
||
- name: Build Docker Image | ||
run: | | ||
docker build \ | ||
--tag "${{ env.IMAGE }}:${{ github.sha }}" \ | ||
--build-arg GITHUB_SHA="${{ github.sha }}" \ | ||
--build-arg GITHUB_REF="${{ github.ref }}" \ | ||
. | ||
- name: Push Docker Image to Docker Hub | ||
run: | | ||
docker tag "${{ env.IMAGE }}:${{ github.sha }}" "${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE }}:${{ github.sha }}" | ||
docker push "${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE }}:${{ github.sha }}" | ||
- name: Deploy Docker Container Locally | ||
run: | | ||
docker run -d --name ${{ env.SERVICE_NAME }} -p 8080:8080 "${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE }}:${{ github.sha }}" | ||
docker run -d --name ${{ env.SERVICE_NAME }} -p 8080:8080 "${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE }}:${{ github.sha }}" |
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