Docker CD #67
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: Docker CD | |
on: | |
# 워크플로우가 수동으로 실행되거나, CI 워크플로우가 성공적으로 완료되면 실행됩니다. | |
workflow_dispatch: | |
jobs: | |
build: | |
if: ${{ contains(github.event.head_commit.message, '#deploye') }} | |
runs-on: ubuntu-latest # ubuntu 최신 버전에서 script를 실행 | |
steps: | |
# 지정한 저장소(현재 REPO)에서 코드를 워크플로우 환경으로 가져오도록 하는 github action | |
- name: checkout code | |
uses: actions/checkout@v4 | |
- name: create remote directory # ec2 서버에 디렉토리를 하나 만들어준다. | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.APP_SERVER_IP }} | |
username: ubuntu | |
key: ${{ secrets.AWS_GENERAL_SSH_KEY }} | |
script: mkdir -p /home/ubuntu/app/petlink | |
- name: copy project # ssh key를 이용해 현재 푸시된 소스를 서버에 복사한다. | |
uses: burnett01/rsync-deployments@6.0.0 | |
with: | |
switches: -avzr --delete # rsync 명령어 옵션 | |
remote_path: /home/ubuntu/app/petlink | |
remote_host: ${{ secrets.APP_SERVER_IP }} | |
remote_user: ubuntu | |
remote_key: ${{ secrets.AWS_GENERAL_SSH_KEY }} | |
- name: Set up .env file # 원격서버에 .env 파일을 만들며 복제해준다 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.APP_SERVER_IP }} | |
username: ubuntu | |
key: ${{ secrets.AWS_GENERAL_SSH_KEY }} | |
script: | | |
cd /home/ubuntu/app/petlink | |
touch ./.env | |
echo "${{ secrets.ENV }}" > ./.env | |
## docker compose up | |
- name: docker compose up | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.APP_SERVER_IP }} | |
username: ubuntu | |
key: ${{ secrets.AWS_GENERAL_SSH_KEY }} | |
script: | | |
cd /home/ubuntu/app/petlink | |
sudo docker ps -q | xargs -r sudo docker rm -f | |
sudo docker pull ${{ secrets.DOCKER_ID }}/petlink:latest | |
docker-compose up -d | |
docker image prune -f |