Merge pull request #260 from DevKor-github/feat/review #52
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 using github actions & docker | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| permissions: | |
| contents: read | |
| jobs: | |
| push_to_registry: | |
| name: Push to aws container registry | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'corretto' | |
| - name: make application-prod.yml | |
| if: contains(github.ref, 'develop') || contains(github.ref, 'main') | |
| run: | | |
| cd ./src/main/resources | |
| touch ./application-prod.yml | |
| echo "${{ secrets.YML_PROD }}" > ./application-prod.yml | |
| shell: bash | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build with Gradle | |
| env: | |
| SPRING_PROFILES_ACTIVE: prod | |
| run: ./gradlew clean build --stacktrace | |
| shell: bash | |
| - name: Docker build & push to prod | |
| if: contains(github.ref, 'develop') || contains(github.ref, 'main') | |
| run: | | |
| docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }} | |
| docker build -t kodaero -f ./Dockerfile . | |
| docker tag kodaero:latest ${{ secrets.DOCKER_USER }}/kodaero:latest | |
| docker push ${{ secrets.DOCKER_USER }}/kodaero:latest | |
| pull_from_registry: | |
| name: Connect server ssh and pull from container registry | |
| needs: push_to_registry | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Get Github action IP | |
| id: ip | |
| uses: haythem/public-ip@v1.2 | |
| - name: Deploy to prod | |
| if: contains(github.ref, 'develop') || contains(github.ref, 'main') | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.HOST_NAME }} | |
| username: ${{ secrets.USER_NAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| port: ${{ secrets.PORT }} | |
| script: | | |
| docker pull ${{ secrets.DOCKER_USER }}/kodaero:latest | |
| chmod +x ./deploy.sh | |
| sudo ./deploy.sh dev | |
| docker image prune -f |