Skip to content

Fix Docker build vcpkg failures with early error detection and log capture - #12

Merged
makr-code merged 2 commits into
mainfrom
copilot/update-dockerfile-vcpkg-logs
Nov 10, 2025
Merged

makr-code merged 2 commits into
mainfrom
copilot/update-dockerfile-vcpkg-logs

Conversation

Copilot AI commented Nov 10, 2025 •

Copy link
Copy Markdown
Contributor

vcpkg boost-headers build failures during CMake configure produce opaque "ninja exit code 1" errors without visible logs, making CI debugging impossible.

Changes

Dockerfile:

  • Move VCPKG_TRIPLET ARG before vcpkg installation to enable triplet-specific pre-installation
  • Pre-install boost-headers during image build with verbose logging to surface failures immediately instead of during CMake configure
  • Clear stale vcpkg buildtrees/packages/downloads to prevent parallel configure race conditions
  • Add error trap to CMake build that dumps buildtrees logs on failure

CI Workflow (.github/workflows/docker-qnap.yml):

  • Upload vcpkg buildtrees logs as artifacts on build failure

Example

Before: vcpkg failures during CMake configure produce:

ninja: build stopped: subcommand failed
/opt/vcpkg/buildtrees/boost-headers/config-x64-linux-rel-CMakeCache.txt.log

After: failures surface during Docker build with full context:

===== vcpkg boost-headers install failed =====
Listing buildtrees for boost-headers:
Printing boost-headers logs:
<actual error details visible in CI>
Original prompt

Problem

The Docker image build in the CI fails during CMake configure because vcpkg fails building boost-headers (ninja returned exit code 1). The CI logs point to /opt/vcpkg/buildtrees/boost-headers/config-x64-linux-rel-CMakeCache.txt.log but the log isn't captured as an artifact. We need to make the Dockerfile fail earlier with clear vcpkg output, clean stale vcpkg state, and print relevant logs on failure so CI shows the actual error. We should also add a small workflow step to upload vcpkg logs when the build job fails.

Changes to make

  1. Update Dockerfile to:

    • Move the VCPKG_TRIPLET ARG so it's available when we pre-install packages.
    • Clone and bootstrap vcpkg, update it, and clear stale buildtrees/packages/downloads.
    • Pre-install boost-headers for the chosen triplet (verbose) during image build so failures surface immediately.
    • Modify the cmake build RUN to dump vcpkg buildtrees logs on failure.
  2. Update .github/workflows/docker-qnap.yml to upload vcpkg buildtrees logs as artifacts when the job fails.

Files to update

  1. Dockerfile (path: Dockerfile, replace existing contents)
# Multi-stage Docker build for VCCDB (Linux x86_64)

FROM ubuntu:22.04 AS build
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    ninja-build \
    cmake \
    git \
    python3 \
    curl \
    unzip \
    tar \
    wget \
    pkg-config \
    ca-certificates \
    zlib1g-dev \
    libssl-dev \
    libicu-dev \
    zip \
    perl \
    nasm \
    && rm -rf /var/lib/apt/lists/*

# Install vcpkg
WORKDIR /opt
# Allow overriding target triplet (x64-linux default for QNAP x86_64)
ARG VCPKG_TRIPLET=x64-linux
ENV VCPKG_DEFAULT_TRIPLET=${VCPKG_TRIPLET}
RUN git clone https://github.com/microsoft/vcpkg.git vcpkg \
    && /opt/vcpkg/bootstrap-vcpkg.sh
ENV VCPKG_ROOT=/opt/vcpkg
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
ENV PATH="${VCPKG_ROOT}:${PATH}"

# Ensure compilers are discoverable by CMake
ENV CC=/usr/bin/gcc
ENV CXX=/usr/bin/g++

# Make sure vcpkg is updated, clear stale state and pre-install boost-headers to fail early with logs
RUN set -eux; \
    cd ${VCPKG_ROOT}; \
    git fetch --all --tags || true; \
    git reset --hard origin/master || true; \
    ./vcpkg update || true; \
    # remove stale or partial build state that often causes parallel configure failures
    rm -rf buildtrees packages downloads || true; \
    # Attempt to install boost-headers for the default triplet to show concrete failure now
    ./vcpkg install boost-headers:${VCPKG_TRIPLET} -v || ( \
        echo "===== vcpkg boost-headers install failed ====="; \
        echo "Listing buildtrees for boost-headers:"; ls -la buildtrees/boost-headers || true; \
        echo "Printing boost-headers logs:"; tail -n +1 buildtrees/boost-headers/*.log || true; \
        false)

# Allow overriding target triplet at build time too (kept for later stages)
ENV VCPKG_TRIPLET=${VCPKG_TRIPLET}

# Build
WORKDIR /src
COPY . .
RUN set -eux; \
    cmake -S . -B build -G Ninja \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake \
      -DVCPKG_TARGET_TRIPLET=${VCPKG_TRIPLET} \
      -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja \
      -DCMAKE_C_COMPILER=/usr/bin/gcc \
      -DCMAKE_CXX_COMPILER=/usr/bin/g++ \
    && cmake --build build -j \
    || ( \
        echo "===== CMake configure/build failed; dumping vcpkg logs ====="; \
        ls -la /opt/vcpkg/buildtrees || true; \
        tail -n +1 /opt/vcpkg/buildtrees/boost-headers/*.log || true; \
        tail -n +1 /opt/vcpkg/buildtrees/*/config-*-linux-*-CMakeCache.txt.log || true; \
        false )

