Skip to content

Commit 96818b2

Browse files
authored
Merge pull request #4399 from esl/sign-mim-packages
Add package signing script to the CI pipeline
2 parents a9697a3 + 290aaec commit 96818b2

File tree

5 files changed

+85
-4
lines changed

5 files changed

+85
-4
lines changed

tools/pkg/Dockerfile_deb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
# vi: ft=dockerfile
23
ARG builder_image
34
ARG target_image
@@ -7,7 +8,15 @@ FROM $builder_image AS builder
78
# Install build deps
89
ENV DEBIAN_FRONTEND=noninteractive
910
RUN apt-get update
10-
RUN apt-get install -y locales git make zlib1g-dev unixodbc-dev gcc g++ libssl-dev curl
11+
RUN apt-get install -y locales git make zlib1g-dev unixodbc-dev gcc g++ libssl-dev curl gpg wget gnupg
12+
13+
# The signing script requires debsigs version 0.2 or higher, which is unavailable in
14+
# package repositories of Ubuntu versions earlier than 24.10 and Debian versions earlier than 13.
15+
# TODO: Switch to installing debsigs via apt once support for these older versions is dropped.
16+
RUN wget http://ftp.de.debian.org/debian/pool/main/d/debsigs/debsigs_0.2.2-1_all.deb && \
17+
dpkg -i debsigs_0.2.2-1_all.deb && \
18+
rm debsigs_0.2.2-1_all.deb && \
19+
which debsigs
1120

1221
ARG erlang_version
1322

@@ -27,6 +36,12 @@ ARG revision
2736

2837
RUN ./deb/build_package.sh $version $revision $erlang_version
2938

39+
# Sign the built package with the keys provided
40+
RUN --mount=type=secret,id=GPG_PUBLIC_KEY,env=GPG_PUBLIC_KEY \
41+
--mount=type=secret,id=GPG_PRIVATE_KEY,env=GPG_PRIVATE_KEY \
42+
--mount=type=secret,id=GPG_PASS,env=GPG_PASS \
43+
./mongooseim/tools/pkg/sign.sh
44+
3045
# Create image for sharing and validation of built package
3146
FROM $target_image AS target
3247

tools/pkg/Dockerfile_rpm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
# vi: ft=dockerfile
23
ARG builder_image
34
ARG target_image
@@ -6,7 +7,7 @@ FROM $builder_image AS builder
67

78
# Install the build dependencies
89
RUN dnf install -y rpm-build rpmdevtools git make zlib-devel unixODBC-devel gcc gcc-c++ \
9-
openssl openssl-devel chrpath glibc-locale-source systemd-rpm-macros
10+
openssl openssl-devel chrpath glibc-locale-source systemd-rpm-macros rpm-sign
1011

1112
# Fix locale setup
1213
# See https://github.com/CentOS/sig-cloud-instance-images/issues/71#issuecomment-266957519
@@ -31,12 +32,18 @@ ARG revision
3132

3233
RUN ./BUILD/mongooseim/tools/pkg/scripts/rpm/build_package.sh $version $revision $erlang_version
3334

35+
# Sign the built package with the keys provided
36+
RUN --mount=type=secret,id=GPG_PUBLIC_KEY,env=GPG_PUBLIC_KEY \
37+
--mount=type=secret,id=GPG_PRIVATE_KEY,env=GPG_PRIVATE_KEY \
38+
--mount=type=secret,id=GPG_PASS,env=GPG_PASS \
39+
./BUILD/mongooseim/tools/pkg/sign.sh
40+
3441
# Create image for sharing and validation of built package
3542
FROM $target_image AS target
3643

3744
# Copy built package from previous image and install it with required dependencies
3845
WORKDIR /root/
39-
COPY --from=builder /root/mongooseim*.rpm .
46+
COPY --from=builder /root/rpmbuild/mongooseim*.rpm .
4047
RUN dnf -y update && dnf install -y mongooseim*.rpm
4148

4249
# Simple check if MiM works

tools/pkg/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ docker build -t mongooseim-${platform}:${version}-${revision} \
8080
--build-arg version=${version} \
8181
--build-arg revision=${revision} \
8282
--build-arg erlang_version=${erlang_version} \
83+
--secret id=GPG_PUBLIC_KEY \
84+
--secret id=GPG_PRIVATE_KEY \
85+
--secret id=GPG_PASS \
8386
-f ${dockerfile_path} \
8487
$context_path
8588

tools/pkg/scripts/rpm/build_package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ os_version=$VERSION_ID
2121
package_os_file_name=${os}~${os_version}
2222

2323
mv ~/rpmbuild/RPMS/${arch}/mongooseim-${version}-${revision}.${arch}.rpm \
24-
~/mongooseim_${version}_${revision}_otp_${otp_version}~${package_os_file_name}_${package_name_arch}.rpm
24+
~/rpmbuild/mongooseim_${version}_${revision}_otp_${otp_version}~${package_os_file_name}_${package_name_arch}.rpm

tools/pkg/sign.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
trap 'rm -f ~/.rpmmacros' EXIT
5+
6+
PACKAGE_NAME=$(find . -maxdepth 1 -type f \( -name "*.deb" -o -name "*.rpm" \))
7+
8+
echo "$GPG_PRIVATE_KEY" | base64 -d | gpg --batch --pinentry-mode loopback --import
9+
10+
GPG_KEY_ID=$(gpg --list-keys --with-colons | grep '^pub' | cut -d':' -f5)
11+
if [ -z "$GPG_KEY_ID" ]; then
12+
echo "Error: Failed to import GPG key."
13+
exit 1
14+
fi
15+
16+
GPG_KEY_EMAIL=$(gpg --list-keys --with-colons | grep '^uid' | cut -d':' -f10 | head -n 1)
17+
18+
echo "$GPG_PUBLIC_KEY" | base64 -d > public.key
19+
20+
if [[ "$PACKAGE_NAME" == *.deb ]]; then
21+
gpg --import public.key
22+
rm -f public.key
23+
24+
debsigs --gpgopts "--no-tty --pinentry-mode loopback --passphrase $GPG_PASS" \
25+
--sign=origin -k="$GPG_KEY_ID" "$PACKAGE_NAME"
26+
echo "DEB package signed successfully: $PACKAGE_NAME"
27+
28+
debsigs --verify "$PACKAGE_NAME"
29+
echo "DEB package verified successfully: $PACKAGE_NAME"
30+
elif [[ "$PACKAGE_NAME" == *.rpm ]]; then
31+
rpm --import public.key
32+
rm -f public.key
33+
34+
cat > ~/.rpmmacros <<EOF
35+
%__gpg $(type -p gpg)
36+
%_gpg_path $HOME/.gnupg
37+
%_gpg_name $GPG_KEY_EMAIL
38+
%_signature gpg
39+
%_gpg_pass $GPG_PASS
40+
%__gpg_sign_cmd %{__gpg} gpg --no-verbose --no-armor --batch \
41+
--pinentry-mode loopback --passphrase "%{_gpg_pass}" \
42+
--no-secmem-warning -u "%{_gpg_name}" \
43+
-sbo %{__signature_filename} %{__plaintext_filename}
44+
EOF
45+
46+
rpm --addsign "$PACKAGE_NAME"
47+
echo "RPM package signed successfully: $PACKAGE_NAME"
48+
49+
rpm --checksig "$PACKAGE_NAME"
50+
echo "RPM package verified successfully: $PACKAGE_NAME"
51+
52+
rm -f ~/.rpmmacros
53+
else
54+
echo "No packages found to sign"
55+
exit 1
56+
fi

0 commit comments

Comments
 (0)