Switched to a multi stage build for a significantly smaller container image.
[citadel-docker.git] / Dockerfile
1 # Dockerfile for Citadel
2
3 # Debian Slim has all of the architectures we build on (amd64, i386, arm32)
4 # The first stage build will bring in all of our development tools.
5 FROM debian:bullseye-slim AS build-stage
6
7 # The "branch" argument specifies the branch or tag from which we will build.
8 ARG branch=master
9
10 # All long term persistent data goes here.  Any volume driver may be used.
11 VOLUME /citadel-data
12
13 # Install prerequisites
14 RUN apt -y update
15 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
16
17 # Build our own local copy of Berkeley DB, because the one included with the system libs is too old.
18 # For the container ... we're going to do static binaries because disk is cheap and the Gotards are doing it this way now too.
19 RUN sh -c 'mkdir /tmp/db_build && \
20         cd /tmp/db_build && \
21         curl -k https://easyinstall.citadel.org/db-6.2.32.NC.tar.gz | tar xvzf - && \
22         cd db-6.2.32.NC/build_unix && \
23         ../dist/configure --prefix=/usr/local --disable-static --disable-compat185 --disable-cxx --disable-debug --disable-dump185 --disable-java --disable-tcl --disable-test --without-rpm && \
24         make && \
25         make install && \
26         cd /tmp && \
27         rm -fr /tmp/db_build'
28
29 # Create our build directory
30 RUN mkdir /tmp/ctdl_build
31
32 # Deploy "ctdlvisor", a small supervisor program which runs inside the container to wrangle the various services
33 ADD ctdlvisor.c /tmp
34 RUN sh -c '\
35         cd /tmp && \
36         cc ctdlvisor.c -o /usr/local/bin/ctdlvisor && \
37         rm -vf /tmp/ctdlvisor.c'
38
39 # Grab the repository at the specified branch or tag.  If there wasn't any change we should enjoy the cache.
40 RUN sh -c '\
41         cd /tmp/ctdl_build && \
42         git clone -b $branch --single-branch git://git.citadel.org/citadel'
43
44 # Build libcitadel
45 RUN sh -c '\
46         cd /tmp/ctdl_build/citadel/libcitadel && \
47         ./bootstrap && \
48         ./configure --prefix=/usr/local && \
49         make && \
50         make install'
51
52 # Build the Citadel Server
53 RUN sh -c '\
54         export CFLAGS=-I/usr/local/include && \
55         export LDFLAGS=-L/usr/local/lib && \
56         cd /tmp/ctdl_build/citadel/citadel && \
57         ./bootstrap && \
58         ./configure && \
59         make && \
60         make install'
61
62 # Build the WebCit front end
63 RUN sh -c '\
64         export CFLAGS=-I/usr/local/include && \
65         export LDFLAGS=-L/usr/local/lib && \
66         cd /tmp/ctdl_build/citadel/webcit && \
67         ./bootstrap && \
68         ./configure && \
69         make && \
70         make install'
71
72 # Build the text mode client
73 RUN sh -c '\
74         export CFLAGS=-I/usr/local/include && \
75         export LDFLAGS=-L/usr/local/lib && \
76         cd /tmp/ctdl_build/citadel/textclient && \
77         ./configure --prefix=/usr --ctdldir=/citadel_data && \
78         make && make install && \
79         cd /tmp && \
80         rm -vfr /tmp/ctdl_build && \
81         rm -vrf /usr/local/citadel/data /usr/local/citadel/files /usr/local/citadel/keys /usr/local/webcit/keys'
82
83 ####################################################################################################
84
85 # Second stage build is runtime only.
86 FROM debian:bullseye-slim AS final-stage
87
88 # All long term persistent data goes here.  Any volume driver may be used.
89 VOLUME /citadel-data
90
91 # Install prerequisites
92 RUN apt -y update
93 RUN apt -y install zlib1g libical3 libexpat1 curl libcurl4 netbase libreadline8 libldap-2.4-2 libssl1.1
94
95 # Bring in Citadel and libraries
96 COPY --from=build-stage /usr/local/ /usr/local/
97 RUN ldconfig -v
98
99 # Ports
100 EXPOSE 25 80 110 119 143 443 465 504 563 587 993 995 2020 5222
101
102 # Let's go!
103 ENTRYPOINT ["/usr/local/bin/ctdlvisor"]
104