# Runtime image
FROM ubuntu:22.04 AS runtime
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates curl jq \
    && rm -rf /var/lib/apt/lists/*

# Copy binary and vcpkg-installed libs to satisfy shared deps
COPY --from=build /src/build/themis_server /usr/local/bin/themis_server
COPY --from=build /opt/vcpkg/installed /opt/vcpkg/installed

# Triplet must match the build stage ARG; default to x64-linux
ARG VCPKG_TRIPLET=x64-linux
ENV LD_LIBRARY_PATH=/opt/vcpkg/installed/${VCPKG_TRIPLET}/lib

# Default config and data
COPY config/config.json /etc/vccdb/config.json
# Default Linux/QNAP config template inside image
RUN mkdir -p /usr/local/share/themis
COPY config/config.qnap.json /usr/local/share/themis/config.qnap.json
VOLUME ["/data"]
EXPOSE 8080 18765

# Default to root; can be overridden via docker-compose (user: "0:0" or non-root)

# Configurable server port (overrides JSON via entrypoint)
ENV THEMIS_PORT=18765
ENV THEMIS_CONFIG_PATH=/etc/vccdb/config.json

# Bootstrap entrypoint to adjust config and ensure directories
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
  1. .github/workflows/docker-qnap.yml (update to upload vcp...

This pull request was created as a result of the following prompt from Copilot chat.

Problem

The Docker image build in the CI fails during CMake configure because vcpkg fails building boost-headers (ninja returned exit code 1). The CI logs point to /opt/vcpkg/buildtrees/boost-headers/config-x64-linux-rel-CMakeCache.txt.log but the log isn't captured as an artifact. We need to make the Dockerfile fail earlier with clear vcpkg output, clean stale vcpkg state, and print relevant logs on failure so CI shows the actual error. We should also add a small workflow step to upload vcpkg logs when the build job fails.

Changes to make

  1. Update Dockerfile to:

    • Move the VCPKG_TRIPLET ARG so it's available when we pre-install packages.
    • Clone and bootstrap vcpkg, update it, and clear stale buildtrees/packages/downloads.
    • Pre-install boost-headers for the chosen triplet (verbose) during image build so failures surface immediately.
    • Modify the cmake build RUN to dump vcpkg buildtrees logs on failure.
  2. Update .github/workflows/docker-qnap.yml to upload vcpkg buildtrees logs as artifacts when the job fails.

Files to update

  1. Dockerfile (path: Dockerfile, replace existing contents)
# Multi-stage Docker build for VCCDB (Linux x86_64)

FROM ubuntu:22.04 AS build
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    ninja-build \
    cmake \
    git \
    python3 \
    curl \
    unzip \
    tar \
    wget \
    pkg-config \
    ca-certificates \
    zlib1g-dev \
    libssl-dev \
    libicu-dev \
    zip \
    perl \
    nasm \
    && rm -rf /var/lib/apt/lists/*

# Install vcpkg
WORKDIR /opt
# Allow overriding target triplet (x64-linux default for QNAP x86_64)
ARG VCPKG_TRIPLET=x64-linux
ENV VCPKG_DEFAULT_TRIPLET=${VCPKG_TRIPLET}
RUN git clone https://github.com/microsoft/vcpkg.git vcpkg \
    && /opt/vcpkg/bootstrap-vcpkg.sh
ENV VCPKG_ROOT=/opt/vcpkg
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
ENV PATH="${VCPKG_ROOT}:${PATH}"

# Ensure compilers are discoverable by CMake
ENV CC=/usr/bin/gcc
ENV CXX=/usr/bin/g++

# Make sure vcpkg is updated, clear stale state and pre-install boost-headers to fail early with logs
RUN set -eux; \
    cd ${VCPKG_ROOT}; \
    git fetch --all --tags || true; \
    git reset --hard origin/master || true; \
    ./vcpkg update || true; \
    # remove stale or partial build state that often causes parallel configure failures
    rm -rf buildtrees packages downloads || true; \
    # Attempt to install boost-headers for the default triplet to show concrete failure now
    ./vcpkg install boost-headers:${VCPKG_TRIPLET} -v || ( \
        echo "===== vcpkg boost-headers install failed ====="; \
        echo "Listing buildtrees for boost-headers:"; ls -la buildtrees/boost-headers || true; \
        echo "Printing boost-headers logs:"; tail -n +1 buildtrees/boost-headers/*.log || true; \
        false)

# Allow overriding target triplet at build time too (kept for later stages)
ENV VCPKG_TRIPLET=${VCPKG_TRIPLET}

# Build
WORKDIR /src
COPY . .
RUN set -eux; \
    cmake -S . -B build -G Ninja \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake \
      -DVCPKG_TARGET_TRIPLET=${VCPKG_TRIPLET} \
      -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja \
      -DCMAKE_C_COMPILER=/usr/bin/gcc \
      -DCMAKE_CXX_COMPILER=/usr/bin/g++ \
    && cmake --build build -j \
    || ( \
        echo "===== CMake configure/build failed; dumping vcpkg logs ====="; \
        ls -la /opt/vcpkg/buildtrees || true; \
        tail -n +1 /opt/vcpkg/buildtrees/boost-headers/*.log || true; \
        tail -n +1 /opt/vcpkg/buildtrees/*/config-*-linux-*-CMakeCache.txt.log || true; \
        false )

