Skip to content

Build and Deploy to Cloud Run #127

Build and Deploy to Cloud Run

Build and Deploy to Cloud Run #127

# This workflow build and push a Docker container to Google Artifact Registry
# and deploy it on Cloud Run when a commit is pushed to the "master"
# branch.
#
# To configure this workflow:
#
# 1. Enable the following Google Cloud APIs:
#
# - Artifact Registry (artifactregistry.googleapis.com)
# - Cloud Run (run.googleapis.com)
# - IAM Credentials API (iamcredentials.googleapis.com)
#
# You can learn more about enabling APIs at
# https://support.google.com/googleapi/answer/6158841.
#
# 2. Create and configure a Workload Identity Provider for GitHub:
# https://github.com/google-github-actions/auth#preferred-direct-workload-identity-federation.
#
# Depending on how you authenticate, you will need to grant an IAM principal
# permissions on Google Cloud:
#
# - Artifact Registry Administrator (roles/artifactregistry.admin)
# - Cloud Run Developer (roles/run.developer)
#
# You can learn more about setting IAM permissions at
# https://cloud.google.com/iam/docs/manage-access-other-resources
#
# 3. Change the values in the "env" block to match your values.
name: 'Build and Deploy to Cloud Run'
env:
DOCKER_IMAGE_URL: asia-southeast1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/pp-repository/
on:
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: 'Checkout'
uses: 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' # actions/checkout@v4
# Configure Workload Identity Federation and generate an access token.
#
# See https://github.com/google-github-actions/auth for more options,
# including authenticating via a JSON credentials file.
- name: Google Cloud Auth
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}'
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Set up Cloud SDK
uses: 'google-github-actions/setup-gcloud@v2'
- name: Configure Docker
run: |
gcloud auth configure-docker asia-southeast1-docker.pkg.dev
- name: (CS) Make Cloud Run build configuration changes
working-directory: ./collaboration-svc
run: |
sed -i -e 's/EXPOSE 80/EXPOSE 8080/' -e 's/"--port", "80"/"--port", "8080"/' ./Dockerfile
- name: (CS) Build and Push Docker Image
working-directory: ./collaboration-svc
run: |
docker build -t ${{ env.DOCKER_IMAGE_URL }}pp-collaboration-svc:latest --platform=linux/amd64 .
docker push ${{ env.DOCKER_IMAGE_URL }}pp-collaboration-svc:latest
- name: (ES) Build and Push Docker Image
working-directory: ./expire-observer-svc
run: |
docker build -t ${{ env.DOCKER_IMAGE_URL }}pp-expire-observer-svc:latest --platform=linux/amd64 .
docker push ${{ env.DOCKER_IMAGE_URL }}pp-expire-observer-svc:latest
- name: (FE) Create .env for Cloud Run
working-directory: ./PeerPrep
run: |
echo "VITE_API_URL=https://api.peerprep.cloud" > .env
echo "VITE_SIGNALING_SERVER_URL=wss://pp-ss-161940165499.asia-east1.run.app" >> .env
echo "VITE_ICE_SERVERS=stun:stun.l.google.com:19302" >> .env
echo "VITE_WS_GATEWAY_URL=wss://pp-api-gateway-161940165499.asia-east1.run.app/ws/fe" >> .env
- name: (FE) Make Cloud Run build configuration changes
working-directory: ./PeerPrep
run: |
sed -i 's/EXPOSE 80/EXPOSE 8080/' ./Dockerfile
sed -i 's/listen 80;/listen 8080;/' ./nginx.conf
sed -i 's/localhost/_/' ./nginx.conf
- name: (FE) Build and Push Docker Image
working-directory: ./PeerPrep
run: |
docker build -t ${{ env.DOCKER_IMAGE_URL }}pp-fe:latest --platform=linux/amd64 .
docker push ${{ env.DOCKER_IMAGE_URL }}pp-fe:latest
- name: (SS) Make Cloud Run build configuration changes
working-directory: ./signaling-svc
run: |
sed -i -e 's/EXPOSE 4444/EXPOSE 8080/' ./Dockerfile
- name: (SS) Build and Push Docker Image
working-directory: ./signaling-svc
run: |
docker build -t ${{ env.DOCKER_IMAGE_URL }}pp-ss:latest --platform=linux/amd64 .
docker push ${{ env.DOCKER_IMAGE_URL }}pp-ss:latest
- name: (QHS) Make Cloud Run build configuration changes
working-directory: ./qns-hist-svc
run: |
sed -i -e 's/EXPOSE 80/EXPOSE 8080/' -e 's/"--port", "80"/"--port", "8080"/' ./Dockerfile
- name: (QHS) Build and Push Docker Image
working-directory: ./qns-hist-svc
run: |
docker build -t ${{ env.DOCKER_IMAGE_URL }}pp-qns-hist-svc:latest --platform=linux/amd64 .
docker push ${{ env.DOCKER_IMAGE_URL }}pp-qns-hist-svc:latest
- name: (AG) Make Cloud Run build configuration changes
working-directory: ./api-gateway
run: |
sed -i -e 's/EXPOSE 80/EXPOSE 8080/' -e 's/"--port", "80"/"--port", "8080"/' ./Dockerfile
- name: (AG) Build and Push Docker Image
working-directory: ./api-gateway
run: |
docker build -t ${{ env.DOCKER_IMAGE_URL }}pp-api-gateway:latest --platform=linux/amd64 .
docker push ${{ env.DOCKER_IMAGE_URL }}pp-api-gateway:latest
- name: (MS) Make Cloud Run build configuration changes
working-directory: ./matching-svc
run: |
sed -i -e 's/EXPOSE 80/EXPOSE 8080/' -e 's/"--port", "80"/"--port", "8080"/' ./Dockerfile
- name: (MS) Build and Push Docker Image
working-directory: ./matching-svc
run: |
docker build -t ${{ env.DOCKER_IMAGE_URL }}pp-matching-svc:latest --platform=linux/amd64 .
docker push ${{ env.DOCKER_IMAGE_URL }}pp-matching-svc:latest
- name: (US) Make Cloud Run build configuration changes
working-directory: ./user-svc
run: |
sed -i -e 's/EXPOSE 80/EXPOSE 8080/' -e 's/"--port", "80"/"--port", "8080"/' ./Dockerfile
- name: (US) Build and Push Docker Image
working-directory: ./user-svc
run: |
docker build -t ${{ env.DOCKER_IMAGE_URL }}pp-user-svc:latest --platform=linux/amd64 .
docker push ${{ env.DOCKER_IMAGE_URL }}pp-user-svc:latest
- name: (QS) Make Cloud Run build configuration changes
working-directory: ./qns-svc
run: |
sed -i -e 's/EXPOSE 80/EXPOSE 8080/' -e 's/"--port", "80"/"--port", "8080"/' ./Dockerfile
- name: (QS) Build and Push Docker Image
working-directory: ./qns-svc
run: |
docker build -t ${{ env.DOCKER_IMAGE_URL }}pp-qns-svc:latest --platform=linux/amd64 .
docker push ${{ env.DOCKER_IMAGE_URL }}pp-qns-svc:latest
# - name: Deploy to Cloud Run
# run: |
# echo SERVICE_NAME $SERVICE_NAME
# gcloud run deploy $SERVICE_NAME \
# --image ${{ env.DOCKER_IMAGE_URL }}:latest \
# --platform managed \
# --region asia-southeast1 \
# --allow-unauthenticated
# If required, use the Cloud Run URL output in later steps
- name: 'Show output'
run: |2-
echo ${{ steps.deploy.outputs.url }}