This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
v0.0.10 #11
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: CI/CD Production | |
on: | |
workflow_dispatch: | |
release: | |
types: [created] | |
# RUNNER_SERVICE_ACCOUNT: | |
jobs: | |
build-and-deploy: | |
env: | |
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
SERVICE: ${{ secrets.GCP_SERVICE }} | |
REGION: ${{ secrets.GCP_REGION }} | |
RUNNER: ${{ secrets.GCP_SERVICE_RUNER_EMAIL }} | |
TAG: latest | |
environment: production | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repo and make it accessible to workflow | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Authenticate to Google Cloud | |
- name: Google Auth | |
id: auth | |
uses: "google-github-actions/auth@v2" | |
with: | |
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" | |
# Authenticate Docker to Google Cloud Artifact Registry | |
- name: Docker Auth | |
id: docker-auth | |
uses: "docker/login-action@v3" | |
with: | |
username: _json_key | |
password: "${{ secrets.GOOGLE_CREDENTIALS }}" | |
registry: "${{ env.REGION }}-docker.pkg.dev" | |
# Build and Push Container to Google Cloud Artifact Registry | |
# ! Remember to add "" to secrets that contain @, &, or other special characters | |
- name: Build and Push Container | |
run: | | |
docker build --no-cache \ | |
--build-arg NEXT_PUBLIC_GA_ID="${{secrets.NEXT_PUBLIC_GA_ID}}" \ | |
--build-arg DATABASE_URL="${{secrets.DATABASE_URL}}" \ | |
--build-arg GCP_SECONDARY_BUCKET_NAME=${{secrets.GCP_SECONDARY_BUCKET_NAME}} \ | |
-f Dockerfile \ | |
-t "${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" ./ | |
docker push "${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" | |
# Deploy to Cloud Run | |
- name: Deploy to Cloud Run | |
run: | | |
gcloud run deploy ${{env.SERVICE}} \ | |
--platform=managed \ | |
--service-account=${{ env.RUNNER }} \ | |
--region=${{ env.REGION }} \ | |
--image="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" \ | |
--min-instances=default \ | |
--max-instances=1 |