Merge pull request #201 from capgoing/perf/#200 #148
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 FOR DEVELOP | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| env: | |
| DOCKERHUB_REPOSITORY: ${{ secrets.DOCKER_REPOSITORY }} | |
| jobs: | |
| CI: | |
| name: Continuous Integration | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Get short SHA | |
| id: slug | |
| run: echo "sha7=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_OUTPUT | |
| - name: Checkout with submodules | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.ACCESS_TOKEN }} | |
| submodules: recursive | |
| fetch-depth: 0 | |
| - name: Update git submodules | |
| run: git submodule update --init --recursive | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: 'gradle' | |
| - name: Verify Backend_Config files | |
| run: ls -al Backend_Config | |
| - name: Build with Gradle Wrapper without Test | |
| run: | | |
| echo "▶ Running Gradle build and test..." | |
| ./gradlew --no-daemon clean build -x test | |
| - name: Build summary | |
| if: success() | |
| run: | | |
| echo " Gradle build completed successfully without tests." | |
| - name: Mark failure if tests failed | |
| if: failure() | |
| run: | | |
| echo "Tests failed. Please check the test report/logs for details." | |
| exit 1 | |
| - name: Upload jar file to Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: jar_files | |
| path: build/libs/*.jar | |
| - name: Upload Dockerfile to Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Dockerfile | |
| path: ./Dockerfile | |
| CD_Delivery_to_DockerHub: | |
| name: CD_Delivery_to_DockerHub | |
| needs: CI | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout with submodules | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.ACCESS_TOKEN }} | |
| submodules: recursive | |
| fetch-depth: 0 | |
| - name: Download jar file from Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: jar_files | |
| path: build/libs | |
| - name: Download Dockerfile file from Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: Dockerfile | |
| path: ./ | |
| - name: Update git submodules | |
| run: git submodule update --init --recursive | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Get short SHA | |
| id: slug | |
| run: echo "sha7=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_OUTPUT | |
| - name: Build, tag, and push image to DockerHub | |
| id: build-image | |
| env: | |
| USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
| IMAGE_TAG: ${{ steps.slug.outputs.sha7 }} | |
| run: | | |
| docker build -t $USERNAME/$DOCKERHUB_REPOSITORY:$IMAGE_TAG -t $USERNAME/$DOCKERHUB_REPOSITORY:latest . | |
| docker push $USERNAME/$DOCKERHUB_REPOSITORY --all-tags | |
| echo "image=$USERNAME/$DOCKERHUB_REPOSITORY:$IMAGE_TAG&latest" >> $GITHUB_OUTPUT | |
| CD_Deploy: | |
| name: CD_Deploy | |
| needs: CD_Delivery_to_DockerHub | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout with submodules | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.ACCESS_TOKEN }} | |
| submodules: recursive | |
| fetch-depth: 0 | |
| - name: Update git submodules | |
| run: git submodule update --init --recursive | |
| - name: Get short SHA | |
| id: slug | |
| run: echo "sha7=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_OUTPUT | |
| - name: Executing remote ssh commands | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.REMOTE_IP }} | |
| username: ${{ secrets.REMOTE_USER }} | |
| key: ${{ secrets.REMOTE_PRIVATE_KEY }} | |
| port: ${{ secrets.REMOTE_SSH_PORT }} | |
| script: | | |
| export DOCKER_IMAGE="${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:latest" | |
| export DOCKER_COMPOSE_PATH="${{ secrets.DOCKER_COMPOSE_PATH }}" | |
| cd /home/ubuntu/scripts | |
| ./rolling-update.sh | |
| echo "Stopping current containers..." | |
| docker compose -f $DOCKER_COMPOSE_PATH down | |
| echo "Pulling the latest image..." | |
| docker compose -f $DOCKER_COMPOSE_PATH pull | |
| echo "Starting new deployment..." | |
| docker compose -f $DOCKER_COMPOSE_PATH up -d | |