Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
docker/publish.sh at master · matf/docker · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
matf
docker
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
docker
/
publish.sh
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
executable file
·
219 lines (188 loc) · 5.81 KB
master
Breadcrumbs
docker
/
publish.sh
Copy path
Top
File metadata and controls
Code
Blame
executable file
·
219 lines (188 loc) · 5.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!
/bin/bash -eu
#
Publish any versions of the docker image not yet pushed to jenkins/jenkins
#
Arguments:
#
-n dry run, do not build or publish images
#
-d debug
set
-o pipefail
sort-versions
() {
if
[
"
$(
uname
)
"
==
'
Darwin
'
]
;
then
gsort --version-sort
else
sort --version-sort
fi
}
#
Try tagging with and without -f to support all versions of docker
docker-tag
() {
local
from=
"
jenkins/jenkins:
$1
"
local
to=
"
$2
/jenkins:
$3
"
local
out
docker pull
"
$from
"
if
out=
$(
docker tag -f
"
$from
"
"
$to
"
2>&1
)
;
then
echo
"
$out
"
else
docker tag
"
$from
"
"
$to
"
fi
}
login-token
() {
#
could use jq .token
curl -q -sSL
"
https://auth.docker.io/token?service=registry.docker.io&scope=repository:jenkins/jenkins:pull
"
|
grep -o
'
"token":"[^"]*"
'
|
cut -d
'
:
'
-f 2
|
xargs
echo
}
is-published
() {
local
tag=
$1
local
opts=
"
"
if
[
"
$debug
"
=
true
]
;
then
opts=
"
-v
"
fi
local
http_code
;
http_code=
$(
curl
$opts
-q -fsSL -o /dev/null -w
"
%{http_code}
"
-H
"
Accept: application/vnd.docker.distribution.manifest.v2+json
"
-H
"
Authorization: Bearer
$TOKEN
"
"
https://index.docker.io/v2/jenkins/jenkins/manifests/
$tag
"
)
if
[
"
$http_code
"
-eq
"
404
"
]
;
then
false
elif
[
"
$http_code
"
-eq
"
200
"
]
;
then
true
else
echo
"
Received unexpected http code from Docker hub:
$http_code
"
fi
}
get-manifest
() {
local
tag=
$1
local
opts=
"
"
if
[
"
$debug
"
=
true
]
;
then
opts=
"
-v
"
fi
curl
$opts
-q -fsSL -H
"
Accept: application/vnd.docker.distribution.manifest.v2+json
"
-H
"
Authorization: Bearer
$TOKEN
"
"
https://index.docker.io/v2/jenkins/jenkins/manifests/
$tag
"
}
get-digest
() {
local
manifest
manifest=
$(
get-manifest
"
$1
"
)
#
get-manifest "$1" | jq .config.digest
if
[
"
$debug
"
=
true
]
;
then
>&2
echo
"
DEBUG: Manifest for
$1
:
$manifest
"
fi
echo
"
$manifest
"
|
grep -A 10 -o
'
"config".*
'
|
grep digest
|
head -1
|
cut -d
'
:
'
-f 2,3
|
xargs
echo
}
get-latest-versions
() {
curl -q -fsSL https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/maven-metadata.xml
|
grep
'
<version>.*</version>
'
|
grep -E -o
'
[0-9]+(\.[0-9]+)+
'
|
sort-versions
|
uniq
|
tail -n 20
}
publish
() {
local
version=
$1
local
variant=
$2
local
tag=
"
${version}${variant}
"
local
sha
local
build_opts=(--no-cache --pull)
if
[
"
$dry_run
"
=
true
]
;
then
build_opts=()
fi
local
dir=war
#
lts is in a different dir
if
[[
"
$version
"
=~
^[0-9]+
\.
[0-9]+
\.
[0-9]+$ ]]
;
then
dir=war-stable
fi
sha=
$(
curl -q -fsSL
"
http://mirrors.jenkins.io/
${dir}
/
${version}
/jenkins.war.sha256
"
|
cut -d
'
'
-f 1
)
docker build --file
"
Dockerfile
$variant
"
\
--build-arg
"
JENKINS_VERSION=
$version
"
\
--build-arg
"
JENKINS_SHA=
$sha
"
\
--tag
"
jenkins/jenkins:
${tag}
"
\
--tag
"
jenkinsci/jenkins:
${tag}
"
\
"
${build_opts[@]+
"
${build_opts[@]}
"
}
"
.
#
" line to fix syntax highlightning
if
[
!
"
$dry_run
"
=
true
]
;
then
docker push
"
jenkins/jenkins:
${tag}
"
docker push
"
jenkinsci/jenkins:
${tag}
"
fi
}
tag-and-push
() {
local
source=
$1
local
target=
$2
local
digest_source
local
digest_target
if
[
"
$debug
"
=
true
]
;
then
>&2
echo
"
DEBUG: Getting digest for
${source}
"
fi
#
if tag doesn't exist yet, ie. dry run
if
!
digest_source=
$(
get-digest
"
${source}
"
)
;
then
echo
"
Unable to get digest for
${source}
${digest_source}
"
digest_source=
"
"
fi
if
[
"
$debug
"
=
true
]
;
then
>&2
echo
"
DEBUG: Getting digest for
${target}
"
fi
if
!
digest_target=
$(
get-digest
"
${target}
"
)
;
then
echo
"
Unable to get digest for
${target}
${digest_target}
"
digest_target=
"
"
fi
if
[
"
$digest_source
"
==
"
$digest_target
"
]
&&
[
-n
"
${digest_target}
"
]
;
then
echo
"
Images
${source}
[
$digest_source
] and
${target}
[
$digest_target
] are already the same, not updating tags
"
else
echo
"
Creating tag
${target}
pointing to
${source}
"
docker-tag
"
${source}
"
"
jenkins
"
"
${target}
"
docker-tag
"
${source}
"
"
jenkinsci
"
"
${target}
"
if
[
!
"
$dry_run
"
=
true
]
;
then
echo
"
Pushing jenkins/jenkins:
${target}
"
docker push
"
jenkins/jenkins:
${target}
"
docker push
"
jenkinsci/jenkins:
${target}
"
else
echo
"
Would push jenkins/jenkins:
${target}
"
fi
fi
}
publish-latest
() {
local
version=
$1
local
variant=
$2
#
push latest (for master) or the name of the branch (for other branches)
if
[
-z
"
${variant}
"
]
;
then
tag-and-push
"
${version}${variant}
"
"
latest
"
else
tag-and-push
"
${version}${variant}
"
"
${variant
#
-}
"
fi
}
publish-lts
() {
local
version=
$1
local
variant=
$2
tag-and-push
"
${version}${variant}
"
"
lts
${variant}
"
}
#
Process arguments
dry_run=false
debug=false
variant=
"
"
while
[[
$#
-gt
0 ]]
;
do
key=
"
$1
"
case
$key
in
-n)
dry_run=true
;;
-d)
debug=true
;;
-v|--variant)
variant=
"
-
"
$2
shift
;;
*
)
echo
"
Unknown option:
$key
"
return
1
;;
esac
shift
done
if
[
"
$dry_run
"
=
true
]
;
then
echo
"
Dry run, will not publish images
"
fi
TOKEN=
$(
login-token
)
lts_version=
"
"
version=
"
"
for
version
in
$(
get-latest-versions
)
;
do
if
is-published
"
$version$variant
"
;
then
echo
"
Tag is already published:
$version$variant
"
else
echo
"
Publishing version:
$version$variant
"
publish
"
$version
"
"
$variant
"
fi
#
Update lts tag
if
[[
"
$version
"
=~
^[0-9]+
\.
[0-9]+
\.
[0-9]+$ ]]
;
then
lts_version=
"
${version}
"
fi
done
publish-latest
"
${version}
"
"
${variant}
"
if
[
-n
"
${lts_version}
"
]
;
then
publish-lts
"
${lts_version}
"
"
${variant}
"
fi
You can’t perform that action at this time.