Backend AWS EC2 CD #8
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: Backend AWS EC2 CD | |
on: | |
workflow_run: | |
workflows: ["Backend Docker Image CI"] | |
types: | |
- completed | |
jobs: | |
build: | |
runs-on: [self-hosted, backend] | |
steps: | |
- name: Stop current Docker containers | |
run: docker-compose -f ./backend/docker-compose.prod.yml down | |
- name: Delete old Docker image | |
run: docker rmi -f nathan7934/whosaidit-backend || true | |
- name: Login to Dockerhub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Pull the Docker image | |
run: docker pull nathan7934/whosaidit-backend:latest | |
# Check out the repository so we can access the docker-compose.prod.yml file | |
- uses: actions/checkout@v3 | |
with: | |
ref: master | |
# Create a .env file with the necessary environment variables in the runner's workspace | |
- name: Create .env file | |
run: | | |
echo "${{ secrets.BACKEND_ENV_VARS }}" > ./backend/.env | |
- name: Start new Docker containers | |
run: docker-compose -f ./backend/docker-compose.prod.yml up -d |