Skip to content

Commit 6fdd662

Browse files
Merge pull request #4385 from esl/use-erlang-images
Use prebuilt Docker images with Erlang to build packages
2 parents 8980ead + dda6c97 commit 6fdd662

File tree

9 files changed

+83
-96
lines changed

9 files changed

+83
-96
lines changed

.circleci/template.yml

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ version: 2.1
22

33
references:
44
# Latest OTP release version number (on the right): https://www.erlang.org/downloads
5-
# Available cimg-erlang images: https://hub.docker.com/r/mongooseim/cimg-erlang/tags
5+
# Available cimg-erlang images: https://hub.docker.com/r/erlangsolutions/erlang/tags?name=cimg
66
# You could need to trigger a pipeline to create a Docker image:
77
# https://github.com/esl/cimg-erlang#trigger-build-using-trigger-pipeline-on-circleci
8-
- &OTP26 mongooseim/cimg-erlang:26.2.5.2
9-
- &OTP27 mongooseim/cimg-erlang:27.0.1
8+
- &LATEST_OTP_VERSION 27.1.2
9+
- &OTP26 erlangsolutions/erlang:cimg-26.2.5.4
10+
- &OTP27 erlangsolutions/erlang:cimg-27.1.2
1011
- &ENTRYPOINT ["/bin/sh", "-c", "eval ${INSTALL_DEPS_CMD:-echo} && echo __INJECT_FILES__ | eval ${BASE32DEC:-base32 --decode} | bash"]
1112
# Caches created via the save_cache step are stored for up to 15 days
1213
- &CERT_KEY certs-cache-{{ checksum "certs_cache_key" }}-v3
@@ -689,14 +690,15 @@ jobs:
689690
type: executor
690691
platform:
691692
type: enum
692-
enum: [rockylinux_9, rockylinux_8, almalinux_9, almalinux_8, debian_bullseye, debian_buster, ubuntu_xenial, ubuntu_focal, ubuntu_bionic, ubuntu_jammy]
693+
enum: [debian-bookworm, debian-bullseye, debian-buster, ubuntu-oracular, ubuntu-noble, ubuntu-jammy, ubuntu-focal, rockylinux-9, rockylinux-8, almalinux-9, almalinux-8]
693694
description: Platform type
694-
otp_package:
695+
otp_version:
695696
type: string
696-
description: Version of the Erlang package to install
697+
description: Version of Erlang/OTP to use
698+
default: *LATEST_OTP_VERSION
697699
environment:
698700
pkg_PLATFORM: <<parameters.platform>>
699-
ESL_ERLANG_PKG_VER: <<parameters.otp_package>>
701+
pkg_OTP_VERSION: <<parameters.otp_version>>
700702
PRESET: pkg
701703
steps:
702704
- checkout
@@ -735,55 +737,72 @@ workflows:
735737
filters: &release_tags
736738
tags:
737739
only: /^\d+\.\d+\.\d+/
738-
# ============= PACKAGES =============
740+
# # ============= PACKAGES =============
739741
- package:
740-
name: rockylinux_8
742+
name: debian-bookworm
741743
executor: otp_27
742-
platform: rockylinux_8
744+
platform: debian-bookworm
743745
context: mongooseim-org
744-
otp_package: "26.2.4"
745746
filters: *all_tags
746747
- package:
747-
name: almalinux_8
748+
name: debian-bullseye
748749
executor: otp_27
749-
platform: almalinux_8
750+
platform: debian-bullseye
750751
context: mongooseim-org
751-
otp_package: "26.2.4"
752752
filters: *all_tags
753753
- package:
754-
name: debian_bullseye
754+
name: debian-buster
755755
executor: otp_27
756-
platform: debian_bullseye
756+
platform: debian-buster
757757
context: mongooseim-org
758-
otp_package: "26.2.1"
759758
filters: *all_tags
760759
- package:
761-
name: debian_buster
760+
name: ubuntu-oracular
762761
executor: otp_27
763-
platform: debian_buster
762+
platform: ubuntu-oracular
764763
context: mongooseim-org
765-
otp_package: "26.2.3"
766764
filters: *all_tags
767765
- package:
768-
name: ubuntu_jammy
766+
name: ubuntu-noble
769767
executor: otp_27
770-
platform: ubuntu_jammy
768+
platform: ubuntu-noble
771769
context: mongooseim-org
772-
otp_package: "26.2.3"
773770
filters: *all_tags
774771
- package:
775-
name: ubuntu_focal
772+
name: ubuntu-jammy
776773
executor: otp_27
777-
platform: ubuntu_focal
774+
platform: ubuntu-jammy
778775
context: mongooseim-org
779-
otp_package: "26.2.1"
780776
filters: *all_tags
781777
- package:
782-
name: ubuntu_bionic
778+
name: ubuntu-focal
783779
executor: otp_27
784-
platform: ubuntu_bionic
780+
platform: ubuntu-focal
781+
context: mongooseim-org
782+
filters: *all_tags
783+
- package:
784+
name: rockylinux-9
785+
executor: otp_27
786+
platform: rockylinux-9
787+
context: mongooseim-org
788+
filters: *all_tags
789+
- package:
790+
name: rockylinux-8
791+
executor: otp_27
792+
platform: rockylinux-8
793+
context: mongooseim-org
794+
filters: *all_tags
795+
- package:
796+
name: almalinux-9
797+
executor: otp_27
798+
platform: almalinux-9
799+
context: mongooseim-org
800+
filters: *all_tags
801+
- package:
802+
name: almalinux-8
803+
executor: otp_27
804+
platform: almalinux-8
785805
context: mongooseim-org
786-
otp_package: "26.2.3"
787806
filters: *all_tags
788807
# ======== BASE DOCKER BUILDS ========
789808
- build_in_docker:

