remvoe GKE deployments add cloud run for deployments #31
Workflow file for this run
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
name: Build and Deploy Docker Images | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
env: | |
LOCATION: me-central1 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: '${{ secrets.GCP_CREDENTIALS }}' | |
- name: Set up Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
- name: Configure Docker for Artifact Registry | |
run: | | |
gcloud auth configure-docker ${{env.LOCATION}}-docker.pkg.dev | |
- name: Build and push Docker image for client | |
run: | | |
docker build \ | |
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ | |
--build-arg GITHUB_SHA=${{ github.sha }} \ | |
--build-arg GITHUB_REF_NAME=${{ github.ref_name }} \ | |
-f apps/client/Dockerfile \ | |
-t ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.sha }} \ | |
-t ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.ref_name }} \ | |
. | |
docker push ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.sha }} | |
docker push ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.ref_name }} | |
- name: Build and push Docker image for server | |
run: | | |
docker build \ | |
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ | |
--build-arg GITHUB_SHA=${{ github.sha }} \ | |
--build-arg GITHUB_REF_NAME=${{ github.ref_name }} \ | |
-f apps/server/Dockerfile \ | |
-t ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.sha }} \ | |
-t ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.ref_name }} \ | |
. | |
docker push ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.sha }} | |
docker push ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.ref_name }} | |
- name: Install kubectl | |
run: gcloud components install kubectl | |
# Deploy server to Cloud Run with environment variables | |
- name: Deploy Server to Cloud Run | |
id: deploy-server | |
uses: google-github-actions/deploy-cloudrun@v0 | |
with: | |
service: ${{ secrets.SERVER_SERVICE }} | |
region: ${{env.LOCATION}} | |
image: ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/${{ secrets.SERVER_SERVICE }}:${{ github.sha }} | |
env_vars: | | |
JWT_SECRET=${{ secrets.JWT_KEY_SECRET }} | |
MONGODB_URI=${{ secrets.MONGODB_URI_SECRET }} | |
TOKEN_EXPIRATION=${{ secrets.JWT_EXPIRATION }} | |
# Deploy client to Cloud Run with the server's URL as an environment variable | |
- name: Deploy Client to Cloud Run | |
id: deploy-client | |
uses: google-github-actions/deploy-cloudrun@v0 | |
with: | |
service: ${{ secrets.CLIENT_SERVICE }} | |
region: ${{env.LOCATION}} | |
image: ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/${{ secrets.CLIENT_SERVICE }}:${{ github.sha }} | |
env_vars: | | |
SERVER_URL=${{ steps.deploy-server.outputs.url }} | |
# If required, use the Cloud Run URL outputs in later steps | |
- name: Show Client URL | |
run: echo ${{ steps.deploy-client.outputs.url }} | |
- name: Show Server URL | |
run: echo ${{ steps.deploy-server.outputs.url }} |