Skip to content

Commit 290aaec

Browse files
committed
Move signing packages script to docker container
1 parent 06a1b70 commit 290aaec

File tree

7 files changed

+36
-20
lines changed

7 files changed

+36
-20
lines changed

.circleci/template.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -707,15 +707,6 @@ jobs:
707707
name: Build package
708708
command: |
709709
./tools/test.sh -p pkg -s false
710-
- run:
711-
name: Install packages necessary for signing
712-
command: |
713-
tools/circle-install-packages.sh \
714-
'dpkg-sig rpm'
715-
- run:
716-
name: Sign package
717-
command: |
718-
./tools/pkg/sign.sh
719710
- when:
720711
condition:
721712
matches:

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/deb/build_package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ date=$(date -R)
3838
sed -i "s#@DATE@#${date}#g" mongooseim/DEBIAN/changelog
3939

4040
chown $USER:$USER -R mongooseim
41-
dpkg-deb -Zxz --build mongooseim ./
41+
dpkg --build mongooseim ./
4242

4343
source /etc/os-release
4444
os=$ID

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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ set -e
33

44
trap 'rm -f ~/.rpmmacros' EXIT
55

6-
cd tools/pkg/packages
7-
PACKAGE_NAME=$(ls)
6+
PACKAGE_NAME=$(find . -maxdepth 1 -type f \( -name "*.deb" -o -name "*.rpm" \))
87

98
echo "$GPG_PRIVATE_KEY" | base64 -d | gpg --batch --pinentry-mode loopback --import
109

@@ -22,17 +21,18 @@ if [[ "$PACKAGE_NAME" == *.deb ]]; then
2221
gpg --import public.key
2322
rm -f public.key
2423

25-
dpkg-sig --sign builder -g "--no-tty --pinentry-mode loopback --passphrase $GPG_PASS" -k "$GPG_KEY_ID" $PACKAGE_NAME
24+
debsigs --gpgopts "--no-tty --pinentry-mode loopback --passphrase $GPG_PASS" \
25+
--sign=origin -k="$GPG_KEY_ID" "$PACKAGE_NAME"
2626
echo "DEB package signed successfully: $PACKAGE_NAME"
2727

28-
dpkg-sig --verify "$PACKAGE_NAME"
28+
debsigs --verify "$PACKAGE_NAME"
2929
echo "DEB package verified successfully: $PACKAGE_NAME"
3030
elif [[ "$PACKAGE_NAME" == *.rpm ]]; then
3131
rpm --import public.key
3232
rm -f public.key
3333

3434
cat > ~/.rpmmacros <<EOF
35-
%__gpg $(which gpg)
35+
%__gpg $(type -p gpg)
3636
%_gpg_path $HOME/.gnupg
3737
%_gpg_name $GPG_KEY_EMAIL
3838
%_signature gpg
@@ -51,6 +51,6 @@ EOF
5151

5252
rm -f ~/.rpmmacros
5353
else
54-
echo "Unknown package type: $PACKAGE_NAME"
54+
echo "No packages found to sign"
5555
exit 1
5656
fi

0 commit comments

Comments
 (0)