From 1b27c23dc86dfa6650fae6254ee492faebc7cdf4 Mon Sep 17 00:00:00 2001 From: David Darras Date: Wed, 4 Jan 2023 14:59:46 +0100 Subject: [PATCH] ci: [#28] First integration workflow - Build and dockerise application - add actuator with liveness/readiness --- .github/workflows/build-docker.yml | 57 ++++++++++++++++ Dockerfile | 4 ++ pom.xml | 13 ++-- .../api/configuration/AppConfig.java | 4 +- src/main/resources/application.yaml | 67 ++++++++++++------- .../db/changelog/db.changelog-master.xml | 62 ++++++++++++++++- src/main/resources/db/master.xml | 64 ------------------ 7 files changed, 176 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/build-docker.yml create mode 100644 Dockerfile delete mode 100644 src/main/resources/db/master.xml diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 0000000..4248244 --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,57 @@ +name: V2 Build Docker + +on: push + +env: + PE_BRANCH: feature/ci + +jobs: + build: + runs-on: ubuntu-latest + outputs: + release-version: ${{ steps.version-step.outputs.pe-version }} + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: "temurin" + java-version: "17" + + - name: Get current version + id: version-step + run: echo "::set-output name=pe-version::$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)" + + - name: Print PE Version + run: echo ${{ steps.version-step.outputs.pe-version }} + + - name: Build PE + run: mvn package --no-transfer-progress + + - name: Upload PE jar + uses: actions/upload-artifact@v3 + with: + name: pe-jar + path: target/*.jar + + docker: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Download PE jar + uses: actions/download-artifact@v3 + with: + name: pe-jar + path: target/ + + - name: Publish to Docker Hub + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: inseefr/public-enemy-back-office + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + default_branch: feature/ci + tags: ${{ needs.build.outputs.release-version }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bafcc9a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM eclipse-temurin:17-jre-alpine +WORKDIR /opt/pe/ +COPY ./target/*.jar /opt/pe/pe.jar +ENTRYPOINT ["java", "-jar", "/opt/pe/pe.jar"] \ No newline at end of file diff --git a/pom.xml b/pom.xml index 65f3d95..e9155e9 100644 --- a/pom.xml +++ b/pom.xml @@ -35,14 +35,13 @@ - org.apache.tomcat.embed - tomcat-embed-jasper - provided + org.springframework.boot + spring-boot-starter-validation org.springframework.boot - spring-boot-starter-validation + spring-boot-starter-actuator @@ -101,7 +100,7 @@ src/main/resources/db/master.xml src/main/resources/db/changelog/db.changelog-master.xml org.postgresql.Driver - jdbc:postgresql://localhost:53941/public-enemy + jdbc:postgresql://localhost:53941/public-enemy-db public test,dev,prod stromae @@ -112,6 +111,10 @@ debug + + org.springframework.boot + spring-boot-maven-plugin + \ No newline at end of file diff --git a/src/main/java/fr/insee/publicenemy/api/configuration/AppConfig.java b/src/main/java/fr/insee/publicenemy/api/configuration/AppConfig.java index 85a109f..6e07db3 100644 --- a/src/main/java/fr/insee/publicenemy/api/configuration/AppConfig.java +++ b/src/main/java/fr/insee/publicenemy/api/configuration/AppConfig.java @@ -35,8 +35,8 @@ public class AppConfig implements WebMvcConfigurer { */ @Bean @ConditionalOnProperty(name="application.proxy.enable", havingValue="true") - public WebClient webClientProxy(@Value("${application.proxy.url}") String proxyUrl, - @Value("${application.proxy.port}") Integer proxyPort, + public WebClient webClientProxy(@Value("${application.proxy.url}") String proxyUrl, + @Value("${application.proxy.port}") Integer proxyPort, WebClient.Builder builder) { HttpClient httpClient = HttpClient.newBuilder() .proxy(ProxySelector.of(new InetSocketAddress(proxyUrl, proxyPort))) diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 18e09d3..fba6bd5 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -1,15 +1,19 @@ -# Configuration des urls -server: - error: - include-binding-errors: always - include-exception: true - include-message: always - include-stacktrace: always +application: + proxy: + enable: false + url: + port: + cors: + allowed-origins: + pogues: + url: https://pogues-url.insee.fr + eno: + url: https://eno-url.insee.fr # LOGGING logging: file: - path: /home/xxx/logs + path: /var/log name: publicenemy/publicenemy.log maxHistory: 365 level: @@ -30,10 +34,18 @@ logging: spring: # DB datasource: - url: jdbc:postgresql://localhost:53941/public-enemy - username: stromae - password: stromaePassword - hikari.maximumPoolSize: 5 + url: jdbc:postgresql://localhost:5432/public-enemy + username: public-enemy + password: public-enemy-password + hikari: + maximumPoolSize: 5 + connection-timeout: 20000 + jpa: + open-in-view: false + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQLDialect + # LIQUIBASE liquibase: enabled: true @@ -45,8 +57,6 @@ spring: multipart: max-file-size: -1 max-request-size: -1 - jpa: - open-in-view: false codec: max-in-memory-size: 5000KB # to make springfox work @@ -57,12 +67,23 @@ springfox: documentation: enabled: true -application: - proxy: - enable: false - url: - port: - cors: - allowed-origins: - pogues: - url: https://pogues-url.insee.fr +management: + server: + port: 9090 + endpoints: + web: + exposure: + include: info,health + endpoint: + health: + show-details: always + probes: + enabled: true + group: + readiness: + include: db, diskSpace + health: + livenessState: + enabled: true + readinessState: + enabled: true \ No newline at end of file diff --git a/src/main/resources/db/changelog/db.changelog-master.xml b/src/main/resources/db/changelog/db.changelog-master.xml index e285ff4..9d04e50 100644 --- a/src/main/resources/db/changelog/db.changelog-master.xml +++ b/src/main/resources/db/changelog/db.changelog-master.xml @@ -1,4 +1,64 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/master.xml b/src/main/resources/db/master.xml deleted file mode 100644 index b54c6ca..0000000 --- a/src/main/resources/db/master.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -