Skip to content

Commit

Permalink
seperate frontend and backend workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
tabriszhu913 committed Jun 26, 2022
1 parent 79aa89c commit e6ce572
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 117 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI workflow for backend

on: push
# push:
# paths:
# - "backend/**"

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
cache: gradle

- name: Test backend
run: |
cd backend
./gradlew test
build-and-push-backend:
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'main' }}
needs: test
steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
cache: gradle

- name: Build bootJar
run: |
cd backend
./gradlew bootJar
- name: Build Image and Deploy
uses: ./.github/workflows/build-deploy.yml
with:
folder: backend
image_name: booking-backend
deployment_name: booking-backend
73 changes: 73 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Reusable workflow to build and deploy

on:
workflow_call:
inputs:
folder:
required: true
type: string
image_name:
required: true
type: string
deployment_name:
required: true
type: string

env:
PROJECT_ID: pivot-lab-2203
GKE_CLUSTER: booking-app-cluster
GKE_ZONE: us-west1
DOCKER_REGISTRY: us-west1-docker.pkg.dev/pivot-lab-2203/docker-image-repo

jobs:
build-image-and-push:
runs-on: ubuntu-latest
steps:
- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v0
with:
credentials_json: '${{ secrets.GOOGLE_SA_CREDENTIALS }}'
token_format: access_token

- uses: docker/setup-buildx-action@v1

- uses: docker/login-action@v1
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: oauth2accesstoken
password: '${{ steps.auth.outputs.access_token }}'

- name: Build and push image to artifact registry
uses: docker/build-push-action@v2
with:
context: ${{ inputs.folder }}
file: ${{ inputs.folder }}/Dockerfile
push: true
tags: ${{ env.DOCKER_REGISTRY }}/${{ inputs.image_name }}:latest

update-image:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v0
with:
credentials_json: '${{ secrets.GOOGLE_SA_CREDENTIALS }}'
token_format: access_token

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ env.PROJECT_ID }}
install_components: kubectl

- run: |-
gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE"
- name: Deploy
run: |-
kubectl rollout restart deployment ${{ inputs.deployment_name }}
kubectl rollout status deployment ${{ inputs.deployment_name }}
20 changes: 20 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI workflow for frontend

on: push
# push:
# paths:
# - "booking-system-ui/**"

jobs:
build-and-push-frontend:
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'main' }}
steps:
- uses: actions/checkout@v3

- name: Build Image and Deploy
uses: ./.github/workflows/build-deploy.yml
with:
folder: backend
image_name: booking-backend
deployment_name: booking-backend
117 changes: 0 additions & 117 deletions .github/workflows/main.yml

This file was deleted.

0 comments on commit e6ce572

Please sign in to comment.