d79953459d378ecd1de0e4ff5a044bf4d88e07bf
[citadel-docker.git] / Dockerfile
1 # Dockerfile for Citadel
2 #
3 # Copyright (c) 2019-2023 by the citadel.org team
4 #
5 # This program is open source software.  Use, duplication, or disclosure
6 # is subject to the terms of the GNU General Public License, version 3.
7
8 # This script implements a two stage build.  In the first stage we load in a full set of
9 # development tools and build all of the components, including a version of Berkeley DB newer than
10 # the one supplied in the repo.  Everything in /usr/local is copied into the second stage, which
11 # is built with only runtime libraries to keep the image small.
12
13 ####################################################################################################
14
15 # Debian Slim has all of the architectures we build on (amd64, i386, arm32)
16 # The first stage build will bring in all of our development tools.
17 FROM debian:bullseye-slim AS build-stage
18
19 # The "branch" argument specifies the branch or tag from which we will build.
20 ARG branch=master
21
22 # All long term persistent data goes here.  Any volume driver may be used.
23 VOLUME /citadel-data
24
25 # Install prerequisites
26 RUN apt -y update
27 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
28
29 # Build our own local copy of Berkeley DB, because the one included with the system libs is too old.
30 # We will install it to /usr/local and carry it over to the second stage build.
31 # build and install Berkeley DB
32 RUN sh -c 'mkdir /tmp/db_build'
33 RUN sh -c 'cd /tmp/db_build && curl -k https://easyinstall.citadel.org/db-18.1.40.tar.gz | tar xvzf -'
34 RUN sh -c '\
35         cd /tmp/db_build/db-18.1.40/build_unix && \
36         ../dist/configure --prefix=/usr/local \
37                 --with-cryptography=no --disable-hash --disable-heap --disable-queue \
38                 --disable-replication --disable-statistics \
39                 --with-uniquename=_ctdl \
40                 --enable-static --disable-shared \
41                 --disable-compat185 --disable-cxx --disable-debug \
42                 --disable-dump185 --disable-java --disable-tcl --disable-test --without-rpm'
43 RUN sh -c 'cd /tmp/db_build/db-18.1.40/build_unix && make -j`cat /proc/cpuinfo  | grep processor | wc -l`'
44 RUN sh -c 'cd /tmp/db_build/db-18.1.40/build_unix && make install_lib'
45 RUN sh -c 'cd /tmp/db_build/db-18.1.40/build_unix && make install_include'
46 RUN sh -c 'cd /tmp/db_build/db-18.1.40/build_unix && make install_utilities'
47 RUN sh -c 'rm -fr /tmp/db_build'
48
49 # Create our build directory
50 RUN mkdir /tmp/ctdl_build
51
52 # Deploy "ctdlvisor", a small supervisor program which runs inside the container to wrangle the various services
53 ADD ctdlvisor.c /tmp
54 RUN sh -c '\
55         cd /tmp && \
56         cc ctdlvisor.c -o /usr/local/bin/ctdlvisor && \
57         rm -vf /tmp/ctdlvisor.c'
58
59 # Grab the repository at the specified branch or tag.  If there wasn't any change we should enjoy the cache.
60 RUN sh -c '\
61         cd /tmp/ctdl_build && \
62         git clone -b $branch --single-branch https://code.citadel.org/citadel/citadel.git'
63
64 # Build libcitadel
65 RUN sh -c '\
66         cd /tmp/ctdl_build/citadel/libcitadel && \
67         ./bootstrap && \
68         ./configure --prefix=/usr/local && \
69         make && \
70         make install'
71
72 # Build the Citadel Server
73 RUN sh -c '\
74         export CFLAGS=-I/usr/local/include && \
75         export LDFLAGS=-L/usr/local/lib && \
76         cd /tmp/ctdl_build/citadel/citadel && \
77         ./bootstrap && \
78         ./configure && \
79         make && \
80         make install'
81
82 # Build the WebCit front end
83 RUN sh -c '\
84         export CFLAGS=-I/usr/local/include && \
85         export LDFLAGS=-L/usr/local/lib && \
86         cd /tmp/ctdl_build/citadel/webcit && \
87         ./bootstrap && \
88         ./configure && \
89         make && \
90         make install'
91
92 # Build the text mode client
93 RUN sh -c '\
94         export CFLAGS=-I/usr/local/include && \
95         export LDFLAGS=-L/usr/local/lib && \
96         cd /tmp/ctdl_build/citadel/textclient && \
97         ./configure --prefix=/usr/local --ctdldir=/citadel_data && \
98         make && make install && \
99         cd /tmp && \
100         rm -vfr /tmp/ctdl_build && \
101         rm -vrf /usr/local/citadel/data /usr/local/citadel/files /usr/local/citadel/keys /usr/local/webcit/keys'
102
103 ####################################################################################################
104
105 # Second stage build only needs runtime libraries.
106 FROM debian:bullseye-slim AS final-stage
107
108 # All long term persistent data goes here.  Any volume driver may be used.
109 VOLUME /citadel-data
110
111 # Install prerequisites
112 RUN apt -y update
113 RUN apt -y install zlib1g libical3 libexpat1 curl libcurl4 netbase libreadline8 libldap-2.4-2 libssl1.1
114
115 # Bring in Citadel and libraries
116 COPY --from=build-stage /usr/local/ /usr/local/
117 RUN ldconfig -v
118
119 # Ports
120 EXPOSE 25 80 110 119 143 443 465 504 563 587 993 995 5222
121
122 # Let's go!
123 ENTRYPOINT ["/usr/local/bin/ctdlvisor"]
124