|
| 1 | +name: testAndDeploy |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - release |
| 7 | + - main |
| 8 | + types: |
| 9 | + - closed |
| 10 | + |
| 11 | +defaults: |
| 12 | + run: |
| 13 | + working-directory: ./BE/exceed |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-22.04 |
| 18 | + permissions: |
| 19 | + contents: read |
| 20 | + pull-requests: write |
| 21 | + |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v3 |
| 24 | + - name: Set up JDK 17 |
| 25 | + uses: actions/setup-java@v3 |
| 26 | + with: |
| 27 | + java-version: '17' |
| 28 | + distribution: 'temurin' |
| 29 | + |
| 30 | + - name: Grant execute permission for gradlew |
| 31 | + run: chmod +x gradlew |
| 32 | + |
| 33 | + - name: Cache Gradle |
| 34 | + uses: actions/cache@v3 |
| 35 | + with: |
| 36 | + path: | |
| 37 | + ~/.gradle/caches |
| 38 | + ~/.gradle/wrapper |
| 39 | + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} |
| 40 | + restore-keys: | |
| 41 | + ${{ runner.os }}-gradle- |
| 42 | +
|
| 43 | + - name: Build with Gradle Wrapper |
| 44 | + run: ./gradlew build |
| 45 | + |
| 46 | + - name: Jacoco Report to PR |
| 47 | + id: jacoco |
| 48 | + |
| 49 | + with: |
| 50 | + paths: ${{ github.workspace }}/**/build/reports/jacoco/test/jacocoTestReport.xml |
| 51 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + |
| 53 | + - name: Send docker-compose.yml |
| 54 | + uses: appleboy/scp-action@master |
| 55 | + with: |
| 56 | + host: ${{ secrets.SSH_HOST }} |
| 57 | + username: ${{ secrets.SSH_USERNAME }} |
| 58 | + key: ${{ secrets.SSH_KEY }} |
| 59 | + source: ./BE/exceed/docker-compose-prod.yml |
| 60 | + target: /home/ubuntu/backend-deploy |
| 61 | + |
| 62 | + - name: Send resources-develop-environment |
| 63 | + uses: appleboy/scp-action@master |
| 64 | + with: |
| 65 | + host: ${{ secrets.SSH_HOST }} |
| 66 | + username: ${{ secrets.SSH_USERNAME }} |
| 67 | + key: ${{ secrets.SSH_KEY }} |
| 68 | + source: ./BE/exceed/resources/gaebaljip-prod-environment |
| 69 | + target: /home/ubuntu/backend-deploy |
| 70 | + |
| 71 | + - name: Create .env.prod file |
| 72 | + run: | |
| 73 | + echo "${{ secrets.ENV_PROD_VARS }}" > .env.prod |
| 74 | +
|
| 75 | + - name: Send env file |
| 76 | + uses: appleboy/scp-action@master |
| 77 | + with: |
| 78 | + host: ${{ secrets.SSH_HOST }} |
| 79 | + username: ${{ secrets.SSH_USERNAME }} |
| 80 | + key: ${{ secrets.SSH_KEY }} |
| 81 | + source: ./BE/exceed/.env.prod |
| 82 | + target: /home/ubuntu/backend-deploy |
| 83 | + |
| 84 | + - name: Docker Image Build |
| 85 | + run: docker build -f Dockerfile-prod -t ${{ secrets.DOCKER_HUB_USER_NAME }}/gaebaljip-prod:latest . |
| 86 | + |
| 87 | + - name: Docker Hub Login |
| 88 | + uses: docker/login-action@v2 |
| 89 | + with: |
| 90 | + username: ${{ secrets.DOCKER_HUB_USER_NAME }} |
| 91 | + password: ${{ secrets.DOCKER_HUB_TOKEN }} |
| 92 | + |
| 93 | + - name: docker Hub Push |
| 94 | + run: docker push ${{ secrets.DOCKER_HUB_USER_NAME }}/gaebaljip-prod:latest |
| 95 | + |
| 96 | + - name: SSH Deploy |
| 97 | + |
| 98 | + with: |
| 99 | + host: ${{ secrets.SSH_HOST }} |
| 100 | + username: ${{ secrets.SSH_USERNAME }} |
| 101 | + key: ${{ secrets.SSH_KEY }} |
| 102 | + script: | |
| 103 | + cd backend-deploy/BE/exceed |
| 104 | + sudo docker-compose down |
| 105 | + sudo docker pull ${{ secrets.DOCKER_HUB_USER_NAME }}/gaebaljip-prod:latest |
| 106 | + sudo docker-compose up --build -d |
| 107 | + sudo docker image prune -a -f |
| 108 | + |
| 109 | + |
0 commit comments