tools/pkg/Dockerfile_deb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# vi: ft=dockerfile
2-
ARG dockerfile_platform
2+
ARG builder_image
3+
ARG target_image
34

4-
FROM $dockerfile_platform AS builder
5+
FROM $builder_image AS builder
56

67
# Install build deps
78
ENV DEBIAN_FRONTEND=noninteractive
@@ -13,37 +14,35 @@ ARG erlang_version
1314
# Fix locales
1415
RUN locale-gen en_US.UTF-8
1516

16-
# Copy source code and put building files
17+
# Copy source code and put building files in proper directories
1718
# The .dockerignore file in root dir ensures only needed files
1819
# including not commited changes are used to build the package
1920
WORKDIR /root/
2021
COPY . ./mongooseim
2122

2223
RUN cp -r ./mongooseim/tools/pkg/scripts/deb .
2324

24-
ARG dockerfile_platform
25-
RUN ./deb/install_erlang.sh
26-
2725
ARG version
2826
ARG revision
2927

3028
RUN ./deb/build_package.sh $version $revision $erlang_version
3129

3230
# Create image for sharing and validation of built package
33-
FROM $dockerfile_platform
31+
FROM $target_image AS target
3432

3533
# Copy built package from previous image and install it with required dependencies
36-
RUN apt-get update && apt-get -y install openssl procps netcat && apt-get -y clean
34+
ENV DEBIAN_FRONTEND=noninteractive
35+
RUN apt-get update && apt-get -y install openssl procps && apt-get -y clean
3736
WORKDIR /root/
3837
COPY --from=builder /root/*.deb .
3938

4039
# Install mongooseim with required dependencies
41-
RUN apt-get update; dpkg -i *.deb; apt-get install -y -f
40+
RUN apt-get update && dpkg -i *.deb && apt-get install -y -f
4241

4342
# Simple check if MiM works
44-
COPY --from=builder /root/mongooseim/tools/wait-for-it.sh .
45-
COPY --from=builder /root/mongooseim/tools/pkg/scripts/smoke_test.sh .
46-
COPY --from=builder /root/mongooseim/tools/pkg/scripts/smoke_templates.escript .
43+
COPY tools/wait-for-it.sh .
44+
COPY tools/pkg/scripts/smoke_test.sh .
45+
COPY tools/pkg/scripts/smoke_templates.escript .
4746

4847
RUN ./smoke_test.sh
4948

tools/pkg/Dockerfile_rpm

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
# vi: ft=dockerfile
2-
ARG dockerfile_platform
2+
ARG builder_image
3+
ARG target_image
34

4-
# Source container is useful for preparing code for the actual build.
5-
FROM $dockerfile_platform AS source
6-
COPY . /SOURCE
7-
# Separate the main code from the testing code.
8-
# So that any changes in the testing code do not trigger cache invalidation in the builder.
9-
RUN mkdir /TESTS \
10-
&& mv /SOURCE/tools/pkg/scripts/smoke_test.sh /TESTS/ \
11-
&& mv /SOURCE/tools/pkg/scripts/smoke_templates.escript /TESTS/
12-
13-
FROM $dockerfile_platform AS builder
5+
FROM $builder_image AS builder
146

157
# Install the build dependencies
16-
RUN yum install -y epel-release
17-
RUN yum install -y rpm-build rpmdevtools git make zlib-devel unixODBC-devel gcc gcc-c++ openssl openssl-devel chrpath
8+
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
1810

1911
# Fix locale setup
2012
# See https://github.com/CentOS/sig-cloud-instance-images/issues/71#issuecomment-266957519
21-
ARG dockerfile_platform
22-
RUN if [ "$dockerfile_platform" == "rockylinux:8" ] || [ "$dockerfile_platform" == "almalinux:8" ]; then \
23-
dnf install -y glibc-locale-source; \
24-
fi
2513
RUN localedef -i en_US -f UTF-8 en_US.UTF-8
2614

2715
ARG erlang_version
@@ -32,8 +20,7 @@ ARG erlang_version
3220
# including not commited changes are used to build the package
3321
RUN rpmdev-setuptree
3422
WORKDIR /root/rpmbuild
35-
COPY --from=source /SOURCE ./BUILD/mongooseim
36-
RUN ./BUILD/mongooseim/tools/pkg/scripts/rpm/install_erlang.sh
23+
COPY . ./BUILD/mongooseim
3724

3825
RUN cp ./BUILD/mongooseim/tools/pkg/scripts/rpm/mongooseim.spec ./SPECS/.
3926
RUN cp ./BUILD/mongooseim/tools/pkg/scripts/rpm/mongooseim.service \
@@ -45,16 +32,17 @@ ARG revision
4532
RUN ./BUILD/mongooseim/tools/pkg/scripts/rpm/build_package.sh $version $revision $erlang_version
4633

4734
# Create image for sharing and validation of built package
48-
FROM $dockerfile_platform
35+
FROM $target_image AS target
4936

5037
# Copy built package from previous image and install it with required dependencies
5138
WORKDIR /root/
5239
COPY --from=builder /root/mongooseim*.rpm .
53-
RUN yum -y update; yum install -y mongooseim*.rpm
40+
RUN dnf -y update && dnf install -y mongooseim*.rpm
5441

5542
# Simple check if MiM works
56-
COPY --from=builder /root/rpmbuild/BUILD/mongooseim/tools/wait-for-it.sh .
57-
COPY --from=source /TESTS/* ./
43+
COPY tools/wait-for-it.sh .
44+
COPY tools/pkg/scripts/smoke_test.sh .
45+
COPY tools/pkg/scripts/smoke_templates.escript .
5846

5947
RUN ./smoke_test.sh
6048

tools/pkg/build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ for (( i = 0; i < $len - 1; i++ )); do
7272
i=$((i+1))
7373
done
7474

75-
dockerfile_platform=${platform/_/:}
75+
builder_image="erlangsolutions/erlang:${platform}-${erlang_version}"
76+
target_image="${platform/-/:}"
7677
docker build -t mongooseim-${platform}:${version}-${revision} \
77-
--build-arg dockerfile_platform=${dockerfile_platform} \
78+
--build-arg builder_image=${builder_image} \
79+
--build-arg target_image=${target_image} \
7880
--build-arg version=${version} \
7981
--build-arg revision=${revision} \
8082
--build-arg erlang_version=${erlang_version} \

tools/pkg/scripts/deb/debian/postinst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ setup()
4040

4141
case "$1" in
4242
configure)
43-
adduser --quiet --system --shell /bin/sh --group --home $PKG_ROOT $NAME 2>/dev/null
43+
useradd --system --shell /bin/sh --home-dir $PKG_ROOT --create-home $NAME
4444
setup "$@"
4545
;;
4646

tools/pkg/scripts/deb/install_erlang.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

tools/pkg/scripts/rpm/install_erlang.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

tools/pkg/scripts/rpm/mongooseim.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ BuildRequires: gcc
2323
BuildRequires: gcc-c++
2424
BuildRequires: openssl
2525
BuildRequires: openssl-devel
26-
BuildRequires: esl-erlang
26+
BuildRequires: systemd-rpm-macros
2727

2828
%description
2929
MongooseIM is Erlang Solutions' robust and efficient XMPP server aimed at large
@@ -49,6 +49,10 @@ chrpath -d %{buildroot}/usr/lib/mongooseim/lib/crypto-*/priv/lib/otp_test_engine
4949
install -p -D -m 0644 %{SOURCE0} %{buildroot}%{_unitdir}/mongooseim.service
5050

