Skip to content
Snippets Groups Projects
Commit fa43d888 authored by Emmanuel Bruno's avatar Emmanuel Bruno
Browse files

adds docke maven and github CI.

parent 6d2dac6b
No related branches found
No related tags found
No related merge requests found
<!-- A MAVEN SETTINGS FILE TO BE USED IN CI -->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>github</id>
<username>${env.GITHUBLOGIN}</username>
<password>${env.GITHUBPASSWORD}</password>
</server>
<server>
<id>dockerhub</id>
<username>${env.DOCKER_USERNAME}</username>
<password>${env.DOCKER_PASSWORD}</password>
</server>
<server>
<id>github.pages</id>
<username>git</username>
<configuration>
<scmVersionType>branch</scmVersionType>
<scmVersion>gh-pages</scmVersion>
</configuration>
</server>
</servers>
<profiles>
<profile>
<id>sonar</id>
<properties>
<sonar.host.url>http://pc-bruno:9000</sonar.host.url>
<sonar.login>${env.SONAR_TOKEN}</sonar.login>
</properties>
</profile>
</profiles>
</settings>
## A simple example to use Github Actions for Java CI
## This produces a simple jar artefact are store in the github maven repository
# We build the project using maven.
# The credential ae set in a specific settings.xml using env variables
# The ENV variables are stored as Github Secrets
#
# The secrets are set in CLI with https://www.npmjs.com/package/gh-create-update-secret
#
# ghrepo=`git remote -v|grep fetch|sed 's/.*:\(.*\).git/\1/'`
# export GH_PAT=$GITHUB_PASSWORD
# gh-create-update-secret --secret GITHUBLOGIN --value $GITHUB_LOGIN --repo $ghrepo
# gh-create-update-secret --secret GITHUBPASSWORD --value $GITHUB_PASSWORD --repo $ghrepo
# gh-create-update-secret --secret DOCKER_USERNAME --value $DOCKER_USERNAME --repo $ghrepo
# gh-create-update-secret --secret DOCKER_PASSWORD --value $DOCKER_PASSWORD --repo $ghrepo
# gh-create-update-secret --secret SONAR_TOKEN --value $SONAR_TOKEN --repo $ghrepo
name: Java CI
# on every push
on: [push]
env:
GITHUBLOGIN: ${{secrets.GITHUBLOGIN}}
GITHUBPASSWORD: ${{secrets.GITHUBPASSWORD}}
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
jobs:
# This job build, test, package and deploy the artefact
maven-build:
# The tags on the runner
runs-on: [self-hosted, Linux]
steps:
#we get the content of the repository
- uses: actions/checkout@v2
# build the project in a docker container with a specific maven settings.xml
# it uses env variables from github secrets for the credentials
# to github, dockerhub and sonar.
- name: Build and test with Maven in docker
run: ./mvn.sh clean verify
# This job runs a sonarqube analysis on the hosted runner
# only on develop branch
maven-sonar:
runs-on: [self-hosted, Linux]
needs: maven-build
# Develop branch only
# if: github.ref == 'refs/heads/develop'
steps:
- name: Launch a sonar analysis
run: ./mvn.sh -D sonar.branch.name=${GITHUB_REF#refs/heads/} --activate-profiles sonar sonar:sonar && mvn --activate-profiles sonar -pl . sonar-quality-gate:check
name: Delete Old Snpashot Package # on every push
on: [push]
jobs:
cleanup:
# The tags on the runner
runs-on: [self-hosted, Linux]
steps:
- uses: smartsquaregmbh/delete-old-packages@v0.2.0
with:
keep: 1
names: |
fr.univtln.bruno.demos.jaxrs.demojaxrs
fr.univtln.bruno.demos.jaxrs.model
fr.univtln.bruno.demos.jaxrs.server
fr.univtln.bruno.demos.jaxrs.javaclient
mvn.sh 0 → 100755
#!/bin/bash
docker run \
--env GITHUBLOGIN="$GITHUBLOGIN" \
--env GITHUBPASSWORD="$GITHUBPASSWORD" \
--env SONAR_TOKEN="$SONAR_TOKEN" \
--volume ~/.m2:/var/maven/.m2 \
--volume ~/.sonar:/var/maven/.sonar \
--volume ~/.config:/var/maven/.config \
--volume ~/.ssh:/home/user/.ssh \
--volume ~/.gitconfig:/home/user/.gitconfig \
--volume "$(pwd)":/usr/src/mymaven \
--workdir /usr/src/mymaven \
--rm \
--env PUID=$(id -u) -e PGID=$(id -g) \
--env MAVEN_CONFIG=/var/maven/.m2 \
brunoe/maven:3.6.3-jdk-11-openj9 \
runuser --user user --group user -- mvn -B -e -T 1C -Duser.home=/var/maven --settings /usr/src/mymaven/.github/ci-settings.xml "$@"
\ No newline at end of file
......@@ -2,10 +2,10 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.univtln.bruno.exemple.simplerest</groupId>
<artifactId>restbiblio</artifactId>
<artifactId>sample-jaxrs</artifactId>
<packaging>jar</packaging>
<version>2.0-SNAPSHOT</version>
<name>restbiblio</name>
<name>Sample JAX-RS</name>
<dependencyManagement>
<dependencies>
<!-- Jakarta RESTful Web Services (JAXRS) https://jakarta.ee/specifications/restful-ws/3.0/ -->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment