Skip to content

Commit

Permalink
Merge pull request #1 from 3iq-hacks/ci
Browse files Browse the repository at this point in the history
Google Cloud CI
  • Loading branch information
joshuanianji authored Jan 7, 2024
2 parents 9bda97f + dc78f0e commit 011a293
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Reusable Deployment

on:
workflow_call:
inputs:
environment:
type: string
required: true
description: Name of the target environment.
ref:
type: string
required: true
description: The tag or SHA to checkout.

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Google Auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: '${{ secrets.WIF_PROVIDER }}'
service_account: '${{ secrets.WIF_SERVICE_ACCOUNT }}'

- name: Build, tag and push container
id: build-image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ vars.REGION }}-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/${{ vars.ARTIFACT_REPO }}/${{ vars.SERVICE_NAME }}:${{ inputs.ref }}
- name: Create Service declaration
run: |-
export CONTAINER_IMAGE="${{ vars.REGION }}-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/${{ vars.ARTIFACT_REPO }}/${{ vars.SERVICE_NAME }}:${{ inputs.ref }}"
export SERVICE_NAME="${{ vars.SERVICE_NAME }}"
export PROJECT_ID="${{ vars.GCP_PROJECT_ID }}"
export REVISION_TAG="${{ inputs.ref }}"
export CLOUD_RUN_SA="${{ vars.CLOUD_RUN_SA }}"
export ENVIRONMENT="${{ inputs.environment }}"
envsubst < ./service-yaml/container.yaml > container-${{ inputs.environment }}.yaml
cat container-${{ inputs.environment }}.yaml
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ vars.SERVICE_NAME }}
region: ${{ vars.REGION }}
metadata: container-${{ inputs.environment }}.yaml
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: CI

on:
push:
branches: [main]

jobs:
prod:
if: ${{ github.ref == 'refs/heads/main' || github.base_ref == 'main' }}
uses: ./.github/workflows/_deployment.yml
permissions:
id-token: write
contents: read
with:
environment: prod
ref: ${{ github.sha }}
secrets: inherit
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ First, run the development server:
pnpm i
pnpm dev
```

gcloud builds submit --tag gcr.io/hacked-2024-410423/nextjs --project hacked-2024-410423

gcloud run deploy --image gcr.io/hacked-2024-410423/nextjs --project hacked-2024-410423 --platform managed --allow-unauthenticated

0 comments on commit 011a293

Please sign in to comment.