Merge branch 'refs/heads/develop' #13
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: deploy CI/CD on branch 'main' | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| # Lecture API Module CI | |
| build-lecture-api: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v2 | |
| with: | |
| distribution: temurin | |
| java-version: '17' | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x ./gradlew | |
| - name: Build API module | |
| run: ./gradlew build -x test | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: docker.io | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build & Push API image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/codin-lecture-api:latest | |
| # Lecture API Module CD | |
| deploy: | |
| needs: [build-lecture-api] | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Deploy to server via SSH | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.HOST }} | |
| username: ${{ secrets.USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| passphrase: ${{ secrets.SSH_KEY_PASSPHRASE }} | |
| port: ${{ secrets.PORT }} | |
| script: | | |
| echo ${{ secrets.PASSWORD }} | sudo -S su -c " | |
| docker ps -a | |
| cd /opt/project/codin-lecture | |
| docker rm -f codin-lecture-api || true | |
| docker pull ${{ secrets.DOCKERHUB_USERNAME }}/codin-lecture-api:latest | |
| docker compose -f lecture-docker-compose.yml up -d | |
| docker images -f "dangling=true" -q | xargs sudo docker rmi || true | |
| docker ps -a | |
| " |