From ac584d80909b776a599fcc3a72bfbc1ca40633e7 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 8 Dec 2024 11:22:39 +0200 Subject: [PATCH] Improve docker build * Use current code instead of cloning from github. * Use multi-stage instead of deleting everything. --- .dockerignore | 10 +++++++ Dockerfile | 75 +++++++++++++++++++++++++++++-------------------- build-docker.sh | 3 ++ 3 files changed, 57 insertions(+), 31 deletions(-) create mode 100644 .dockerignore create mode 100755 build-docker.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..d536ee6e7d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.git +.gitignore +.dockerignore +Dockerfile +build-docker.sh +*.o +*.lo +*.la +**/build +**/.deps diff --git a/Dockerfile b/Dockerfile index cc45f66270..febf143ba4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/build-docker.sh b/build-docker.sh new file mode 100755 index 0000000000..603ad497ac --- /dev/null +++ b/build-docker.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker build --build-arg MYVERSION=$(git describe --always) . "$@"