Skip to content

Commit

Permalink
setting: github actions cd
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoya324 committed Oct 12, 2024
1 parent 2d427af commit 90ed0de
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: FINDY EGG CD Workflow

on:
push:
branches: [ "main", "develop" ]

permissions:
contents: read

jobs:
integration:
runs-on: ubuntu-latest

deploy:
runs-on: ubuntu-latest

needs: integration

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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: FINDY CI-CD Workflow
name: FINDY CI Workflow

on:
push:
Expand Down

0 comments on commit 90ed0de

Please sign in to comment.