Skip to content

Merge pull request #541 from bounswe/feature/FE-test-components #158

Merge pull request #541 from bounswe/feature/FE-test-components

Merge pull request #541 from bounswe/feature/FE-test-components #158

Workflow file for this run

name: Deploy Dev to Docker Hub and DigitalOcean
on:
push:
branches:
- dev
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DO_SSH_PASSWORD: ${{ secrets.DO_SSH_PASSWORD }}
DO_REMOTE: ${{ secrets.DO_REMOTE }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Log in to Docker Hub
- name: Docker Hub login
run: echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
# Build the frontend image
- name: Build frontend Docker image
run: |
FRONTEND_IMAGE_TAG=${{ github.sha }}
FRONTEND_API_URL="http://${{ secrets.DO_REMOTE }}:30002"
docker build --build-arg REACT_APP_API_BASE_URL=$FRONTEND_API_URL -t 24cmpe451group2/frontend:$FRONTEND_IMAGE_TAG ./frontend
docker tag 24cmpe451group2/frontend:${{ github.sha }} 24cmpe451group2/frontend:latest
# Build the backend image
- name: Build backend Docker image
run: |
BACKEND_IMAGE_TAG=${{ github.sha }}
docker build -t 24cmpe451group2/backend:$BACKEND_IMAGE_TAG ./backend
docker tag 24cmpe451group2/backend:${{ github.sha }} 24cmpe451group2/backend:latest
# Build the annotations image
- name: Build annotations Docker image
run: |
ANNOTATIONS_IMAGE_TAG=${{ github.sha }}
docker build -t 24cmpe451group2/annotations:$ANNOTATIONS_IMAGE_TAG ./annotations_project
docker tag 24cmpe451group2/annotations:${{ github.sha }} 24cmpe451group2/annotations:latest
# Push the frontend image to Docker Hub
- name: Push frontend Docker image
run: |
FRONTEND_IMAGE_TAG=${{ github.sha }}
docker push 24cmpe451group2/frontend:$FRONTEND_IMAGE_TAG
docker push 24cmpe451group2/frontend:latest
# Push the backend image to Docker Hub
- name: Push backend Docker image
run: |
BACKEND_IMAGE_TAG=${{ github.sha }}
docker push 24cmpe451group2/backend:$BACKEND_IMAGE_TAG
docker push 24cmpe451group2/backend:latest
# Push the annotations image to Docker Hub
- name: Push annotations Docker image
run: |
ANNOTATIONS_IMAGE_TAG=${{ github.sha }}
docker push 24cmpe451group2/annotations:$ANNOTATIONS_IMAGE_TAG
docker push 24cmpe451group2/annotations:latest
# Login to DigitalOcean Droplet and trigger deployment updates
- name: Deploy to DigitalOcean
run: |
sshpass -p "${{ secrets.DO_SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no root@${{ secrets.DO_REMOTE }} << EOF
echo "Updating backend and frontend deployments"
kubectl set image deployment/frontend frontend=24cmpe451group2/frontend:${{ github.sha }} --namespace=default
kubectl set image deployment/backend backend=24cmpe451group2/backend:${{ github.sha }} --namespace=default
kubectl set image deployment/annotations annotations=24cmpe451group2/annotations:${{ github.sha }} --namespace=default
kubectl rollout status deployment/frontend --timeout=5m --namespace=default
kubectl rollout status deployment/backend --timeout=5m --namespace=default
kubectl rollout status deployment/annotations --timeout=5m --namespace=default
EOF