Skip to content

Commit

Permalink
add prod workflow to default branch
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmwang committed Aug 16, 2024
1 parent fda382f commit faf96ab
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/cd-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: Deploy to Production

concurrency: prod

on:
workflow_dispatch:

env:
artifact-retention-days: 7

jobs:
branch-check:
name: Check Branch
runs-on: ubuntu-latest
environment: prod

build-backend:
name: Build Backend Image
needs: branch-check
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Build Image with Tag
run: |
docker build --target backend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod" .
docker save "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod" --output "bt-backend-prod.tar"
- name: Upload Image as Artifact
uses: actions/upload-artifact@v4
with:
name: "bt-backend-prod.tar"
path: "bt-backend-prod.tar"
retention-days: ${{ env.artifact-retention-days }}
overwrite: true

build-frontend:
name: Build Frontend Image
needs: branch-check
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Build Image with Tag
run: |
docker build --target frontend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod" .
docker save "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod" --output "bt-frontend-prod.tar"
- name: Upload Image as Artifact
uses: actions/upload-artifact@v4
with:
name: "bt-frontend-prod.tar"
path: "bt-frontend-prod.tar"
retention-days: ${{ env.artifact-retention-days }}
overwrite: true

push-backend:
name: Push Backend Image
needs: build-backend
runs-on: ubuntu-latest

steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Download Artifact as Image
uses: actions/download-artifact@v4
with:
name: "bt-backend-prod.tar"

- name: Push Image to Docker Hub
run: |
docker import "bt-backend-prod.tar" "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod"
docker push "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod"
push-frontend:
name: Push Frontend Image
needs: build-frontend
runs-on: ubuntu-latest

steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Download Artifact as Image
uses: actions/download-artifact@v4
with:
name: "bt-frontend-prod.tar"

- name: Push Image to Docker Hub
run: |
docker import "bt-frontend-prod.tar" "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod"
docker push "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod"
deploy:
name: Deploy with SSH
needs: [push-backend, push-frontend]
runs-on: ubuntu-latest

steps:
- name: SSH and Helm Install
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: root
key: ${{ secrets.SSH_KEY }}
script: |
cd ./infra
if helm status bt-prod-app ; then
kubectl rollout restart bt-prod-app-backend
kubectl rollout restart bt-prod-app-frontend
else
helm install bt-prod-app ./app --namespace=bt \
--set host=stanfurdtime.com
fi

0 comments on commit faf96ab

Please sign in to comment.