Skip to content

Commit

Permalink
Story #14186: use k8s for vitmui build
Browse files Browse the repository at this point in the history
  • Loading branch information
achoubiemohamed committed Feb 4, 2025
1 parent c58fa83 commit f86a241
Showing 1 changed file with 71 additions and 29 deletions.
100 changes: 71 additions & 29 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
def IMPORTANT_BRANCH_OR_TAG = (env.BRANCH_NAME =~ /(develop|master_.*)/).matches() || env.TAG_NAME != null

pipeline {
agent {
label 'java11'
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
metadata:
labels:
some-label: buildpod
spec:
containers:
- name: maven
image: maven:3.9.8-amazoncorretto-17-debian-bookworm
env:
- name: TZ
value: Europe/Paris
resources:
requests:
memory: "1Gi"
limits:
memory: "2Gi"
command:
- cat
tty: true
- name: npm
image: node:18.20.3
resources:
requests:
memory: "1Gi"
limits:
memory: "2Gi"
command:
- cat
tty: true
'''
}
}

environment {
M2_REPO = "${HOME}/.m2"
CI = credentials("app-jenkins")

SERVICE_GIT_URL = credentials("service-gitlab-url")
SERVICE_NEXUS_URL = credentials("service-nexus-url")
SERVICE_NEXUS_URL = "http://172.16.0.43"
SERVICE_REPO_SSHURL = credentials("repository-connection-string")
SERVICE_REPOSITORY_URL = credentials("service-repository-url")
SERVICE_REPOSITORY_URL = "https://repository.dev.programmevitam.fr"
}

options {
Expand All @@ -37,6 +70,7 @@ pipeline {
agent none
when { expression { env.DO_CHECKS_AND_TESTS == null } }
steps {
container('maven') {
script {
INPUT_PARAMS = input message: 'Configure your build',
parameters: [
Expand All @@ -48,10 +82,13 @@ pipeline {
env.DO_CHECKS_AND_TESTS = INPUT_PARAMS.DO_CHECKS_AND_TESTS
}
}
}

}

stage('Show Configuration') {
steps {
container('maven') {
script {
if (env.GOAL == 'build') {
// If the goal is only to build, we only run "mvn verify" (includes running tests, except if explicitely skipped)
Expand All @@ -61,7 +98,7 @@ pipeline {
env.MVN_GOAL = 'deploy'
}

env.MVN_COMMAND = "/usr/local/maven/bin/mvn --settings ${pwd()}/.ci/settings.xml --show-version --batch-mode --errors -DdeployAtEnd=true"
env.MVN_COMMAND = "mvn --settings ${pwd()}/.ci/settings.xml --show-version --batch-mode --errors -DdeployAtEnd=true"
if (env.DO_CHECKS_AND_TESTS == 'false') {
// If checks and tests are disabled:
// - "-T1C" builds modules in parallel
Expand All @@ -81,13 +118,29 @@ pipeline {
echo "MVN_COMMAND = ${env.MVN_COMMAND}"
echo "POM_VERSION = ${env.POM_VERSION}"
}
}
}

stage('Upgrade build context') {
steps {
sh 'sudo apt install -y build-essential make ruby ruby-dev rubygems jq'
sh 'sudo timedatectl set-timezone Europe/Paris'
sh 'sudo gem install fpm'
container('maven') {
sh 'date'
sh 'apt update || true'
sh 'echo "deb http://deb.debian.org/debian bookworm main contrib non-free" >> /etc/apt/sources.list'
sh 'echo "deb http://deb.debian.org/debian bookworm-updates main contrib non-free" >> /etc/apt/sources.list'
sh 'apt install -y rpm'
sh 'apt install -y build-essential make ruby ruby-dev rubygems jq nodejs'
sh 'apt install -y npm'
sh 'gem install fpm'
sh 'npm -v'
sh 'export DOCKER_HOST=tcp://kubedock-service.tools:2475'
sh 'export TESTCONTAINERS_RYUK_DISABLED=true'
sh 'export TESTCONTAINERS_CHECKS_DISABLE=true'
sh 'id'
sh 'env'
sh 'sleep 600'

}
}
}

Expand All @@ -98,14 +151,17 @@ pipeline {
environment(name: 'DO_CHECKS_AND_TESTS', value: 'true')
}
steps {
container('maven') {
sh './tools/check_icomoon.sh'
}
}

}
stage('Frontend') {
steps {
container('npm') {
dir('ui/ui-frontend') {
script {
nvm('v18.20.3') {
sh 'npm ci'
if (env.DO_CHECKS_AND_TESTS == 'true') {
sh 'npm run lint'
Expand All @@ -115,24 +171,22 @@ pipeline {
if (env.DO_CHECKS_AND_TESTS == 'true') {
sh 'npm run ci:test'
}
}

if (env.GOAL == 'publish') {
// If the goal is to publish, we also generate .deb/.rpm
sh '../../tools/packaging/package-fronts.sh ui-identity,ui-archive-search,ui-portal,ui-pastis,ui-collect,ui-referential,ui-ingest,ui-design-system ${POM_VERSION}'
}
}
}
}
}
}
stage('Backend') {
tools {
jdk 'java17' // java11 || java17 || java21
maven 'maven-3.9' // maven-3.8 || maven-3.9
}
steps {
container('maven') {
// TODO: generate .deb/.rpm by running Makefile directly in the Jenkinsfile instead of being run by a maven plugin
nvm('v18.20.3') { // We need node for spotless (when env.DO_CHECKS_AND_TESTS == 'true')
sh '${MVN_COMMAND} clean ${MVN_GOAL} -U -Pvitam,deb,rpm'

}
}
}
Expand All @@ -158,13 +212,15 @@ pipeline {
}
}
steps {
container('maven') {
dir('ui/ui-frontend') {
nvm('v18.20.3') {
sh 'npm run build:pastis-standalone'
}
}
sh '${MVN_COMMAND} deploy -Pstandalone --projects "api/api-pastis/pastis-standalone" -Dspotless.check.skip=true -Dmaven.test.skip -Dlicense.skip=true'
}
}
}

stage("Publish") {
Expand Down Expand Up @@ -204,18 +260,4 @@ pipeline {
}
}
}

post {
// Clean after build
always {
// Cleanup any remaining docker volumes
sh 'docker volume prune -f'

// Cleanup M2 repo
sh 'rm -fr ${M2_REPO}/repository/fr/gouv/vitamui/'

// Cleanup workspace
cleanWs()
}
}
}

0 comments on commit f86a241

Please sign in to comment.