Skip to content

Commit

Permalink
Improve docker build
Browse files Browse the repository at this point in the history
* Use current code instead of cloning from github.
* Use multi-stage instead of deleting everything.
  • Loading branch information
orgads committed Dec 8, 2024
1 parent 375b652 commit ac584d8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 31 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.git
.gitignore
.dockerignore
Dockerfile
build-docker.sh
*.o
*.lo
*.la
**/build
**/.deps
75 changes: 44 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
FROM debian:bookworm-slim
FROM debian:bookworm-slim AS build
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
autoconf \
automake \
build-essential \
ca-certificates \
cmake \
curl \
g++ \
gcc \
git \
libboost-filesystem-dev \
libboost-log-dev \
libboost-system-dev \
libboost-thread-dev \
libcurl4-openssl-dev \
libgoogle-perftools-dev \
libssl-dev \
libtool \
libtool-bin \
make \
zlib1g-dev

ARG BUILD_CPUS=4
ARG DETECTED_TAG=main
WORKDIR /usr/local/src/drachtio-server
COPY . .
RUN ./bootstrap.sh
WORKDIR /usr/local/src/drachtio-server/build
ARG MYVERSION=1.0.0
RUN ../configure --enable-tcmalloc=yes CPPFLAGS='-DNDEBUG' CXXFLAGS='-O2'
RUN make -j$(nproc) MYVERSION=${MYVERSION}

FROM debian:bookworm-slim

RUN apt-get update \
&& apt-get -y --quiet --force-yes upgrade \
&& apt-get install -y --no-install-recommends ca-certificates gcc g++ make build-essential \
cmake git autoconf automake curl libtool libtool-bin libssl-dev libcurl4-openssl-dev zlib1g-dev \
libgoogle-perftools-dev jq libboost-all-dev \
&& git clone --depth=50 https://github.com/drachtio/drachtio-server.git /usr/local/src/drachtio-server \
&& cd /usr/local/src/drachtio-server \
&& git fetch --tags \
&& echo "checking out ${DETECTED_TAG}" \
&& git checkout ${DETECTED_TAG} \
&& git submodule update --init --recursive \
&& ./bootstrap.sh \
&& mkdir build \
&& cd build \
&& ../configure --enable-tcmalloc=yes CPPFLAGS='-DNDEBUG' CXXFLAGS='-O2' \
&& make -j${BUILD_CPUS} \
&& make install \
&& apt-get purge -y --quiet --auto-remove gcc g++ make cmake build-essential git libtool libtool-bin \
&& rm -rf /var/lib/apt/* \
&& rm -rf /var/lib/dpkg/* \
&& rm -rf /var/lib/cache/* \
&& rm -Rf /var/log/* \
&& rm -Rf /var/lib/apt/lists/* \
&& cd /usr/local/src \
&& cp drachtio-server/docker.drachtio.conf.xml /etc/drachtio.conf.xml \
&& cp drachtio-server/entrypoint.sh / \
&& rm -Rf drachtio-server \
&& cd /usr/local/bin \
&& rm -f timer ssltest parser uri_test test_https test_asio_curl
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
jq \
libboost-filesystem1.74.0 \
libboost-log1.74.0 \
libboost-system1.74.0 \
libboost-thread1.74.0 \
libgoogle-perftools4 \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

COPY --from=build /usr/local/src/drachtio-server/build/drachtio /usr/local/bin/
COPY docker.drachtio.conf.xml /etc/drachtio.conf.xml
COPY ./entrypoint.sh /

VOLUME ["/config"]
Expand Down
3 changes: 3 additions & 0 deletions build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

docker build --build-arg MYVERSION=$(git describe --always) . "$@"

0 comments on commit ac584d8

Please sign in to comment.