-
Notifications
You must be signed in to change notification settings - Fork 41
/
Jenkinsfile.containers
161 lines (145 loc) · 7.81 KB
/
Jenkinsfile.containers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
pipeline {
agent {
label 'java11'
}
environment {
MVN_BASE = "/usr/local/maven/bin/mvn --settings ${pwd()}/.ci/settings.xml"
MVN_COMMAND = "${MVN_BASE} --show-version --batch-mode --errors --fail-at-end -DdeployAtEnd=true "
M2_REPO = "${HOME}/.m2"
CI = credentials("app-jenkins")
SERVICE_SONAR_URL = credentials("service-sonar-java11-url")
SERVICE_NEXUS_URL = credentials("service-nexus-url")
SERVICE_REPO_SSHURL = credentials("repository-connection-string")
SERVICE_GIT_URL = credentials("service-gitlab-url")
SERVICE_DOCKER_PULL_URL=credentials("SERVICE_DOCKER_PULL_URL")
SERVICE_DOCKER_PUSH_URL=credentials("SERVICE_DOCKER_PUSH_URL")
SERVICE_REPOSITORY_URL=credentials("service-repository-url")
GITHUB_ACCOUNT_TOKEN = credentials("vitam-prg-token")
ES_VERSION="8.14.3"
MONGO_VERSION="7.0.8"
MINIO_VERSION="RELEASE.2020-04-15T00-39-01Z" // more precise than edge
OPENIO_VERSION="18.10"
JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
}
stages {
stage('Build and create vitam docker images'){
steps {
withCredentials([
[$class: 'UsernamePasswordMultiBinding', credentialsId: 'app-jenkins',usernameVariable: 'CI_USR', passwordVariable: 'CI_PSW'],
string(credentialsId: "service-nexus-url", variable: 'SERVICE_NEXUS_URL') ]) {
sh '''
npm config get cache
npm config get
npm config ls -l
echo $HOME
cat /etc/passwd
whoami
'''
sh '$MVN_COMMAND -f sources/pom.xml install -Djib.skip=false -Dmaven.test.skip=true -DskipTests=true -Djacoco.skip=true -Dlicense.skip -Denv.SERVICE_NEXUS_URL=$SERVICE_NEXUS_URL -DsendCredentialsOverHttp=true -Djib.to.auth.username=$CI_USR -Djib.to.auth.password=$CI_PSW'
withCredentials([
[$class: 'UsernamePasswordMultiBinding', credentialsId: 'app-jenkins',usernameVariable: 'CI_USR', passwordVariable: 'CI_PSW'],
string(credentialsId: "service-nexus-url", variable: 'SERVICE_NEXUS_URL')
]) {
sh 'echo $CI_PSW | docker login ${SERVICE_DOCKER_PULL_URL} -u $CI_USR --password-stdin'
sh 'echo $CI_PSW | docker login ${SERVICE_DOCKER_PUSH_URL} -u $CI_USR --password-stdin'
sh "docker pull ${SERVICE_DOCKER_PUSH_URL}/vitam/metadata"
sh "docker tag ${SERVICE_DOCKER_PUSH_URL}/vitam/metadata ${SERVICE_DOCKER_PUSH_URL}/vitam/metadata-collect"
sh "docker push ${SERVICE_DOCKER_PUSH_URL}/vitam/metadata-collect"
sh "docker pull ${SERVICE_DOCKER_PUSH_URL}/vitam/workspace"
sh "docker tag ${SERVICE_DOCKER_PUSH_URL}/vitam/workspace ${SERVICE_DOCKER_PUSH_URL}/vitam/workspace-collect"
sh "docker push ${SERVICE_DOCKER_PUSH_URL}/vitam/workspace-collect"
}
}
}
}
stage('build cots') {
steps {
withCredentials([
[$class: 'UsernamePasswordMultiBinding', credentialsId: 'app-jenkins',usernameVariable: 'CI_USR', passwordVariable: 'CI_PSW'],
string(credentialsId: "service-nexus-url", variable: 'SERVICE_NEXUS_URL')
]) {
sh 'echo $CI_PSW | docker login ${SERVICE_DOCKER_PULL_URL} -u $CI_USR --password-stdin'
sh 'echo $CI_PSW | docker login ${SERVICE_DOCKER_PUSH_URL} -u $CI_USR --password-stdin'
}
dir("containers/vitam-external") {
script {
def filePath = 'sources.containers'
// Read the file contents
def fileContents = readFile file: filePath
def lines = fileContents.split('\n')
// Iterate over the lines
lines.each { line ->
// Process each line as needed
sh "docker pull ${SERVICE_DOCKER_PULL_URL}/${line}"
sh "docker tag ${SERVICE_DOCKER_PULL_URL}/${line} ${SERVICE_DOCKER_PUSH_URL}/vitam-external/${line}"
sh "docker push ${SERVICE_DOCKER_PUSH_URL}/vitam-external/${line}"
}
}
}
}
}
stage('Set scanner prerequisites') {
steps {
// Install trivy
sh 'sudo curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.47.0'
sh 'sudo curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/html.tpl > html.tpl'
}
}
stage('Scan containers') {
steps {
script {
def dockerImages = [
'$SERVICE_DOCKER_PUSH_URL/vitam/access-external',
'$SERVICE_DOCKER_PUSH_URL/vitam/access-internal',
'$SERVICE_DOCKER_PUSH_URL/vitam/batch-report',
'$SERVICE_DOCKER_PUSH_URL/vitam/collect-external',
'$SERVICE_DOCKER_PUSH_URL/vitam/collect-internal',
'$SERVICE_DOCKER_PUSH_URL/vitam/functional-administration',
'$SERVICE_DOCKER_PUSH_URL/vitam/ihm-demo',
'$SERVICE_DOCKER_PUSH_URL/vitam/ihm-recette',
'$SERVICE_DOCKER_PUSH_URL/vitam/ingest-internal',
'$SERVICE_DOCKER_PUSH_URL/vitam/ingest-external',
'$SERVICE_DOCKER_PUSH_URL/vitam/ingest-security',
'$SERVICE_DOCKER_PUSH_URL/vitam/logbook',
'$SERVICE_DOCKER_PUSH_URL/vitam/metadata',
'$SERVICE_DOCKER_PUSH_URL/vitam/metadata-collect',
'$SERVICE_DOCKER_PUSH_URL/vitam/offer',
'$SERVICE_DOCKER_PUSH_URL/vitam/processing',
'$SERVICE_DOCKER_PUSH_URL/vitam/scheduler',
'$SERVICE_DOCKER_PUSH_URL/vitam/storage-engine',
'$SERVICE_DOCKER_PUSH_URL/vitam/worker',
'$SERVICE_DOCKER_PUSH_URL/vitam/workspace'
// Add more images as needed
]
// Create reports directory
sh 'mkdir -p reports'
// Iterate over the list of images
dockerImages.each { image ->
def imageName = image.tokenize('/').last()
// Pull the Docker image
sh "docker pull $image"
// Run Trivy scan
sh "trivy image $image --ignore-unfixed --vuln-type os,library --format template --template '@html.tpl' -o reports/${imageName}-scan.html || true"
// Publish HTML report
publishHTML target: [
allowMissing: true,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'reports',
reportFiles: "${imageName}-scan.html",
reportName: "Trivy Scan ${imageName}",
reportTitles: "Trivy Scan ${imageName}"
]
}
}
}
}
}
post {
// Clean after build
always {
sh 'docker system prune -a -f'
cleanWs()
}
}
}