FINDY CD Workflow #5
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: FINDY CD Workflow | |
on: | |
workflow_run: | |
workflows: [ "FINDY CI Workflow" ] | |
types: | |
- completed | |
permissions: | |
contents: read | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set environment variables for Docker Compose | |
run: | | |
echo "DOCKER_REPO=${{ secrets.DOCKER_REPO }}" >> $GITHUB_ENV | |
echo "GITHUB_RUN_NUMBER=${{ github.run_number }}" >> $GITHUB_ENV | |
- name: Check docker-compose.yml file | |
run: | | |
if [ ! -f docker/docker-compose.yml ]; then | |
echo "Error: docker/docker-compose.yml not found." | |
exit 1 | |
fi | |
- name: Copy docker-compose into instance | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.PUBLIC_DNS }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.PEM_KEY }} | |
source: "docker/docker-compose.yml" | |
target: "/home/${{ secrets.USERNAME }}/docker/docker-compose.yml" | |
strip_components: 3 | |
overwrite: true | |
debug: true | |
- name: Deploy to EC2 dev | |
uses: appleboy/[email protected] | |
if: contains(github.ref, 'develop') | |
with: | |
host: ${{ secrets.PUBLIC_DNS }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.PEM_KEY }} | |
script: | | |
cd /home/${{ secrets.USERNAME }} | |
export DOCKER_REPO=${{ secrets.DOCKER_REPO }} | |
export GITHUB_RUN_NUMBER=${{ github.run_number }} | |
echo "DOCKER_REPO=${DOCKER_REPO}" | |
echo "GITHUB_RUN_NUMBER=${GITHUB_RUN_NUMBER}" | |
envsubst < <(echo "${{ secrets.DOCKER_COMPOSE_DEV }}") > docker-compose.yml | |
echo ${{ secrets.DOCKER_PASSWORD }} | sudo docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
if [ "$(sudo docker ps -q)" ]; then sudo docker stop $(sudo docker ps -q); fi | |
if [ "$(sudo docker ps -a -q)" ]; then sudo docker rm $(sudo docker ps -a -q); fi | |
sudo docker pull ${{ secrets.DOCKER_REPO }}:develop-${{ github.run_number }} | |
sudo docker-compose -f docker-compose-dev.yml up -d | |
sudo docker image prune -f |