-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathJenkinsfile.meta
135 lines (127 loc) · 4.26 KB
/
Jenkinsfile.meta
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
properties([
disableConcurrentBuilds(),
disableResume(),
durabilityHint('PERFORMANCE_OPTIMIZED'),
pipelineTriggers([
githubPush(),
cron('@hourly'), // check periodically to bring in new image builds
]),
])
node {
stage('Checkout') {
// prevent meta from triggering itself
// If 'Include in polling' is enabled or 'Include in changelog' is enabled, then when polling occurs, the job will be started if changes are detected from this SCM source.
checkout(changelog: false, poll: false, scm: scmGit(
userRemoteConfigs: [[
url: '[email protected]:docker-library/meta.git',
credentialsId: 'docker-library-bot',
name: 'origin',
]],
branches: [[name: '*/main']],
extensions: [
cloneOption(
noTags: true,
shallow: true,
depth: 1,
),
submodule(
parentCredentials: true,
recursiveSubmodules: true,
trackingSubmodules: true,
),
cleanBeforeCheckout(),
cleanAfterCheckout(),
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'meta'],
],
))
checkout(scmGit(
userRemoteConfigs: [[
url: 'https://github.com/docker-library/official-images.git',
name: 'origin',
]],
branches: [[name: '*/master']],
extensions: [
cleanBeforeCheckout(),
cleanAfterCheckout(),
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'meta/.doi'],
],
))
checkout(scmGit(
userRemoteConfigs: [[
url: 'https://github.com/docker-library/meta-scripts.git',
name: 'origin',
]],
branches: [[name: '*/main']],
extensions: [
cleanBeforeCheckout(),
cleanAfterCheckout(),
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'meta/.scripts'],
],
))
sh '''
git -C meta config user.name 'Docker Library Bot'
git -C meta config user.email '[email protected]'
'''
}
env.BASHBREW_LIBRARY = workspace + '/meta/.doi/library'
dir('meta') {
withCredentials([
// thanks to rate limits, we either have to "docker login" or look things up via our proxy
string(credentialsId: 'dockerhub-public-proxy', variable: 'DOCKERHUB_PUBLIC_PROXY'),
]) {
stage('Fetch') {
sh 'bashbrew --library .doi/library fetch --all'
}
stage('Sources') {
sh '''
# we only need to regenerate "sources.json" if ".doi" or ".scripts" have changed since we last generated it
needsBuild=
if [ ! -s commits.json ] || [ ! -s sources.json ]; then
needsBuild=1
fi
doi="$(git -C .doi log -1 --format='format:%H')"
scripts="$(git -C .scripts log -1 --format='format:%H')"
export doi scripts
jq -n '{ doi: env.doi, scripts: env.scripts }' | tee commits.json
if [ -z "$needsBuild" ] && ! git diff --exit-code commits.json; then
needsBuild=1
fi
if [ -n "$needsBuild" ]; then
# use previous run as cache
[ -s sources.json ] && cp sources.json sources-copy.json
.scripts/sources.sh --cache-file sources-copy.json --all > sources.json
# clean up temporary cache
rm -f sources-copy.json
fi
'''
}
stage('Builds') {
sh '.scripts/builds.sh --cache cache-builds.json sources.json > builds.json'
}
}
stage('Janky') {
// ideally, the other jobs that act on the data generated by this one would directly reference each Jenkinsfile.* from *within* the ".scripts" submodule that this job has updated (so that we only run updated scripts with updated data, in the case of something major changing for example)
// Jenkins *does* technically support this, but it requires disabling "lightweight checkout", and doing the full checkout of "meta" (even just making sure it's up-to-date) *just* to grab a single Jenkinsfile from the .scripts submodule is really heavy and kicks over our Jenkins server
// to mitigate this, we "copy up" the Jenkinsfiles directly into "meta" so that we can go back to a "lightweight" checkout
sh '''
rm -rf .jenkins
mkdir .jenkins
echo 'Jenkinsfile* linguist-language=groovy' > .jenkins/.gitattributes
cp -av .scripts/Jenkinsfile* .jenkins/
'''
}
stage('Commit') {
sh '''
git add -A .
if ! git diff --staged --exit-code; then # commit fails if there's nothing to commit
git commit -m 'Update and regenerate'
fi
'''
}
sshagent(['docker-library-bot']) {
stage('Push') {
sh 'git push origin HEAD:main'
}
}
}
}