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
  • Loading branch information
davdarras committed Feb 22, 2023
1 parent 788e637 commit 4ea0a9c
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 5 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 }}
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"]
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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</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 @@ -190,6 +193,10 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
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 4ea0a9c

Please sign in to comment.