fix #14
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: CD | |
on: | |
push: | |
branches: ['CD_test_branch'] | |
tags: ['v*.*.*'] | |
env: | |
TARGET_DIR: '~/api/${{ github.event.repository.name }}' | |
jobs: | |
docker-hub: | |
name: Docker Hub Image Push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Sending Image to Docker Hub | |
uses: mr-smithers-excellent/docker-build-push@v5 | |
with: | |
image: gerocuidadodev/gerocuidado-usuario-api | |
registry: docker.io | |
directory: ./ | |
dockerfile: ./Dockerfile.prod | |
tags: latest | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
deploy-ec2: | |
name: Deploy EC2 | |
needs: docker-hub | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the files | |
uses: actions/checkout@v2 | |
- name: Executing remote ssh commands using ssh key | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST_DNS }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
cd ${{env.TARGET_DIR}} | |
git pull | |
git checkout CD_test_branch | |
git pull | |
sudo docker compose stop | |
sudo docker compose rm gerocuidado-usuario-api-prod | |
sudo docker compose -f docker-compose.prod.yml up -V --force-recreate --build -d |