⬆️ [add] #15 S3 의존성 추가 #7
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: Docker CI/CD with Compose | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| # 1. 소스코드 체크아웃 | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # 2. Docker Buildx 설정 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # 3. DockerHub 로그인 | |
| - name: DockerHub 로그인 | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # 4. Docker 이미지 빌드 및 푸시 | |
| - name: Docker 이미지 빌드 및 푸시 | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: yeeun0702/spring-plus:latest | |
| # 5. docker-compose.yml을 EC2에 복사 | |
| - name: EC2에 docker-compose.yml 업로드 | |
| uses: appleboy/scp-action@v0.1.4 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_KEY }} | |
| source: docker-compose.yml | |
| target: /home/${{ secrets.EC2_USER }}/app/ | |
| # 6. EC2에서 docker-compose 실행 | |
| - name: EC2에서 docker-compose로 배포 | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_KEY }} | |
| script: | | |
| cd /home/${{ secrets.EC2_USER }}/app | |
| docker compose pull | |
| docker compose down || true | |
| docker compose up -d |