forked from coreos/fedora-coreos-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-cosa.Jenkinsfile
156 lines (146 loc) · 6.02 KB
/
build-cosa.Jenkinsfile
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
def pipeutils, streams, official
def gitref, commit, shortcommit
node {
checkout scm
pipeutils = load("utils.groovy")
streams = load("streams.groovy")
official = pipeutils.isOfficial()
}
properties([
pipelineTriggers([
githubPush()
]),
parameters([
string(name: 'ARCHES',
description: 'Space-separated list of target architectures',
defaultValue: "x86_64" + " " + streams.additional_arches.join(" "),
trim: true),
string(name: 'COREOS_ASSEMBLER_GIT_URL',
description: 'Override the coreos-assembler git repo to use',
defaultValue: "https://github.com/coreos/coreos-assembler.git",
trim: true),
string(name: 'COREOS_ASSEMBLER_GIT_REF',
description: 'Override the coreos-assembler git ref to use',
defaultValue: "",
trim: true),
string(name: 'CONTAINER_REGISTRY_REPO',
description: 'Override the registry to push the container to',
defaultValue: "quay.io/coreos-assembler/coreos-assembler",
trim: true),
string(name: 'CONTAINER_REGISTRY_STAGING_REPO',
description: 'Override the staging registry where intermediate images go',
defaultValue: "quay.io/coreos-assembler/coreos-assembler-staging",
trim: true),
string(name: 'COREOS_ASSEMBLER_IMAGE',
description: 'Override the coreos-assembler image to use',
defaultValue: "coreos-assembler:main",
trim: true),
]),
buildDiscarder(logRotator(
numToKeepStr: '100',
artifactNumToKeepStr: '100'
)),
durabilityHint('PERFORMANCE_OPTIMIZED')
])
node {
change = checkout(
changelog: true,
poll: false,
scm: [
$class: 'GitSCM',
branches: [[name: 'origin/rhcos*'], [name: 'origin/main']],
userRemoteConfigs: [[url: 'https://github.com/coreos/coreos-assembler.git']],
extensions: [[$class: 'CloneOption',
noTags: true,
reference: '',
shallow: true]]
]
)
// Handle here if we were triggered by a git webhook or triggered
// manually by a human. If trigerred by a webhook we can pick up
// the branch that was pushed to from $change. If not we need to
// pick it up from params.COREOS_ASSEMBLER_GIT_REF specified by
// the user (or "main" if not specified).
gitref = params.COREOS_ASSEMBLER_GIT_REF
if (pipeutils.triggered_by_push()) {
gitref = change.GIT_BRANCH['origin/'.length()..-1]
} else {
if (gitref == "") {
gitref = "main"
}
shwrap("git fetch --depth=1 origin ${gitref} && git checkout FETCH_HEAD")
}
def output = shwrapCapture("git rev-parse HEAD")
commit = output.substring(0,40)
shortcommit = commit.substring(0,7)
}
currentBuild.description = "[${gitref}] Running"
// Get the list of requested architectures to build for
def basearches = params.ARCHES.split() as Set
try {
lock(resource: "build-cosa-${gitref}") {
timeout(time: 60, unit: 'MINUTES') {
cosaPod(image: params.COREOS_ASSEMBLER_IMAGE,
memory: "256Mi", kvm: false) {
currentBuild.description = "[${gitref}@${shortcommit}] Running"
withCredentials([file(credentialsId: 'cosa-push-registry-secret', variable: 'REGISTRY_SECRET')]) {
stage('Build COSA') {
parallel basearches.collectEntries{arch -> [arch, {
pipeutils.withPodmanRemoteArchBuilder(arch: arch) {
shwrap("""
cosa remote-build-container \
--arch $arch --git-ref $commit \
--git-url ${params.COREOS_ASSEMBLER_GIT_URL} \
--repo ${params.CONTAINER_REGISTRY_STAGING_REPO} \
--push-to-registry --auth=\$REGISTRY_SECRET
""")
}
}]}
}
stage('Push Manifest') {
def images = ""
for (architecture in basearches) {
def arch = architecture
images += " --image=docker://${params.CONTAINER_REGISTRY_STAGING_REPO}:${arch}-${shortcommit}"
}
shwrap("""
cosa push-container-manifest \
--auth=\$REGISTRY_SECRET --tag ${gitref} \
--repo ${params.CONTAINER_REGISTRY_REPO} ${images}
""")
// Specifically for the `main` branch let's also update the `latest` tag
// If there was a way to alias/tie these two together in the Quay UI
// that would be preferable.
if (gitref == "main") {
shwrap("""
skopeo copy --all --authfile \$REGISTRY_SECRET \
docker://${params.CONTAINER_REGISTRY_REPO}:main \
docker://${params.CONTAINER_REGISTRY_REPO}:latest
""")
}
}
stage('Delete Intermediate Tags') {
parallel basearches.collectEntries{arch -> [arch, {
shwrap("""
skopeo delete --authfile=\$REGISTRY_SECRET \
docker://${params.CONTAINER_REGISTRY_STAGING_REPO}:${arch}-${shortcommit}
""")
}]}
}
}
currentBuild.result = 'SUCCESS'
}
}}} catch (e) {
currentBuild.result = 'FAILURE'
throw e
} finally {
if (currentBuild.result == 'SUCCESS') {
currentBuild.description = "[${gitref}@${shortcommit}] ⚡"
} else {
currentBuild.description = "[${gitref}@${shortcommit}] ❌"
}
if (official && currentBuild.result != 'SUCCESS') {
message = ":fcos: :trashfire: build-cosa <${env.BUILD_URL}|#${env.BUILD_NUMBER}> [${params.COREOS_ASSEMBLER_GIT_REF}-${shortcommit}]"
slackSend(color: 'danger', message: message)
}
}