# Runtime image
FROM ubuntu:22.04 AS runtime
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates curl jq \
    && rm -rf /var/lib/apt/lists/*

# Copy binary and vcpkg-installed libs to satisfy shared deps
COPY --from=build /src/build/themis_server /usr/local/bin/themis_server
COPY --from=build /opt/vcpkg/installed /opt/vcpkg/installed

# Triplet must match the build stage ARG; default to x64-linux
ARG VCPKG_TRIPLET=x64-linux
ENV LD_LIBRARY_PATH=/opt/vcpkg/installed/${VCPKG_TRIPLET}/lib

# Default config and data
COPY config/config.json /etc/vccdb/config.json
# Default Linux/QNAP config template inside image
RUN mkdir -p /usr/local/share/themis
COPY config/config.qnap.json /usr/local/share/themis/config.qnap.json
VOLUME ["/data"]
EXPOSE 8080 18765

# Default to root; can be overridden via docker-compose (user: "0:0" or non-root)

# Configurable server port (overrides JSON via entrypoint)
ENV THEMIS_PORT=18765
ENV THEMIS_CONFIG_PATH=/etc/vccdb/config.json

# Bootstrap entrypoint to adjust config and ensure directories
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
  1. .github/workflows/docker-qnap.yml (update to upload vcpkg logs when the build-and-push job fails). Replace the workflow file contents with the existing content plus the added step after the Build and push step.
name: docker-qnap

on:
  push:
    branches: [ main ]
  workflow_dispatch:

permissions:
  contents: read
  packages: write

env:
  DOCKERHUB_REPO: themisdb/themis
  GHCR_REPO: ghcr.io/${{ github.repository_owner }}/themis

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - platform: linux/amd64
            triplet: x64-linux
          - platform: linux/arm64
            triplet: arm64-linux
    steps:
      - uses: actions/checkout@v4
      - name: Decide if Docker Hub should be pushed
        run: |
          if [ -n "${{ secrets.DOCKERHUB_USERNAME }}" ] && [ -n "${{ secrets.DOCKERHUB_TOKEN }}" ]; then
            echo "PUSH_IMAGE=true" >> $GITHUB_ENV
          else
            echo "PUSH_IMAGE=false" >> $GITHUB_ENV
          fi
      - name: Set short SHA
        run: echo "SHORT_SHA=${GITHUB_SHA::12}" >> $GITHUB_ENV
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Login to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Login to Docker Hub
        if: ${{ env.PUSH_IMAGE == 'true' }}
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Compose image tags
        run: |
          set -e
          TAGS="${GHCR_REPO}:latest-${{ matrix.triplet }}\n${GHCR_REPO}:g${SHORT_SHA}-${{ matrix.triplet }}"
          if [ "${PUSH_IMAGE}" = "true" ]; then
            TAGS="$TAGS\n${DOCKERHUB_REPO}:latest-${{ matrix.triplet }}\n${DOCKERHUB_REPO}:g${SHORT_SHA}-${{ matrix.triplet }}"
          fi
          {
            echo 'TAGS<<EOF'
            echo -e "$TAGS"
            echo 'EOF'
          } >> "$GITHUB_ENV"
      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          platforms: ${{ matrix.platform }}
          build-args: |
            VCPKG_TRIPLET=${{ matrix.triplet }}
            VCPKG_COMMIT=beea85fdd8bf6b716acdac191cde9bfc7c72b73b
            VCPKG_KEEP_BUILDTREES=1
            VCPKG_LOG_LEVEL=debug
          tags: ${{ env.TAGS }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

      - name: Upload vcpkg logs on failure
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: vcpkg-build-logs
          path: |
            /opt/vcpkg/buildtrees/**/*.log
            /opt/vcpkg/buildtrees/**/config-*-linux-*-CMakeCache.txt.log

  manifest:
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    needs: build-and-push
    steps:
      - name: Check Docker Hub credentials
        id: check-dockerhub
        run: |
          if [ -n "${{ secrets.DOCKERHUB_USERNAME }}" ] && [ -n "${{ secrets.DOCKERHUB_TOKEN }}" ]; then
            echo "available=true" >> $GITHUB_OUTPUT
          else
            echo "available=false" >> $GITHUB_OUTPUT
          fi
      - name: Set short SHA
        run: echo "SHORT_SHA=${GITHUB_SHA::12}" >> $GITHUB_ENV
      - name: Login to Docker Hub
        if: steps.check-dockerhub.outputs.available == 'true'
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Login to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Create and push multi-arch manifests (Docker Hub)
        if: steps.check-dockerhub.outputs.available == 'true'
        env:
          DOCKERHUB_REPO: ${{ env.DOCKERHUB_REPO }}
        run: |
          set -e
          echo "Creating manifest for latest"
          docker manifest create "$DOCKERHUB_REPO:latest" \
            --amend "$DOCKERHUB_REPO:latest-x64-linux" \
            --amend "$DOCKERHUB_REPO:latest-arm64-linux"
          docker manifest push "$DOCKERHUB_REPO:latest"

          echo "Creating manifest for g$SHORT_SHA"
          docker manifest create "$DOCKERHUB_REPO:g$SHORT_SHA" \
            --amend "$DOCKERHUB_REPO:g$SHORT_SHA-x64-linux" \
            --amend "$DOCKERHUB_REPO:g$SHORT_SHA-arm64-linux"
          docker manifest push "$DOCKERHUB_REPO:g$SHORT_SHA"
      - name: Create and push multi-arch manifests (GHCR)
        env:
          GHCR_REPO: ${{ env.GHCR_REPO }}
        run: |
          set -e
          echo "Creating GHCR manifest for latest"
          docker manifest create "$GHCR_REPO:latest" \
            --amend "$GHCR_REPO:latest-x64-linux" \
            --amend "$GHCR_REPO:latest-arm64-linux"
          docker manifest push "$GHCR_REPO:latest"

          echo "Creating GHCR manifest for g$SHORT_SHA"
          docker manifest create "$GHCR_REPO:g$SHORT_SHA" \
            --amend "$GHCR_REPO:g$SHORT_SHA-x64-linux" \
            --amend "$GHCR_REPO:g$SHORT_SHA-arm64-linux"
          docker manifest push "$GHCR_REPO:g$SHORT_SHA"

