Merge branch 'main' of https://github.com/Luxshan2000/drivers-license… #40
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: CICD Frontend and Backend | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build Docker frontend image | |
run: docker build -t drivesmart/drivesmart-frontend ./webapp | |
- name: Publish frontend image to Docker Hub | |
run: docker push drivesmart/drivesmart-frontend | |
build-backend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build Docker backend image | |
run: docker build -t drivesmart/drivesmart-backend ./backend | |
- name: Publish backend image to Docker Hub | |
run: docker push drivesmart/drivesmart-backend | |
deploy: | |
needs: [build-frontend, build-backend] | |
runs-on: aws-ec2 | |
steps: | |
- name: Pull frontend image from Docker Hub | |
run: docker pull drivesmart/drivesmart-frontend | |
- name: Pull backend image from Docker Hub | |
run: docker pull drivesmart/drivesmart-backend | |
- name: Delete old frontend container | |
run: docker rm -f drivesmart-frontend-container | |
- name: Delete old backend container | |
run: docker rm -f drivesmart-backend-container | |
- name: Run frontend container | |
run: docker run -d -p 3000:3000 --name drivesmart-frontend-container drivesmart/drivesmart-frontend | |
- name: Run backend container | |
run: docker run -d -p 5000:5000 --name drivesmart-backend-container drivesmart/drivesmart-backend |