feat: Swagger 설정 및 모집글 API 문서화 완료 #35
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: CI/CD for Spring Boot + MySQL with Docker Compose | |
| on: | |
| push: | |
| branches: [ "main", "store-service/main" ] | |
| pull_request: | |
| branches: [ "main", "store-service/main" ] | |
| env: | |
| SERVICE_NAME: store-service # 예: order-service | |
| DOCKER_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_NAME }}:latest | |
| EC2_HOST: ${{ secrets.EC2_HOST }} | |
| EC2_SSH_USER: ec2-user | |
| PRIVATE_KEY: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | |
| TIMEZONE: Asia/Seoul | |
| DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
| DOCKER_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
| PROJECT_PATH: /home/ec2-user/delivery-system/store-service # 예: /home/ec2-user/delivery-system/order-service | |
| APPLICATION: ${{ secrets.APPLICATION }} | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| environment: store-service | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - name: Set up application.properties | |
| run: | | |
| mkdir -p "${{ env.SERVICE_NAME }}"/src/main/resources | |
| echo "${{ env.APPLICATION }}" > "${{ env.SERVICE_NAME }}/src/main/resources/application.properties" | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x ${{ env.SERVICE_NAME }}/gradlew | |
| - name: Build Spring Boot Application | |
| working-directory: ${{ env.SERVICE_NAME }} | |
| run: ./gradlew build | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ env.DOCKER_USERNAME }} | |
| password: ${{ env.DOCKER_TOKEN }} | |
| - name: Build Docker Image | |
| run: docker build -t ${{ env.DOCKER_IMAGE }} ./${{ env.SERVICE_NAME }} | |
| - name: Push Docker Image | |
| run: docker push ${{ env.DOCKER_IMAGE }} | |
| deploy-to-ec2: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' | |
| needs: build-and-push | |
| environment: store-service | |
| steps: | |
| - name: Deploy to EC2 via SSH | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ env.EC2_HOST }} | |
| username: ${{ env.EC2_SSH_USER }} | |
| key: ${{ env.PRIVATE_KEY }} | |
| script: | | |
| cd ${{ env.PROJECT_PATH }} | |
| sudo docker compose pull | |
| sudo docker compose down | |
| sudo docker compose up -d |