Notes

  • The Dockerfile change forces the boost-headers port to build during image creation. If a system dependency is missing (common cause), the logs will be printed during the Docker build and will surface in the Actions log for the buildx step. This avoids the opaque vcpkg parallel-configure failure later during CMake configure.
  • The workflow upload step may not always find files (vcpkg buildtrees are inside the image build); however, printing logs during Docker build should already reveal the root cause. The upload step is included to capture logs when running builds that expose /opt/vcpkg on the runner.

Please create a branch and open a pull request with the two updated files described above in repository makr-code/ThemisDB.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update Dockerfile to improve vcpkg error handling Fix Docker build vcpkg failures with early error detection and log capture Nov 10, 2025
Copilot AI requested a review from makr-code November 10, 2025 17:54
@makr-code
makr-code marked this pull request as ready for review November 10, 2025 18:16
@makr-code
makr-code merged commit c62fbfd into main Nov 10, 2025
@makr-code
makr-code deleted the copilot/update-dockerfile-vcpkg-logs branch November 30, 2025 11:50
makr-code added a commit that referenced this pull request Dec 6, 2025
…-logs

Fix Docker build vcpkg failures with early error detection and log capture
Copilot AI added a commit that referenced this pull request Jan 3, 2026
Issue #9 - Configuration error logging:
- Add specific exception catching for YAML and JSON parsing errors
- Log detailed error messages with exception details
- Add file open failure logging
- Better debugging for configuration issues

