| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- # syntax=docker/dockerfile:1.4
- # Smartbotic Package Builder
- # Debian 13 (trixie) based build container for production binaries
- #
- # Usage (standard build - installs dependencies each time):
- # docker buildx build -f packaging/Dockerfile.build --target packages --output "type=local,dest=dist/" .
- #
- # Usage (fast build with pre-built base image):
- # # First build the base image once:
- # docker buildx build -f packaging/Dockerfile.base -t smartbotic-build-base:debian13 .
- # # Then use it for fast builds:
- # docker buildx build -f packaging/Dockerfile.build \
- # --build-arg BASE_IMAGE=smartbotic-build-base:debian13 \
- # --build-arg BUILD_VERSION=x.y.z \
- # --build-arg BUILD_GIT_COMMIT=$(git rev-parse HEAD) \
- # --build-arg BUILD_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) \
- # --target packages --output "type=local,dest=dist/" .
- #
- # Build caches are persistent across builds via BuildKit cache mounts:
- # - /ccache: C++ compiler cache (ccache)
- # - /npm-cache: npm package cache
- ARG BASE_IMAGE=debian:trixie
- FROM ${BASE_IMAGE} AS builder
- ARG BUILD_VERSION=0.0.0
- ARG BUILD_TARGET=debian13
- ARG BUILD_JOBS=16
- ARG BUILD_GIT_COMMIT=unknown
- ARG BUILD_GIT_BRANCH=unknown
- ENV DEBIAN_FRONTEND=noninteractive
- ENV BUILD_VERSION=${BUILD_VERSION}
- ENV BUILD_TARGET=${BUILD_TARGET}
- ENV BUILD_JOBS=${BUILD_JOBS}
- ENV BUILD_GIT_COMMIT=${BUILD_GIT_COMMIT}
- ENV BUILD_GIT_BRANCH=${BUILD_GIT_BRANCH}
- # ccache configuration
- ENV CCACHE_DIR=/ccache
- ENV CCACHE_MAXSIZE=5G
- ENV CCACHE_COMPRESS=1
- ENV CCACHE_COMPRESSLEVEL=6
- ENV PATH="/usr/lib/ccache:${PATH}"
- # Install build dependencies (skipped if using pre-built base image)
- RUN if [ ! -f /etc/smartbotic-build-base ]; then \
- apt-get update && apt-get install -y --no-install-recommends \
- build-essential cmake ninja-build git pkg-config ca-certificates ccache \
- libcurl4-openssl-dev libssl-dev \
- nlohmann-json3-dev libspdlog-dev libsystemd-dev \
- protobuf-compiler libprotobuf-dev libgrpc++-dev protobuf-compiler-grpc \
- liblz4-dev nodejs npm \
- && rm -rf /var/lib/apt/lists/*; \
- else echo "Using pre-built base image: $(cat /etc/smartbotic-build-base)"; fi
- WORKDIR /build
- # Copy package files first for better layer caching
- COPY webui/package.json webui/package-lock.json ./webui/
- # Install npm dependencies with cache mount
- RUN --mount=type=cache,target=/npm-cache,id=npm-cache \
- cd webui && npm ci --cache /npm-cache
- # Copy WebUI source and build
- COPY webui/ ./webui/
- RUN cd webui && npm run build
- # Copy C++ source code (excluding webui which is already copied)
- COPY CMakeLists.txt ./
- COPY cmake/ ./cmake/
- COPY lib/ ./lib/
- COPY src/ ./src/
- COPY config/ ./config/
- COPY packaging/ ./packaging/
- COPY external/ ./external/
- # Build all targets with ccache and Release optimizations
- RUN --mount=type=cache,target=/ccache,id=ccache \
- cmake -B build -G Ninja \
- -DCMAKE_BUILD_TYPE=Release \
- -DCMAKE_C_COMPILER_LAUNCHER=ccache \
- -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
- -DBUILD_TESTS=OFF \
- -DBUNDLE_DATABASE=ON \
- -DGIT_COMMIT_OVERRIDE=${BUILD_GIT_COMMIT} \
- -DGIT_BRANCH_OVERRIDE=${BUILD_GIT_BRANCH} \
- && cmake --build build --parallel ${BUILD_JOBS} \
- && ccache --show-stats || true
- # Package creation stage
- FROM builder AS packager
- # Create package output directory
- RUN mkdir -p /packages
- # Run package creation script
- RUN chmod +x /build/packaging/scripts/create-packages.sh && \
- /build/packaging/scripts/create-packages.sh
- # Output stage - just the packages
- FROM scratch AS packages
- COPY --from=packager /packages/*.tar.gz /
|