Skip to content

Commit

Permalink
ci: [#28] First integration workflow
Browse files Browse the repository at this point in the history
- Build and dockerise application
- add actuator with liveness/readiness
- add sonar
  • Loading branch information
davdarras committed Feb 22, 2023
1 parent bd342b6 commit 516ce2b
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 26 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -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 }}
32 changes: 32 additions & 0 deletions .github/workflows/sonar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Public enemy

on: [push]
jobs:
sonarcloud:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Build and analyze
run: mvn clean verify sonar:sonar --no-transfer-progress
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Empty file added .releaserc
Empty file.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
71 changes: 46 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fr.insee</groupId>
<artifactId>public-enemy-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0-beta.1</version>
<packaging>jar</packaging>

<name>public-enemy-api</name>
Expand All @@ -21,6 +21,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<start-class>fr.insee.publicenemy.api.PublicEnemyApplication</start-class>
<sonar.organization>inseefr</sonar.organization>
<sonar.projectKey>InseeFr_Public-Enemy-Back-Office</sonar.projectKey>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.java.binaries>target</sonar.java.binaries>
</properties>

<dependencies>
Expand Down Expand Up @@ -67,14 +71,13 @@
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- JPA -->
Expand Down Expand Up @@ -132,6 +135,39 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -169,26 +205,11 @@
<referenceDefaultSchemaName>public</referenceDefaultSchemaName>
<verbose>true</verbose>
<logging>debug</logging>
</configuration>
</plugin>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Expand Down
23 changes: 22 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ server:
# LOGGING
logging:
file:
path: /home/xxx/logs
path: /var/log
name: publicenemy/publicenemy.log
maxHistory: 365
level:
Expand Down Expand Up @@ -88,3 +88,24 @@ application:
-
name: Loi_informatique
value: https://www.legifrance.gouv.fr/affichTexte.do?cidTexte=JORFTEXT000000886460

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

0 comments on commit 516ce2b

Please sign in to comment.