# Dockerfile for Citadel
+#
+# Copyright (c) 2019-2023 by the citadel.org team
+#
+# This program is open source software. Use, duplication, or disclosure
+# is subject to the terms of the GNU General Public License, version 3.
-# This container is built on MiniDeb, a stripped down version of Debian for use in containers.
-# Rehosting on another base Linux image is not expected to create compatibility issues.
-FROM debian:stable-slim
+# This script implements a two stage build. In the first stage we load in a full set of
+# development tools and build all of the components, including a version of Berkeley DB newer than
+# the one supplied in the repo. Everything in /usr/local is copied into the second stage, which
+# is built with only runtime libraries to keep the image small.
+
+####################################################################################################
+
+# Debian Slim has all of the architectures we build on (amd64, i386, arm32)
+# The first stage build will bring in all of our development tools.
+FROM debian:bullseye-slim AS build-stage
+
+# The "branch" argument specifies the branch or tag from which we will build.
+ARG branch=master
# All long term persistent data goes here. Any volume driver may be used.
VOLUME /citadel-data
-RUN apt -y update
-
# Install prerequisites
+RUN apt -y update
RUN apt -y install gcc bison make zlib1g-dev libldap2-dev libssl-dev gettext libical-dev libexpat1-dev curl libcurl4-openssl-dev git autoconf automake netbase libreadline-dev
# Build our own local copy of Berkeley DB, because the one included with the system libs is too old.
-RUN sh -c 'mkdir /tmp/db_build && \
- cd /tmp/db_build && \
- curl -k https://easyinstall.citadel.org/db-6.2.32.NC.tar.gz | tar xvzf - && \
- cd db-6.2.32.NC/build_unix && \
- ../dist/configure --prefix=/usr/local/ctdlsupport --disable-compat185 --disable-cxx --disable-debug --disable-dump185 --disable-java --disable-tcl --disable-test --without-rpm && \
- make && \
- make install && \
- cd /tmp && \
- rm -fr /tmp/db_build'
-
-# Deploy "ctdlvisor", a small supervisor program which runs inside the container to wrangle the various services
-ADD ctdlvisor.c /tmp
+# We will install it to /usr/local and carry it over to the second stage build.
+# build and install Berkeley DB
+RUN sh -c 'mkdir /tmp/db_build'
+RUN sh -c 'cd /tmp/db_build && curl -k https://easyinstall.citadel.org/db-18.1.40.tar.gz | tar xvzf -'
+RUN sh -c '\
+ cd /tmp/db_build/db-18.1.40/build_unix && \
+ ../dist/configure --prefix=/usr/local \
+ --enable-smallbuild \
+ --with-uniquename=_ctdl \
+ --enable-static --disable-shared \
+ --disable-compat185 --disable-cxx --disable-debug \
+ --disable-dump185 --disable-java --disable-tcl --disable-test --without-rpm'
+RUN sh -c 'cd /tmp/db_build/db-18.1.40/build_unix && make -j`cat /proc/cpuinfo | grep processor | wc -l`'
+RUN sh -c 'cd /tmp/db_build/db-18.1.40/build_unix && make install_lib'
+RUN sh -c 'cd /tmp/db_build/db-18.1.40/build_unix && make install_include'
+RUN sh -c 'cd /tmp/db_build/db-18.1.40/build_unix && make install_utilities'
+RUN sh -c 'rm -fr /tmp/db_build'
# Create our build directory
RUN mkdir /tmp/ctdl_build
-# Burn the cache if the upstream repository has changed
-ADD "https://easyinstall.citadel.org/libcitadel-easyinstall.tar.gz" /tmp/ctdl_build
-ADD "https://easyinstall.citadel.org/citadel-easyinstall.tar.gz" /tmp/ctdl_build
-ADD "https://easyinstall.citadel.org/webcit-easyinstall.tar.gz" /tmp/ctdl_build
-ADD "https://easyinstall.citadel.org/textclient-easyinstall.tar.gz" /tmp/ctdl_build
+# Deploy "ctdlvisor", a small supervisor program which runs inside the container to wrangle the various services
+ADD ctdlvisor.c /tmp
+RUN sh -c '\
+ cd /tmp && \
+ cc ctdlvisor.c -o /usr/local/bin/ctdlvisor && \
+ rm -vf /tmp/ctdlvisor.c'
-# Download and build Citadel
-RUN sh -c 'export CFLAGS=-I/usr/local/ctdlsupport/include && \
- export LDFLAGS="-L/usr/local/ctdlsupport/lib -Wl,--rpath -Wl,/usr/local/ctdlsupport/lib" && \
+# Grab the repository at the specified branch or tag. If there wasn't any change we should enjoy the cache.
+RUN sh -c '\
cd /tmp/ctdl_build && \
- tar xvzf libcitadel-easyinstall.tar.gz && \
- tar xvzf citadel-easyinstall.tar.gz && \
- tar xvzf webcit-easyinstall.tar.gz && \
- tar xvzf textclient-easyinstall.tar.gz && \
- cd /tmp/ctdl_build/libcitadel && \
- ./configure --prefix=/usr && \
+ git clone -b $branch --single-branch https://code.citadel.org/citadel/citadel.git'
+
+# Build libcitadel
+RUN sh -c '\
+ cd /tmp/ctdl_build/citadel/libcitadel && \
+ ./bootstrap && \
+ ./configure --prefix=/usr/local && \
make && \
- make install && \
- cd /tmp/ctdl_build/citadel && \
+ make install'
+
+# Build the Citadel Server
+RUN sh -c '\
+ export CFLAGS=-I/usr/local/include && \
+ export LDFLAGS=-L/usr/local/lib && \
+ cd /tmp/ctdl_build/citadel/citadel && \
+ ./bootstrap && \
./configure && \
make && \
- make install && \
- cd /tmp/ctdl_build/webcit && \
+ make install'
+
+# Build the WebCit front end
+RUN sh -c '\
+ export CFLAGS=-I/usr/local/include && \
+ export LDFLAGS=-L/usr/local/lib && \
+ cd /tmp/ctdl_build/citadel/webcit && \
+ ./bootstrap && \
./configure && \
make && \
- make install && \
- cd /tmp/ctdl_build/textclient && \
- ./bootstrap && \
- ./configure --prefix=/usr --ctdldir=/citadel_data && \
+ make install'
+
+# Build the text mode client
+RUN sh -c '\
+ export CFLAGS=-I/usr/local/include && \
+ export LDFLAGS=-L/usr/local/lib && \
+ cd /tmp/ctdl_build/citadel/textclient && \
+ ./configure --prefix=/usr/local --ctdldir=/citadel_data && \
make && make install && \
cd /tmp && \
- cc ctdlvisor.c -o /usr/local/bin/ctdlvisor && \
- rm -vf /tmp/ctdlvisor.c && \
- cd /tmp && \
rm -vfr /tmp/ctdl_build && \
rm -vrf /usr/local/citadel/data /usr/local/citadel/files /usr/local/citadel/keys /usr/local/webcit/keys'
+####################################################################################################
+
+# Second stage build only needs runtime libraries.
+FROM debian:bullseye-slim AS final-stage
+
+# All long term persistent data goes here. Any volume driver may be used.
+VOLUME /citadel-data
+
+# Install prerequisites
+RUN apt -y update
+RUN apt -y install zlib1g libical3 libexpat1 curl libcurl4 netbase libreadline8 libldap-2.4-2 libssl1.1
+
+# Bring in Citadel and libraries
+COPY --from=build-stage /usr/local/ /usr/local/
+RUN ldconfig -v
+
# Ports
-EXPOSE 25 80 110 119 143 443 465 504 563 587 993 995 2020 5222
+EXPOSE 25 80 110 119 143 443 465 504 563 587 993 995 5222
# Let's go!
ENTRYPOINT ["/usr/local/bin/ctdlvisor"]
+