Skip to content

Commit 8a0382f

Browse files
authored
Merge pull request #718 from jenkinsci/feat/jenkins-gpg-key-2026
feat(deb,rpm) allow custom GPG public key file through a new environment variable 'GPG_PUBLIC_KEY_FILE' and fix missing Debian HTML
2 parents 1e2834d + bacd952 commit 8a0382f

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

bin/indexGenerator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(self, argv):
6060
self.product_name = os.getenv("PRODUCTNAME", "Jenkins")
6161
self.distribution = os.getenv("OS_FAMILY", "debian")
6262
self.gpg_pub_key_info_file = os.getenv("GPGPUBKEYINFO", ".")
63+
self.gpg_public_key_filename = os.getenv("GPG_PUBLIC_KEY_FILENAME", "jenkins.io.key")
6364
self.target_directory = "./target/" + self.distribution
6465

6566
try:
@@ -107,6 +108,7 @@ def show_information(self):
107108
print("Root header generated: " + self.root_header)
108109
print("Root footer generated: " + self.root_footer)
109110
print("GPG Key Info File: " + self.gpg_pub_key_info_file)
111+
print("GPG Public Key Filename: " + self.gpg_public_key_filename)
110112

111113
def generate_root_header(self):
112114

@@ -169,6 +171,7 @@ def generate_repository_header(self):
169171
"releaseline": self.releaseline,
170172
"web_url": self.web_url,
171173
"pub_key_info": self.fetch_pubkeyinfo(),
174+
"gpg_public_key_filename": self.gpg_public_key_filename,
172175
}
173176

174177
env = jinja2.Environment(
@@ -192,6 +195,7 @@ def generate_repository_index(self):
192195
"releaseline": self.releaseline,
193196
"web_url": self.web_url,
194197
"pub_key_info": self.fetch_pubkeyinfo(),
198+
"gpg_public_key_filename": self.gpg_public_key_filename,
195199
}
196200

