From 243001a3d52d86434cf7db1eda80db670716df5a Mon Sep 17 00:00:00 2001 From: Saccilotto Date: Mon, 3 Mar 2025 21:15:18 -0300 Subject: [PATCH 1/3] feat: added github actions based on build test push image and trigger steps alongside dockerfile --- .github/workflows/build-trigger.yml | 44 +++++++++++++++++++++++++++++ Dockerfile | 11 ++++++++ 2 files changed, 55 insertions(+) create mode 100644 .github/workflows/build-trigger.yml create mode 100644 Dockerfile diff --git a/.github/workflows/build-trigger.yml b/.github/workflows/build-trigger.yml new file mode 100644 index 00000000..44d401d3 --- /dev/null +++ b/.github/workflows/build-trigger.yml @@ -0,0 +1,44 @@ +name: Backend CI/CD + +on: + push: + branches: [ main, master ] + workflow_dispatch: + +jobs: + build-and-test: + name: Build and Test Backend + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + distribution: 'adopt' + java-version: '11' + + - name: Build with Gradle + run: ./gradlew build + + - name: Run tests + run: ./gradlew test + + - name: Build and push Docker image + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin + docker build -t your-org/backend:latest . + docker push your-org/backend:latest + + # Trigger infrastructure deployment + - name: Trigger infrastructure deployment + uses: peter-evans/repository-dispatch@v2 + with: + token: ${{ secrets.REPO_ACCESS_TOKEN }} + repository: your-org/infrastructure + event-type: backend-updated + client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}' \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f6289ff0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +# Use an official OpenJDK runtime as a parent image +FROM openjdk:11-jre-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the built jar file from the host to the container +COPY build/libs/*.jar app.jar + +# Run the jar file +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file From 1d1e2a3dc6017e6a6de52a268f338b349f1b88b6 Mon Sep 17 00:00:00 2001 From: jhonatapers Date: Tue, 13 May 2025 20:39:56 -0300 Subject: [PATCH 2/3] fix: update gradlew file permissions to executable --- gradlew | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 gradlew diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From 143dbd19d7eea4bfe16a8ba62a10a33edf7d3e33 Mon Sep 17 00:00:00 2001 From: jhonatapers Date: Tue, 13 May 2025 20:48:58 -0300 Subject: [PATCH 3/3] feat: add GitHub Actions workflows for Docker image build and push; update application configuration files --- .../workflows/build-and-push-docker-image.yml | 42 ++++++++++++++++++ .github/workflows/build-trigger.yml | 44 ------------------- .github/workflows/latest.yml | 16 +++++++ .github/workflows/nightly.yaml | 16 +++++++ .github/workflows/release.yml | 15 +++++++ .../src/main/resources/application-dev.yml | 21 +++++++++ .../src/main/resources/application-hmg.yml | 14 ------ .../src/main/resources/application-local.yml | 3 ++ .../src/main/resources/application.yml | 2 +- 9 files changed, 114 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/build-and-push-docker-image.yml delete mode 100644 .github/workflows/build-trigger.yml create mode 100644 .github/workflows/latest.yml create mode 100644 .github/workflows/nightly.yaml create mode 100644 .github/workflows/release.yml create mode 100644 infrastructure/src/main/resources/application-dev.yml delete mode 100644 infrastructure/src/main/resources/application-hmg.yml diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml new file mode 100644 index 00000000..8fb0ef57 --- /dev/null +++ b/.github/workflows/build-and-push-docker-image.yml @@ -0,0 +1,42 @@ +name: build-and-push-docker-image + +on: + workflow_call: + inputs: + imageName: + required: true + type: string + imageTag: + required: true + type: string + secrets: + DOCKERHUB_USERNAME: + required: true + DOCKERHUB_TOKEN: + required: true + +jobs: + docker: + runs-on: [self-hosted, Linux, X64] + steps: + + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ inputs.imageName }}:${{ inputs.imageTag }} \ No newline at end of file diff --git a/.github/workflows/build-trigger.yml b/.github/workflows/build-trigger.yml deleted file mode 100644 index 44d401d3..00000000 --- a/.github/workflows/build-trigger.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Backend CI/CD - -on: - push: - branches: [ main, master ] - workflow_dispatch: - -jobs: - build-and-test: - name: Build and Test Backend - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up JDK 11 - uses: actions/setup-java@v2 - with: - distribution: 'adopt' - java-version: '11' - - - name: Build with Gradle - run: ./gradlew build - - - name: Run tests - run: ./gradlew test - - - name: Build and push Docker image - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - run: | - echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin - docker build -t your-org/backend:latest . - docker push your-org/backend:latest - - # Trigger infrastructure deployment - - name: Trigger infrastructure deployment - uses: peter-evans/repository-dispatch@v2 - with: - token: ${{ secrets.REPO_ACCESS_TOKEN }} - repository: your-org/infrastructure - event-type: backend-updated - client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}' \ No newline at end of file diff --git a/.github/workflows/latest.yml b/.github/workflows/latest.yml new file mode 100644 index 00000000..7298decc --- /dev/null +++ b/.github/workflows/latest.yml @@ -0,0 +1,16 @@ +name: Release build & push to Docker Hub + +on: + push: + branches: + - main + +jobs: + release-build-push: + uses: ./.github/workflows/build-and-push-docker-image.yml + with: + imageName: drive-api + imageTag: latest + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml new file mode 100644 index 00000000..d9cf34e5 --- /dev/null +++ b/.github/workflows/nightly.yaml @@ -0,0 +1,16 @@ +name: Develop nightly build & push to Docker Hub + +on: + push: + branches: + - develop + +jobs: + nightly-build-push: + uses: ./.github/workflows/build-and-push-docker-image.yml + with: + imageName: drive-api + imageTag: nightly + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..ff7b3d05 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,15 @@ +name: Release build & push to Docker Hub + +on: + release: + types: [published] + +jobs: + release-build-push: + uses: ./.github/workflows/build-and-push-docker-image.yml + with: + imageName: drive-api + imageTag: ${{ github.event.release.tag_name }} + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} \ No newline at end of file diff --git a/infrastructure/src/main/resources/application-dev.yml b/infrastructure/src/main/resources/application-dev.yml new file mode 100644 index 00000000..615c1b85 --- /dev/null +++ b/infrastructure/src/main/resources/application-dev.yml @@ -0,0 +1,21 @@ +server: + port: ${SERVER_PORT} + +keycloak: + realm: callv2 + host: ${KEYCLOAK_HOST} + client: + user-api: + client-id: ${KEYCLOAK_CLIENT_ID} + client-secret: ${KEYCLOAK_CLIENT_SECRET} + +postgres: + host: ${POSTGRES_HOST} + port: ${POSTGRES_PORT} + database: drive + username: ${POSTGRES_USER} + password: ${POSTGRES_PASSWORD} + +storage: + file-system: + location: ${STORAGE_LOCATION} \ No newline at end of file diff --git a/infrastructure/src/main/resources/application-hmg.yml b/infrastructure/src/main/resources/application-hmg.yml deleted file mode 100644 index 902c7b9c..00000000 --- a/infrastructure/src/main/resources/application-hmg.yml +++ /dev/null @@ -1,14 +0,0 @@ -keycloak: - realm: ${KEYCLOAK_REALM} - host: ${KEYCLOAK_HOST} - -postgres: - host: ${POSTGRES_HOST} - port: ${POSTGRES_PORT} - database: ${POSTGRES_DATABASE} - username: ${POSTGRES_USERNAME} - password: ${POSTGRES_PASSWORD} - -storage: - file-system: - location: ${STORAGE_LOCATION} \ No newline at end of file diff --git a/infrastructure/src/main/resources/application-local.yml b/infrastructure/src/main/resources/application-local.yml index a3d66db9..db006c14 100644 --- a/infrastructure/src/main/resources/application-local.yml +++ b/infrastructure/src/main/resources/application-local.yml @@ -1,3 +1,6 @@ +server: + port: 8080 + keycloak: realm: callv2 host: http://localhost:8090 diff --git a/infrastructure/src/main/resources/application.yml b/infrastructure/src/main/resources/application.yml index ef1e152b..eff8f608 100644 --- a/infrastructure/src/main/resources/application.yml +++ b/infrastructure/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8080 + port: 80 servlet: context-path: /api compression: