From 74704c86e72f1cf1476f9f5b355ad0fdfe39fd6e Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Wed, 28 Feb 2024 22:53:36 +0100 Subject: [PATCH] docker_publish workflow --- .dockerignore | 3 +- .github/workflows/docker_publish.yml | 67 +++++++++++++++++++ CHANGELOG.md | 3 +- Dockerfile | 34 ++++++++++ .../java/fjdaogenquickstart/AppInfo.java | 20 ++++++ src/main/resources/application.yml | 4 ++ 6 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docker_publish.yml create mode 100644 Dockerfile create mode 100644 src/main/java/org/fugerit/java/fjdaogenquickstart/AppInfo.java diff --git a/.dockerignore b/.dockerignore index 94810d0..4d41e88 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,5 @@ !target/*-runner !target/*-runner.jar !target/lib/* -!target/quarkus-app/* \ No newline at end of file +!target/quarkus-app/* +!src/test/resources/h2init/* diff --git a/.github/workflows/docker_publish.yml b/.github/workflows/docker_publish.yml new file mode 100644 index 0000000..507d70e --- /dev/null +++ b/.github/workflows/docker_publish.yml @@ -0,0 +1,67 @@ +# CI with maven build and scan + +name: CI docker build + +on: + # Trigger analysis when pushing in master or pull requests, and when creating + # a pull request. + push: + branches: + - develop + release: + types: [published] + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + # Shallow clones should be disabled for a better relevancy of analysis + fetch-depth: 0 + - name: Echo ref name trigger + run: echo ${{ github.ref_name }} + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'corretto' + cache: 'maven' + - name: Cache Maven packages + uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Cache SonarCloud packages + uses: actions/cache@v1 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Maven version + run: mvn -v + env: + # Needed to get some information about the pull request, if any + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # SonarCloud access token should be generated from https://sonarcloud.io/account/security/ + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + - name: Build and analyze + run: mvn -B clean package + # using action https://github.com/marketplace/actions/build-and-push-docker-images + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: fugeritorg/fj-daogen-quickstart:${{ github.ref_name }},fugeritorg/fj-daogen-quickstart:latest \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d697a78..56083f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Added - sample demo app for fj-daogen version 1.5.1 -- project based on quarkus 3.8.1 \ No newline at end of file +- project based on quarkus 3.8.1 +- docker_publish workflow \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..012a7e3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# fj-daogen-quarkus-demo image build 1.0.0 +# +# Public built image form amd64/arm64 linux can be found on repository : +# https://hub.docker.com/repository/docker/fugeritorg/fj-daogen-quarkus-demo/general +# +# create : docker run -it -p 8080:8080 --name fj-daogen-quarkus-demo fugeritorg/fj-daogen-quarkus-demo:latest +# start : docker start fj-daogen-quarkus-demo +# stop : docker stop fj-daogen-quarkus-demo +# +# Image tag : +# docker image tag [image tag] fugeritorg/fj-daogen-quarkus-demo:latest +# +# Change with any base openjdk image is preferred +FROM amazoncorretto:21.0.2-alpine3.19 + +LABEL org.opencontainers.image.authors="Fugerit" \ + org.opencontainers.image.source="Quarkus" \ + org.opencontainers.image.revision="1.0.0" + +COPY --chown=185:0 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185:0 target/quarkus-app/*.jar /deployments/ +COPY --chown=185:0 target/quarkus-app/app/ /deployments/app/ +COPY --chown=185:0 target/quarkus-app/quarkus/ /deployments/quarkus/ +RUN mkdir -p src/test/resources/h2init/ +COPY --chown=185:0 src/test/resources/h2init/* /deployments/src/test/resources/h2init/ + +RUN echo "securerandom.source=file:/dev/./urandom" >> /usr/lib/jvm/default-jvm/jre/lib/security/java.security + +CMD java -Dfile.encoding="UTF-8" -jar /deployments/quarkus-run.jar + +WORKDIR /deployments/ + +ENTRYPOINT ["java","-jar","/deployments/quarkus-run.jar"] + diff --git a/src/main/java/org/fugerit/java/fjdaogenquickstart/AppInfo.java b/src/main/java/org/fugerit/java/fjdaogenquickstart/AppInfo.java new file mode 100644 index 0000000..a12def2 --- /dev/null +++ b/src/main/java/org/fugerit/java/fjdaogenquickstart/AppInfo.java @@ -0,0 +1,20 @@ +package org.fugerit.java.fjdaogenquickstart; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +import java.util.Properties; + +@Path("/info") +public class AppInfo { + + @GET + @Path("/props") + @Produces(MediaType.APPLICATION_JSON) + public Properties props() { + return System.getProperties(); + } + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0cfd787..31a2893 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -9,3 +9,7 @@ quarkus: driver: org.h2.Driver url: jdbc:h2:mem:default;DB_CLOSE_DELAY=-1;MODE=PostgreSQL;INIT=RUNSCRIPT FROM './src/test/resources/h2init/init.sql'; +"%prod": + datasource: + jdbc: + url: jdbc:h2:mem:default;DB_CLOSE_DELAY=-1;MODE=PostgreSQL;INIT=RUNSCRIPT FROM '/deployments/h2init/init.sql';