5151
%pre
52+
if ! [ -d %{_localstatedir}/lock ]; then
53+
# /var/lock links to non-existing /run/lock on Rocky Linux 9
54+
mkdir -m 755 `readlink -f %{_localstatedir}/lock`
55+
fi
5256
getent group mongooseim >/dev/null || groupadd mongooseim
5357
getent passwd mongooseim >/dev/null || adduser -g mongooseim mongooseim
5458
exit 0

tools/test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ build_pkg () {
278278
cd tools/pkg
279279

280280
local platform=$1
281-
local esl_erlang_pkg_vsn=$2
281+
local erlang_version=$2
282282
local project_root=$(git rev-parse --show-toplevel)
283283

284284
if [[ $platform == rockylinux* ]] || [[ $platform == almalinux* ]]; then
@@ -302,7 +302,7 @@ build_pkg () {
302302
--platform $platform \
303303
--version $version \
304304
--revision $revision \
305-
--erlang_version $esl_erlang_pkg_vsn \
305+
--erlang_version $erlang_version \
306306
--dockerfile_path "$project_root/tools/pkg/$dockerfile_name" \
307307
--context_path $project_root \
308308
--built_packages_directory "$project_root/tools/pkg/packages"
@@ -331,7 +331,7 @@ elif [ "$PRESET" == "edoc_only" ]; then
331331
tools/print-dots.sh stop
332332
exit ${RESULT}
333333
elif [ "$PRESET" == "pkg" ]; then
334-
build_pkg $pkg_PLATFORM $ESL_ERLANG_PKG_VER
334+
build_pkg $pkg_PLATFORM $pkg_OTP_VERSION
335335
elif [ "$PRESET" == "small_tests" ]; then
336336
time maybe_run_small_tests
337337
SMALL_RESULT=$?

0 commit comments

Comments
 (0)