forked from openshift/os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.treecompose
79 lines (69 loc) · 3.38 KB
/
Jenkinsfile.treecompose
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
def DOCKER_IMG = "quay.io/cgwalters/coreos-assembler"
def DOCKER_ARGS = "--net=host -v /srv:/srv --privileged"
// this var conveniently refers to a location on the server as well as the local dir we sync to/from
def repo = "${env.ARTIFACT_SERVER_DIR}/repo"
def manifest = "host.yaml"
def ref = "openshift/3.10/x86_64/os";
node(env.NODE) {
checkout scm
// We will likely be iterating on this image a lot, so do the equvialent of Kubernetes
// `imagePullPolicy: Always`.
docker.image(DOCKER_IMG).pull()
docker.image(DOCKER_IMG).inside(DOCKER_ARGS) {
stage("Sync In") {
withCredentials([sshUserPrivateKey(credentialsId: env['ARTIFACT_SSH_CREDS_ID'],
keyFileVariable: 'KEY_FILE')]) {
sh """
# a few idempotent commands for bootstrapping
mkdir -p ${repo}
ostree init --repo=${repo} --mode=archive
/usr/app/ostree-releng-scripts/rsync-repos \
--src ${env.ARTIFACT_SERVER}:${repo}/ --dest=${repo} \
--rsync-opt=--stats --rsync-opt=-e \
--rsync-opt='ssh -i ${env.KEY_FILE} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
"""
}
}
stage("Provision") {
sh "cp RPM-GPG-* /etc/pki/rpm-gpg/"
sh "make repo-refresh"
}
def last_build_version, force_nocache
stage("Check for Changes") {
sh "rm -f $WORKSPACE/build.stamp"
sh "coreos-assembler --dry-run --repo=${repo} --touch-if-changed=$WORKSPACE/build.stamp ${manifest}"
// XXX: need to factor this out in a common lib
last_build_version = sh(returnStdout: true,
script: "ostree show --repo=${repo} --print-metadata-key=version ${ref}").trim()
last_build_version = last_build_version[1..-2] // trim single quotes
if (fileExists('force-nocache-build')) {
force_nocache = readFile('force-nocache-build').trim();
}
}
if (!fileExists('build.stamp') && last_build_version != force_nocache) {
currentBuild.result = 'SUCCESS'
currentBuild.description = '(No changes)'
return
}
stage("Compose Tree") {
sh "coreos-assembler --repo=${repo} ${manifest}"
sh "ostree --repo=${repo} rev-parse ${ref} > commit.txt"
def commit = readFile('commit.txt').trim();
currentBuild.description = '🆕 commit ' + commit;
sh "rpm-ostree --repo=${repo} db diff ${commit}^ ${commit}"
}
stage("Sync Out") {
withCredentials([sshUserPrivateKey(credentialsId: env['ARTIFACT_SSH_CREDS_ID'],
keyFileVariable: 'KEY_FILE')]) {
sh """
ostree prune --repo=${repo} --keep-younger-than='30 days ago' --refs-only
ostree summary --repo=${repo} --update
/usr/app/ostree-releng-scripts/rsync-repos \
--dest ${env.ARTIFACT_SERVER}:${repo}/ --src=${repo} \
--rsync-opt=--stats --rsync-opt=-e \
--rsync-opt='ssh -i ${env.KEY_FILE} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
"""
}
}
}
}