fix: redis 설정 수정 #25
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 AWS EC2 using Docker | |
| on: | |
| push: | |
| branches: | |
| - main | |
| env: | |
| DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_HUB_USERNAME }}/moddo | |
| SERVER_HOST: ${{ secrets.EC2_HOST }} | |
| SERVER_USER: ${{ secrets.EC2_USER }} | |
| SERVER_PASSWORD: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | |
| DOKCER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN}} | |
| jobs: | |
| build-and-push-docker: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| with: | |
| token: ${{secrets.CONFIG_SUBMODULE_TOKEN}} | |
| submodules: true | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Pull the existing Docker image (if any) | |
| run: | | |
| docker pull ${{ env.DOCKER_IMAGE_NAME }}:latest || true | |
| - name: Run tests (Testcontainers, Spring REST Docs) | |
| run: ./gradlew test asciidoctor --no-daemon | |
| - name: Build JAR | |
| run: ./gradlew bootJar --no-daemon | |
| - name: Build the Docker image with cache | |
| run: | | |
| docker build . --file Dockerfile --tag ${{ env.DOCKER_IMAGE_NAME }}:latest \ | |
| --cache-from=${{ env.DOCKER_IMAGE_NAME }}:latest \ | |
| --platform linux/amd64 | |
| - name: Login to Docker Hub using Access Token | |
| run: | | |
| echo ${{ env.DOKCER_HUB_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | |
| - name: Push the Docker image | |
| run: docker push ${{env.DOCKER_IMAGE_NAME}}:latest | |
| deploy-to-ec2: | |
| needs: build-and-push-docker | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Deploy to EC2 | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ env.SERVER_HOST }} | |
| username: ${{ env.SERVER_USER }} | |
| key: ${{ env.SERVER_PASSWORD }} | |
| port: 22 | |
| envs: GITHUB_SHA | |
| script: | | |
| docker compose stop app | |
| docker compose rm -f app | |
| docker rmi ${{env.DOCKER_IMAGE_NAME}}:latest | |
| docker compose pull app | |
| docker compose up -d app |