[test] merge (#268) #45
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: CD with Gradle and Docker | |
| on: | |
| push: | |
| branches: | |
| - 'main' | |
| permissions: | |
| contents: read | |
| env: | |
| RESOURCE_PATH: src/main/resources | |
| COMPOSE_PATH: /home/ec2-user/compose | |
| APP_PORT: 8000 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: ☕️ set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| server-id: github | |
| settings-path: ${{ github.workspace }} | |
| - name: 🧾 Create application.yml from secret (base64) | |
| run: | | |
| mkdir -p ${{ env.RESOURCE_PATH }} | |
| echo "${{ secrets.APPLICATION_YML_PROD }}" | base64 --decode > ${{ env.RESOURCE_PATH }}/application.yml | |
| shell: bash | |
| - name: 🐘 Cache Gradle dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| gradle-${{ runner.os }}- | |
| - name: 👏🏻 grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: 🐘 build with Gradle (without test) | |
| run: ./gradlew clean build -x test --stacktrace | |
| - name: 🐳 Docker build & push | |
| run: | | |
| docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
| docker build --build-arg PORT=${{env.APP_PORT}} -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} | |
| - name: 🚀 deploy to server | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST_PROD }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_KEY }} | |
| port: ${{ secrets.EC2_PORT }} | |
| envs: GITHUB_SHA | |
| script: | | |
| echo "🗂️ Change Directory to Compose Path" | |
| cd ${{ env.COMPOSE_PATH }} | |
| sudo docker ps -a | |
| echo "🥳 Pulling new image" | |
| sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} | |
| echo "🚀 Run Blue-Green Deploy Script" | |
| sudo bash deploy.sh |