\$\begingroup\$
\$\endgroup\$
4
I have the following dockerfile, which builds a Backend and Frontend for a large project. The project uses the following technologies:
- C++ (using vcpkg as a package manager <-- very slow)
- Swift (using SPM <-- reasonably fast)
- Rust (using Cargo <-- reasonably fast)
- NPM (reasonably fast)
Can you review this docker build with a focus on speed and performance? I am looking forward to replace this build script with nix; will this negatively impact the performance of this project?
FROM swift:6.0.3-noble AS build1-environment
RUN apt update && apt upgrade -y && apt install -y curl && curl -sfS https://dotenvx.sh | sh
FROM build1-environment AS build2-environment
RUN apt install -y curl git cmake \
ninja-build gdb clangd clang-format clang-tidy zip unzip swi-prolog \
cargo rustc rust-src rustfmt npm
# we do not need to install clang since it is included in the swift:noble image
FROM build2-environment AS vcpkg-builder
# install vcpkg
RUN curl -L -o vcpkg.tar.gz https://github.com/microsoft/vcpkg/archive/master.tar.gz
RUN mkdir /opt/vcpkg
RUN tar xf vcpkg.tar.gz --strip-components=1 -C /opt/vcpkg
RUN /opt/vcpkg/bootstrap-vcpkg.sh
RUN ln -s /opt/vcpkg/vcpkg /usr/local/bin/vcpkg
# build dependencies
WORKDIR /tmp/vcpkg-cache
COPY vcpkg.json .
ENV VCPKG_BUILD_PARALLEL_LEVEL=8
RUN vcpkg install --triplet x64-linux
FROM build2-environment AS development
ARG BUILD_MODE
WORKDIR /
RUN git config --global --add safe.directory /workspace
FROM development AS build
ARG BUILD_MODE
COPY --from=vcpkg-builder --chmod=777 /root/.cache/vcpkg ~/.cache/vcpkg
RUN mkdir /workspace
COPY . /workspace
WORKDIR /workspace
RUN dotenvx run -f .env.${BUILD_MODE} -- cmake \
--preset debug-x86-64-unknown-linux-gnu \
-S . \
-B out/build/debug-x86-64-unknown-linux-gnu \
-G Ninja
RUN dotenvx run -f .env.${BUILD_MODE} -- ninja \
-C out/build/debug-x86-64-unknown-linux-gnu \
SwiftPackage
RUN strip .build/debug/LX
FROM build1-environment AS production
ARG BUILD_MODE
ENV BUILD_MODE=${BUILD_MODE}
RUN mkdir /app
COPY --from=build /workspace/.build/debug/LX /app
COPY --from=build /workspace/.env* /app
WORKDIR /app
CMD /usr/bin/env dotenvx run -f .env.${BUILD_MODE} -- /app/LX
EXPOSE 1337
HEALTHCHECK CMD curl --fail http://localhost:1337/version || exit 1
Currently, the build times are around 30min, mostly for apt-get-dependencies and vcpkg.
lang-cpp
&&
. Reference: stackoverflow.com/a/39330458/4688321. Also, you may want to removevcpkg.tar.gz
once its extracted. \$\endgroup\$