[YS-401] chore: GitHub Actions 워크플로우에 ktlint 코드 품질 검사 추가 (#135) #12
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: Production Server CI/CD | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| jobs: | |
| ci: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: ✔️ checkout | |
| uses: actions/checkout@v3 | |
| - name: ✔️ set JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: ✔️ create application.yml | |
| run: | | |
| cd ./infrastructure/src/main/resources | |
| touch ./application-prod.yml | |
| echo "${{ secrets.PROD_YML }}" >> ./application-prod.yml | |
| shell: bash | |
| - name: ✔️ give executive authority to gradlew | |
| run: chmod +x gradlew | |
| - name: ✔️ build gradlew | |
| run: ./gradlew clean build -x test --stacktrace | |
| - name: ✔️ build docker image and push to docker hub | |
| run: | | |
| docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
| docker build --build-arg SPRING_PROFILES_ACTIVE=prod -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:prod . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:prod | |
| - name: ✔️ send deploy-prod.sh to EC2 production server | |
| uses: appleboy/scp-action@master | |
| with: | |
| username: ubuntu | |
| host: ${{ secrets.PROD_WAS_HOST }} | |
| key: ${{ secrets.PROD_WAS_KEY }} | |
| port: ${{ secrets.WAS_SSH_PORT }} | |
| source: "./scripts/deploy-prod.sh" | |
| target: "/home/ubuntu/" | |
| - name: ✔️ send docker-compose-prod.yml to EC2 production server | |
| uses: appleboy/scp-action@master | |
| with: | |
| username: ubuntu | |
| host: ${{ secrets.PROD_WAS_HOST }} | |
| key: ${{ secrets.PROD_WAS_KEY }} | |
| port: ${{ secrets.WAS_SSH_PORT }} | |
| source: "./docker-compose-prod.yml" | |
| target: "/home/ubuntu/" | |
| cd: | |
| needs: ci | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: ✔️ checkout | |
| uses: actions/checkout@v3 | |
| - name: ✔️ pull docker image from docker hub and deploy | |
| uses: appleboy/ssh-action@master | |
| with: | |
| username: ubuntu | |
| host: ${{ secrets.PROD_WAS_HOST }} | |
| key: ${{ secrets.PROD_WAS_KEY }} | |
| script: | | |
| sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
| sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:prod | |
| chmod 777 ./scripts/deploy-prod.sh | |
| cp ./scripts/deploy-prod.sh ./deploy-prod.sh | |
| ./deploy-prod.sh | |
| docker image prune -f |