diff --git a/.github/workflows/code-analyze-push.yml b/.github/workflows/code-analyze-push.yml deleted file mode 100644 index 900bcde7..00000000 --- a/.github/workflows/code-analyze-push.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Code Analyze Push - -run-name: Run code analyze triggered with push by ${{github.actor}} - -on: - push: - branches: - - dev -jobs: - build: - name: Build and analyze - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: 21 - distribution: 'temurin' # Alternative distribution options are available. - - name: Cache SonarQube packages - uses: actions/cache@v4 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Cache Gradle packages - uses: actions/cache@v4 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - name: Build with tests - env: - JWT_SECRET: ${{ secrets.JWT_SECRET }} - continue-on-error: true - run: ./gradlew build --info - - - name: SonarQube Analysis - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - JWT_SECRET: ${{ secrets.JWT_SECRET }} - run: ./gradlew sonar --info \ No newline at end of file diff --git a/.github/workflows/code-analyze-pr.yml b/.github/workflows/code-analyze-sonarqube.yml similarity index 81% rename from .github/workflows/code-analyze-pr.yml rename to .github/workflows/code-analyze-sonarqube.yml index 08f369c6..5c258ca8 100644 --- a/.github/workflows/code-analyze-pr.yml +++ b/.github/workflows/code-analyze-sonarqube.yml @@ -1,6 +1,6 @@ -name: Code Analyze Pull Request +name: Code Analyze With SonarQube -run-name: Run code analyze triggered with pull request by ${{github.actor}} +run-name: Run code analyze triggered by ${{github.actor}} on: pull_request: @@ -8,6 +8,13 @@ on: branches: - main - dev + paths: + - 'src/**' + push: + branches: + - dev + paths: + - 'src/**' jobs: build: @@ -15,26 +22,31 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: 21 - distribution: 'temurin' # Alternative distribution options are available. + distribution: 'temurin' + - name: Cache SonarQube packages uses: actions/cache@v4 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages uses: actions/cache@v4 with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} restore-keys: ${{ runner.os }}-gradle + - name: Build with tests env: JWT_SECRET: ${{ secrets.JWT_SECRET }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1fac436f..e6c01564 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,13 +1,13 @@ -name: CI/CD Deploy +name: CI/CD Deploy and Start services -run-name: Deploy springboot as backend image to ECR by ${{github.actor}} +run-name: Deploy to ECR and Start services by ${{github.actor}} on: push: - branches: [ "main" ] - paths-ignore: - - 'README.md' - - '.gitignore' + branches: + - main + paths: + - 'src/**' jobs: build: @@ -32,20 +32,31 @@ jobs: - name: Build with Gradle Wrapper run: ./gradlew build -x test - - name: Build image - run: | - docker build -t ${{ secrets.AWS_ORGANIZATION }}/backend . - docker tag ${{ secrets.AWS_ORGANIZATION }}/backend:latest ${{ secrets.AWS_ECR_BACKEND_REPO }}:latest - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 + - name: Login to DockerHub + uses: docker/login-action@v3 with: - role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} - aws-region: ${{ secrets.AWS_REGION }} + username: ${{secrets.DOCKER_USERNAME}} + password: ${{secrets.DOCKER_TOKEN}} - - name: Login to Amazon ECR - uses: aws-actions/amazon-ecr-login@v2 + - name: Build and Push Docker Image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{secrets.DOCKER_USERNAME}}/if-be:latest - - name: Push image to ECR - run: | - docker push ${{ secrets.AWS_ECR_BACKEND_REPO }}:latest \ No newline at end of file + start-services: + needs: build + runs-on: ubuntu-latest + steps: + - name: Connect to cloud server and run Docker commands + uses: appleboy/ssh-action@v1.2.2 + with: + host: ${{secrets.BACKEND_HOST}} + username: ${{secrets.CLOUD_USERNAME}} + key: ${{secrets.CLOUD_SECRET_KEY}} + port: ${{secrets.CLOUD_PORT}} + script: | + cd ~ + /bin/bash run_springboot.sh diff --git a/.github/workflows/start-service.yml b/.github/workflows/start-service.yml deleted file mode 100644 index 90f6cdff..00000000 --- a/.github/workflows/start-service.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Start services - -run-name: Start containers in cloud service by ${{ github.actor }} - -on: - workflow_run: - workflows: [CI/CD Deploy] - types: - - completed - -jobs: - start-services: - runs-on: ubuntu-latest - steps: - - name: Connect to cloud server - uses: appleboy/ssh-action@v1.2.2 - with: - host: ${{secrets.CLOUD_HOST}} - username: ${{secrets.CLOUD_USERNAME}} - key: ${{secrets.CLOUD_SECRET_KEY}} - port: ${{secrets.CLOUD_PORT}} - script: | - cd ~ - sudo docker compose stop backend - sudo docker compose rm -f backend - sudo docker compose pull backend - sudo docker compose up -d backend diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 275af44a..e240f9e2 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -3,7 +3,7 @@ spring: cookie: secure: true datasource: - url: jdbc:mariadb://mariadb:3306/${MARIADB_DATABASE} + url: jdbc:mariadb://${MARIADB_HOST}:3306/${MARIADB_DATABASE} driver-class-name: org.mariadb.jdbc.Driver username: ${MARIADB_USER} password: ${MARIADB_PASSWORD}