-
Notifications
You must be signed in to change notification settings - Fork 14
/
Jenkinsfile.deploy
100 lines (91 loc) · 2.42 KB
/
Jenkinsfile.deploy
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
// one job per arch (for now) that copies built images to the arch-specific namespaces
properties([
disableConcurrentBuilds(),
disableResume(),
durabilityHint('PERFORMANCE_OPTIMIZED'),
rateLimitBuilds(throttle: [
count: 1,
durationName: 'hour',
userBoost: true,
]),
pipelineTriggers([
upstream('../meta'),
cron('H H/6 * * *'), // run every few hours whether we "need" it or not
]),
])
env.BASHBREW_ARCH = env.JOB_NAME.minus('/deploy').split('/')[-1] // "windows-amd64", "arm64v8", etc
node('put-shared') { ansiColor('xterm') {
stage('Checkout') {
checkout(scmGit(
userRemoteConfigs: [[
url: 'https://github.com/docker-library/meta.git',
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'],
],
))
}
// make sure "docker login" is localized to this workspace
env.DOCKER_CONFIG = workspace + '/.docker'
dir(env.DOCKER_CONFIG) { deleteDir() }
stage('Login') {
withCredentials([
usernamePassword(
credentialsId: 'docker-hub-' + env.BASHBREW_ARCH,
usernameVariable: 'DOCKER_USERNAME',
passwordVariable: 'DOCKER_PASSWORD',
),
]) {
sh '''#!/usr/bin/env bash
set -Eeuo pipefail # no -x
docker login --username "$DOCKER_USERNAME" --password-stdin <<<"$DOCKER_PASSWORD"
'''
}
}
dir('meta') {
stage('Generate') {
sh '''#!/usr/bin/env bash
set -Eeuo pipefail -x
jq -L.scripts '
include "deploy";
arch_tagged_manifests(env.BASHBREW_ARCH)
| deploy_objects[]
' builds.json | tee deploy.json
'''
}
withCredentials([
string(credentialsId: 'dockerhub-public-proxy', variable: 'DOCKERHUB_PUBLIC_PROXY'),
string(credentialsId: 'dockerhub-public-proxy-host', variable: 'DOCKERHUB_PUBLIC_PROXY_HOST'),
]) {
stage('Deploy') {
sh '''#!/usr/bin/env bash
set -Eeuo pipefail -x
(
cd .scripts
# TODO make a helper to build binaries correctly/consistently 🙃
if ./.any-go-nt.sh bin/deploy; then
./.go-env.sh go build -trimpath -o bin/deploy ./cmd/deploy
fi
)
.scripts/bin/deploy < deploy.json
'''
}
}
}
// "docker logout"
dir(env.DOCKER_CONFIG) { deleteDir() }
} }