Skip to content

Commit

Permalink
ci: add cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
lmquang committed Nov 8, 2024
1 parent 8b07473 commit e9fd49d
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/build-and-push-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Dev - Build and Push to Artifact Registry

on:
push:
branches:
- 'develop'
- 'cicd'

env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
AR_REGION: asia-southeast1
REPOSITORY: icy
IMAGE_NAME: backend

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'

- name: Set up Cloud SDK
uses: 'google-github-actions/setup-gcloud@v0'

- name: Configure Docker
run: |
gcloud auth configure-docker ${{ env.AR_REGION }}-docker.pkg.dev --quiet
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and push final Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ env.AR_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
${{ env.AR_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max

# Setup kustomize
- name: Setup kustomize
run: |
curl -o kustomize --location https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
chmod u+x ./kustomize
mv kustomize /tmp
- name: Checkout dwarvesf/infrastructure
uses: actions/checkout@master
with:
repository: dwarvesf/infrastructure
token: ${{ secrets.GH_PAT }}
path: ./infrastructure
ref: main
- name: Update api version
run: |
cd ./infrastructure/icy/backend/$K8S_ENVIRONMENT
git config user.name lmquang
git config user.email [email protected]
/tmp/kustomize edit set image ${{ env.AR_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}=${{ env.AR_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
git commit -am "[skip ci] icy-backend ${K8S_ENVIRONMENT} image update"
git push origin main
68 changes: 68 additions & 0 deletions .github/workflows/build-and-push-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Prod - Build and Push to Artifact Registry

on:
push:
tags:
- 'v*'

env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
AR_REGION: asia-southeast1
REPOSITORY: icy
IMAGE_NAME: backend

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'

- name: Set up Cloud SDK
uses: 'google-github-actions/setup-gcloud@v0'

- name: Configure Docker
run: |
gcloud auth configure-docker ${{ env.AR_REGION }}-docker.pkg.dev --quiet
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and push final Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ env.AR_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
${{ env.AR_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max

# Setup kustomize
- name: Setup kustomize
run: |
curl -o kustomize --location https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
chmod u+x ./kustomize
mv kustomize /tmp
- name: Checkout dwarvesf/infrastructure
uses: actions/checkout@master
with:
repository: dwarvesf/infrastructure
token: ${{ secrets.GH_PAT }}
path: ./infrastructure
ref: main
- name: Update api version
run: |
cd ./infrastructure/icy/backend/$K8S_ENVIRONMENT
git config user.name lmquang
git config user.email [email protected]
/tmp/kustomize edit set image ${{ env.AR_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}=${{ env.AR_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
git commit -am "[skip ci] icy-backend ${K8S_ENVIRONMENT} image update"
git push origin main

0 comments on commit e9fd49d

Please sign in to comment.