Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup CI/CD pipeline #127

Closed
wants to merge 13 commits into from
89 changes: 89 additions & 0 deletions .github/workflows/agent-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Agent Production

on:
push:
branches: ['main']
# check which application has been changed
paths:
- 'apps/agent/**'
- 'infra/docker/Dockerfile.agent'
- '.github/workflows/agent-production.yml'


env:
REGION: "us-east1"
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }}
SERVICE: "sahil-agent-production"

jobs:
build:
name: Build - Push - Deploy
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

outputs:
output1: ${{ steps.step1.outputs.IMAGE }}

steps:
- name: Clone
uses: actions/checkout@v3
id: step1
- run: |
echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-agent:production-$GITHUB_SHA" >> $GITHUB_ENV

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# GCP auth
- name: Authenticate the service account
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ env.GCP_SA_KEY }}'

- name: Install gcloud on the job runner
uses: google-github-actions/setup-gcloud@v1
with:
service_account_key: '${{ env.GCP_SA_KEY }}'
project_id: '${{ env.GCP_PROJECT_ID }}'
export_default_credentials: true

- name: Authorize admin account to push docker image
run: gcloud auth configure-docker

- name: Use gcloud CLI
run: 'gcloud info'

# Buils & Push
- name: Build & Push
uses: docker/build-push-action@v3
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: infra/docker/Dockerfile.agent
#labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ env.IMAGE }}

- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v0
with:
service: ${{ env.SERVICE }}
region: ${{ env.REGION }}
image: ${{ env.IMAGE }}
# NOTE: env variables here
# env_vars: |
# NODE_ENV=production
# PORT=3000

# If required, use the Cloud Run url output in later steps
- name: Show Output
run: |
- echo ${{ steps.deploy.outputs.url }}
- echo ${{ steps.step1.outputs.IMAGE }}
88 changes: 88 additions & 0 deletions .github/workflows/agent-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Agent Stagging

on:
push:
branches: ['develop']
# check which application has been changed
paths:
- 'apps/agent/**'
- 'infra/docker/Dockerfile.agent'
- '.github/workflows/agent-staging.yml'


env:
REGION: "us-central1"
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }}
SERVICE: "sahil-agent-stagging"

jobs:
build:
name: Build - Push - Deploy
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

outputs:
output1: ${{ steps.step1.outputs.IMAGE }}

steps:
- name: Clone
uses: actions/checkout@v3
id: step1
- run: |
echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-agent:stagging-$GITHUB_SHA" >> $GITHUB_ENV

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# GCP auth
- name: Authenticate the service account
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ env.GCP_SA_KEY }}'

- name: Install gcloud on the job runner
uses: google-github-actions/setup-gcloud@v1
with:
service_account_key: '${{ env.GCP_SA_KEY }}'
project_id: '${{ env.GCP_PROJECT_ID }}'
export_default_credentials: true

- name: Authorize admin account to push docker image
run: gcloud auth configure-docker

- name: Use gcloud CLI
run: 'gcloud info'

- name: Build & Push
uses: docker/build-push-action@v3
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: infra/docker/Dockerfile.agent
#labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ env.IMAGE }}

- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v0
with:
service: ${{ env.SERVICE }}
region: ${{ env.REGION }}
image: ${{ env.IMAGE }}
# NOTE: env variables here
# env_vars: |
# NODE_ENV=production
# PORT=3000

# If required, use the Cloud Run url output in later steps
- name: Show Output
run: |
- echo ${{ steps.deploy.outputs.url }}
- echo ${{ steps.step1.outputs.IMAGE }}
89 changes: 89 additions & 0 deletions .github/workflows/api-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: API Production

on:
push:
branches: ['main']
# check which application has been changed
paths:
- 'apps/api/**'
- 'infra/docker/Dockerfile.api'
- '.github/workflows/api-production.yml'


env:
REGION: "us-east1"
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }}
SERVICE: "sahil-api-production"

jobs:
build:
name: Build - Push - Deploy
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

outputs:
output1: ${{ steps.step1.outputs.IMAGE }}

steps:
- name: Clone
uses: actions/checkout@v3
id: step1
- run: |
echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-api:production-$GITHUB_SHA" >> $GITHUB_ENV

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# GCP auth
- name: Authenticate the service account
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ env.GCP_SA_KEY }}'

- name: Install gcloud on the job runner
uses: google-github-actions/setup-gcloud@v1
with:
service_account_key: '${{ env.GCP_SA_KEY }}'
project_id: '${{ env.GCP_PROJECT_ID }}'
export_default_credentials: true

- name: Authorize admin account to push docker image
run: gcloud auth configure-docker

- name: Use gcloud CLI
run: 'gcloud info'

# Buils & Push
- name: Build & Push
uses: docker/build-push-action@v3
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: infra/docker/Dockerfile.api
#labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ env.IMAGE }}

- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v0
with:
service: ${{ env.SERVICE }}
region: ${{ env.REGION }}
image: ${{ env.IMAGE }}
# NOTE: env variables here
# env_vars: |
# NODE_ENV=production
# PORT=3000

# If required, use the Cloud Run url output in later steps
- name: Show Output
run: |
- echo ${{ steps.deploy.outputs.url }}
- echo ${{ steps.step1.outputs.IMAGE }}
88 changes: 88 additions & 0 deletions .github/workflows/api-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: API Stagging

on:
push:
branches: ['develop']
# check which application has been changed
paths:
- 'apps/api/**'
- 'infra/docker/Dockerfile.api'
- '.github/workflows/api-staging.yml'


env:
REGION: "us-central1"
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }}
SERVICE: "sahil-api-stagging"

jobs:
build:
name: Build - Push - Deploy
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

outputs:
output1: ${{ steps.step1.outputs.IMAGE }}

steps:
- name: Clone
uses: actions/checkout@v3
id: step1
- run: |
echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-api:stagging-$GITHUB_SHA" >> $GITHUB_ENV

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# GCP auth
- name: Authenticate the service account
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ env.GCP_SA_KEY }}'

- name: Install gcloud on the job runner
uses: google-github-actions/setup-gcloud@v1
with:
service_account_key: '${{ env.GCP_SA_KEY }}'
project_id: '${{ env.GCP_PROJECT_ID }}'
export_default_credentials: true

- name: Authorize admin account to push docker image
run: gcloud auth configure-docker

- name: Use gcloud CLI
run: 'gcloud info'

- name: Build & Push
uses: docker/build-push-action@v3
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: infra/docker/Dockerfile.api
#labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ env.IMAGE }}

- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v0
with:
service: ${{ env.SERVICE }}
region: ${{ env.REGION }}
image: ${{ env.IMAGE }}
# NOTE: env variables here
# env_vars: |
# NODE_ENV=production
# PORT=3000

# If required, use the Cloud Run url output in later steps
- name: Show Output
run: |
- echo ${{ steps.deploy.outputs.url }}
- echo ${{ steps.step1.outputs.IMAGE }}
Loading
Loading