Skip to content

Commit

Permalink
Update Dockerfile_* for package building
Browse files Browse the repository at this point in the history
There are two base images used:
  - Builder, e.g. erlangsolutions/erlang:ubuntu-jammy-27.1.2,
    has Erlang preinstalled, and is used to build the package.
  - Target, e.g. ubuntu:jammy, is used to test the package.

Other changes:
  - Simplify and unify 'deb' and 'rpm', removing unnecessary complexity
  - Join commmands with '&&' to capture errors early
  - For new Ubuntu versions, it is necessary to set DEBIAN_FRONTEND
    in order to install the package. Alternatively, one could install
    a dialog frontend.
  - For Rocky/Alma, use 'dnf' as the package manager
  • Loading branch information
chrzaszcz committed Oct 30, 2024
1 parent 99b96f6 commit ce59688
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
23 changes: 11 additions & 12 deletions tools/pkg/Dockerfile_deb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# vi: ft=dockerfile
ARG dockerfile_platform
ARG builder_image
ARG target_image

FROM $dockerfile_platform AS builder
FROM $builder_image AS builder

# Install build deps
ENV DEBIAN_FRONTEND=noninteractive
Expand All @@ -13,37 +14,35 @@ ARG erlang_version
# Fix locales
RUN locale-gen en_US.UTF-8

# Copy source code and put building files
# Copy source code and put building files in proper directories
# The .dockerignore file in root dir ensures only needed files
# including not commited changes are used to build the package
WORKDIR /root/
COPY . ./mongooseim

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

ARG dockerfile_platform
RUN ./deb/install_erlang.sh

ARG version
ARG revision

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

# Create image for sharing and validation of built package
FROM $dockerfile_platform
FROM $target_image AS target

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

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

# Simple check if MiM works
COPY --from=builder /root/mongooseim/tools/wait-for-it.sh .
COPY --from=builder /root/mongooseim/tools/pkg/scripts/smoke_test.sh .
COPY --from=builder /root/mongooseim/tools/pkg/scripts/smoke_templates.escript .
COPY tools/wait-for-it.sh .
COPY tools/pkg/scripts/smoke_test.sh .
COPY tools/pkg/scripts/smoke_templates.escript .

RUN ./smoke_test.sh

Expand Down
34 changes: 11 additions & 23 deletions tools/pkg/Dockerfile_rpm
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
# vi: ft=dockerfile
ARG dockerfile_platform
ARG builder_image
ARG target_image

# Source container is useful for preparing code for the actual build.
FROM $dockerfile_platform AS source
COPY . /SOURCE
# Separate the main code from the testing code.
# So that any changes in the testing code do not trigger cache invalidation in the builder.
RUN mkdir /TESTS \
&& mv /SOURCE/tools/pkg/scripts/smoke_test.sh /TESTS/ \
&& mv /SOURCE/tools/pkg/scripts/smoke_templates.escript /TESTS/

FROM $dockerfile_platform AS builder
FROM $builder_image AS builder

# Install the build dependencies
RUN yum install -y epel-release
RUN yum install -y rpm-build rpmdevtools git make zlib-devel unixODBC-devel gcc gcc-c++ openssl openssl-devel chrpath
RUN dnf install -y rpm-build rpmdevtools git make zlib-devel unixODBC-devel gcc gcc-c++ \
openssl openssl-devel chrpath glibc-locale-source systemd-rpm-macros

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

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

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

# Create image for sharing and validation of built package
FROM $dockerfile_platform
FROM $target_image AS target

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

# Simple check if MiM works
COPY --from=builder /root/rpmbuild/BUILD/mongooseim/tools/wait-for-it.sh .
COPY --from=source /TESTS/* ./
COPY tools/wait-for-it.sh .
COPY tools/pkg/scripts/smoke_test.sh .
COPY tools/pkg/scripts/smoke_templates.escript .

RUN ./smoke_test.sh

Expand Down

0 comments on commit ce59688

Please sign in to comment.