197201
env = jinja2.Environment(

deb/publish/publish.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set -euxo pipefail
88
: "${DEBDIR:? Require where to put binary files}"
99
: "${DEB_WEBDIR:? Require where to put repository index and other web contents}"
1010
: "${DEB_URL:? Require Debian repository Url}"
11+
: "${GPG_PUBLIC_KEY_FILENAME:="${ORGANIZATION}.key"}"
1112

1213
# $$ Contains current pid
1314
D="$AGENT_WORKDIR/$$"
@@ -22,12 +23,14 @@ function clean() {
2223
function generateSite() {
2324
cp -R "$bin/contents/." "$D/contents"
2425

25-
gpg --export -a --output "$D/contents/${ORGANIZATION}.key" "${GPG_KEYNAME}"
26-
gpg --import-options show-only --import "$D/contents/${ORGANIZATION}.key" >"$D/contents/${ORGANIZATION}.key.info"
26+
local gpg_publickey_file="$D/contents/${GPG_PUBLIC_KEY_FILENAME}"
27+
local gpg_publickey_info_file="$D/contents/${GPG_PUBLIC_KEY_FILENAME}.info"
28+
gpg --export -a --output "${gpg_publickey_file}" "${GPG_KEYNAME}"
29+
gpg --import-options show-only --import "${gpg_publickey_file}" > "${gpg_publickey_info_file}"
2730

2831
"$BASE/bin/indexGenerator.py" \
2932
--distribution debian \
30-
--gpg-key-info-file "${D}/contents/${ORGANIZATION}.key.info" \
33+
--gpg-key-info-file "${gpg_publickey_info_file}" \
3134
--targetDir "$D/html"
3235

3336
"$BASE/bin/branding.py" "$D"
@@ -87,14 +90,10 @@ function uploadPackageSite() {
8790
}
8891

8992
function uploadHtmlSite() {
90-
# Html file need to be located in the binary directory
9193
rsync --archive \
9294
--verbose \
9395
--progress \
94-
--include "HEADER.html" \
95-
--include "FOOTER.html" \
96-
--exclude "*" \
97-
"$D/html/" "$DEBDIR/"
96+
"$D/html/" "$DEB_WEBDIR/"
9897
}
9998

10099
function show() {
@@ -103,6 +102,7 @@ function show() {
103102
echo "DEBDIR: $DEBDIR"
104103
echo "DEB_WEBDIR: $DEB_WEBDIR"
105104
echo "GPG_KEYNAME: $GPG_KEYNAME"
105+
echo "GPG_PUBLIC_KEY_FILENAME: $GPG_PUBLIC_KEY_FILENAME"
106106
echo "---"
107107
}
108108

rpm/publish/publish.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set -euxo pipefail
88
: "${RPM_URL:?Require rpm repository url}"
99
: "${RELEASELINE?Require rpm release line}"
1010
: "${BASE:?Require base directory}"
11+
: "${GPG_PUBLIC_KEY_FILENAME:="${ORGANIZATION}.key"}"
1112

1213
# $$ Contains current pid
1314
D="$AGENT_WORKDIR/$$"
@@ -17,10 +18,14 @@ function clean() {
1718
}
1819

1920
function generateSite() {
20-
local gpg_publickey="$D/repodata/repomd.xml.key"
21-
mkdir -p "$(dirname "${gpg_publickey}")"
22-
gpg --export -a --output "${gpg_publickey}" "${GPG_KEYNAME}"
23-
gpg --import-options show-only --import "${gpg_publickey}" >"$D/${ORGANIZATION}.key.info"
21+
local gpg_publickey_repomd="$D/repodata/repomd.xml.key"
22+
local gpg_publickey_file="$D/${GPG_PUBLIC_KEY_FILENAME}"
23+
local gpg_publickey_info_file="$D/${GPG_PUBLIC_KEY_FILENAME}.info"
24+
25+
mkdir -p "$(dirname "${gpg_publickey_repomd}")"
26+
gpg --export -a --output "${gpg_publickey_repomd}" "${GPG_KEYNAME}"
27+
gpg --import-options show-only --import "${gpg_publickey_repomd}" > "${gpg_publickey_info_file}"
28+
cp "${gpg_publickey_repomd}" "${gpg_publickey_file}" # Duplicate between repository files and user facing website
2429

2530
cat >"$D/${ARTIFACTNAME}.repo" <<EOF
2631
[${ARTIFACTNAME}]
@@ -39,7 +44,7 @@ EOF
3944

4045
"$BASE/bin/indexGenerator.py" \
4146
--distribution rpm \
42-
--gpg-key-info-file "${D}/${ORGANIZATION}.key.info" \
47+
--gpg-key-info-file "${gpg_publickey_info_file}" \
4348
--targetDir "$D"
4449

4550
"$BASE/bin/branding.py" "$D"
@@ -76,6 +81,7 @@ function show() {
7681
echo "RPMDIR: $RPMDIR"
7782
echo "RPM_WEBDIR: $RPM_WEBDIR"
7883
echo "GPG_KEYNAME: $GPG_KEYNAME"
84+
echo "GPG_PUBLIC_KEY_FILENAME: $GPG_PUBLIC_KEY_FILENAME"
7985
echo "---"
8086
}
8187

templates/header.debian.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<pre class="text-white bg-dark">
1111
<code>
1212
sudo wget -O /etc/apt/keyrings/jenkins-keyring.asc \
13-
<a href="{{web_url}}/{{organization}}-2023.key" style="color:white">{{web_url}}/{{organization}}-2023.key</a></code>
13+
<a href="{{web_url}}/{{gpg_public_key_filename}}" style="color:white">{{web_url}}/{{gpg_public_key_filename}}</a></code>
1414
</pre>
1515

1616
Then add a Jenkins apt repository entry:

0 commit comments

Comments
 (0)