Issue #10 - Defensive nullptr checks:
- Add null check after transaction creation in TransactionManager
- Throw exception if MVCC transaction creation fails
- Existing code already has good checks for GetBaseDB(), weak_ptr::lock()

Issue #11 - Static cast usage:
- Documented in new coding standards
- Added guidelines for safe type conversions
- Existing casts are safe (size comparisons, dimension checks)

Issue #12 - Code style consistency:
- Created comprehensive CODING_STANDARDS.md
- Defined logging level usage (ERROR, WARN, INFO, DEBUG)
- Memory management guidelines (RAII, smart pointers)
- Thread safety patterns (atomics, mutexes)
- Signal handler safety requirements
- Error handling best practices

Co-authored-by: makr-code <[email protected]>
Copilot AI added a commit that referenced this pull request Jan 7, 2026
Security fixes for remaining TODO items from ROCKSDB_WRAPPER_AUDIT_REPORT.md:

Issue #12 (Phase 2 - Reopen Leak):
- Add explicit close() before db_.reset() when database already open
- Prevents resource leak when reopening after failed open
- Ensures clean state before reinitialization

Issue #13 (Phase 2 - Snapshot Inconsistency):
- Add comprehensive documentation for snapshot lifecycle
- Clarify that snapshots are transaction-local
- Warn callers not to use snapshot pointers after transaction ends

Issue #14 (Phase 2 - write_options Cleanup):
- Already fixed: del() function now uses transactions (line 567)
- No direct write_options_ access, prevents use-after-free
- Consistent with MVCC transaction model

Issue #15 (Phase 3 - Infinite Loop in scanPrefix):
- Add prefix_same_as_start ReadOption for prefix scans
- Prevents over-iteration when prefix doesn't match
- RocksDB optimizes and auto-stops when prefix changes
- Protects against denial-of-service via excessive scanning

All 4 security gaps from audit report are now addressed.

Co-authored-by: makr-code <[email protected]>
@makr-code makr-code added this to the Phase 3: Integration & Testing milestone Feb 21, 2026
@makr-code makr-code added this to the v1.0.2 milestone Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants