Merge pull request #75 from pirogramming/refactor/image-change #20
This file contains hidden or 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: Deploy to EC2 | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 코드 체크아웃 | |
| uses: actions/checkout@v4 | |
| # docker-compose.yml의 env_file: .env 를 compose가 파싱할 때 파일 존재만 확인하면 되고 | |
| # 실제 값은 필요 없다 (빌드/푸시는 컨테이너를 실행하지 않으므로). 실제 값은 EC2의 .env가 담당. | |
| - name: 빌드용 더미 .env 생성 | |
| run: touch .env | |
| - name: Docker Hub 로그인 | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # docker-compose.yml에 정의된 web 서비스만 빌드/푸시한다. | |
| # db(mysql), nginx는 공개 이미지를 그대로 pull해서 쓰므로 push 대상이 아니다. | |
| - name: web 이미지 빌드 | |
| run: docker compose build web | |
| - name: web 이미지 Docker Hub에 push | |
| run: docker compose push web | |
| deploy: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: EC2에 SSH로 접속해 배포 | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_KEY }} | |
| # EC2의 ~/caffeine-diary 디렉토리에 docker-compose.yml, nginx.conf, .env가 | |
| # 미리 준비되어 있어야 한다 (최초 1회는 수동 세팅 필요). | |
| script: | | |
| cd ~/CaffeineDiary | |
| docker compose pull | |
| docker compose up -d | |
| docker image prune -f |