Deploy to Development #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Dev | |
on: | |
workflow_dispatch: | |
inputs: | |
ttl: | |
description: "Deployment time to live in seconds" | |
required: true | |
type: number | |
default: 86400 | |
env: | |
artifact-retention-days: 3 | |
jobs: | |
build-push-backend: | |
name: Build and Push Backend Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set vars | |
id: vars | |
run: echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV | |
- name: Build Image with Tag | |
run: | | |
docker build --target backend-dev --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}" . | |
docker save "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}" --output "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}.tar" | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push Image to Docker Hub | |
run: | | |
docker push "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}" | |
- name: Upload Image as Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}.tar | |
path: ${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}.tar | |
retention-days: env.artifact-retention-days | |
overwrite: true | |
build-push-frontend: | |
name: Build and Push Frontend Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set vars | |
id: vars | |
run: echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV | |
- name: Build Image with Tag | |
run: | | |
docker build --target frontend-dev --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}" . | |
docker save "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}" --output "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}.tar" | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push Image to Docker Hub | |
run: | | |
docker push "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}" | |
- name: Upload Image as Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}.tar | |
path: ${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}.tar | |
retention-days: env.artifact-retention-days | |
overwrite: true | |
deploy: | |
name: Deploy with SSH | |
needs: [build-push-backend, build-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 | |
helm uninstall bt-dev-app-${{ env.sha_short }} || true | |
helm install bt-dev-app-${{ env.sha_short }} ./app --namespace=bt \ | |
--set env=dev \ | |
--set ttl=${{ inputs.ttl }} \ | |
--set frontend.image.tag=${{ env.sha_short }} \ | |
--set backend.image.tag=${{ env.sha_short }} \ | |
--set host=${{ env.sha_short }}.stanfurdtime.com \ | |
--set mongoUri=mongodb://bt-dev-mongo-mongodb.bt.svc.cluster.local:27017/bt \ | |
--set redisUri=redis://bt-dev-redis-master.bt.svc.cluster.local:6379 \ | |
--set nodeEnv=development |