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/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/Dockerfile b/Dockerfile index cd3dfb94..87ade5db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,18 @@ -FROM amazoncorretto:21-alpine AS builder +FROM eclipse-temurin:21.0.7_6-jdk-alpine AS builder -WORKDIR /app +WORKDIR /usr/app COPY . . -RUN ./gradlew clean :infrastructure:bootJar --no-daemon +RUN ./gradlew clean bootJar --no-daemon -FROM amazoncorretto:21-alpine +FROM eclipse-temurin:21.0.7_6-jdk-alpine -WORKDIR /app +COPY --from=builder /usr/app/build/libs/application.jar /opt/app/application.jar -RUN mkdir -p /app/storage && chmod -R 777 /app/storage +RUN addgroup -S app && adduser -S app -G app +USER app:app -COPY --from=builder /app/build/libs/application.jar app.jar +EXPOSE 80 -ENV SPRING_PROFILES_ACTIVE=local -ENV KEYCLOAK_REALM=callv2 -ENV KEYCLOAK_HOST=http://localhost:8090 -ENV POSTGRES_HOST=localhost -ENV POSTGRES_PORT=5432 -ENV POSTGRES_DATABASE=callv2 -ENV POSTGRES_USERNAME=callv2 -ENV POSTGRES_PASSWORD=callv2 -ENV STORAGE_LOCATION=/app/storage - -EXPOSE 8080 - -ENTRYPOINT ["sh", "-c", "java -jar /app/app.jar --spring.profiles.active=${SPRING_PROFILES_ACTIVE}"] \ No newline at end of file +CMD ["sh", "-c", "java -jar /opt/app/application.jar"] \ No newline at end of file diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 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: