canary/docker/Dockerfile.dev
Eduardo Dantas 2194d3731f
CI/CD: improve permissions, artifacts, vcpkg cache, and test flexibility (#3832)
This commit significantly improves the CI/CD workflows and build configuration with a focus on security, reliability, and flexibility.

Key changes:
- Added explicit permissions blocks to all reusable workflows and updated the main CI workflow to grant contents: write where required.
- Improved artifact handling by uploading built binaries on Linux, macOS, and Windows, and clearly separating main branch Docker image pushes from PR artifact exports.
- Strengthened vcpkg binary cache handling by validating that cache uploads are not skipped and failing the build if no cache is pushed.
- Updated NuGet authentication to prefer the dedicated VCPKG_PACKAGES_TOKEN secret, with a fallback to GITHUB_TOKEN.
- Added MySQL service setup and schema import to the Linux workflow to enable database-backed tests.
- Gated test execution based on build type to improve CI test coverage.
- Refactored the CMake build system by replacing BUILD_TESTING with CANARY_BUILD_TESTS for more granular control.
- Added and updated CMake presets to enable or disable tests across platforms and configurations.

These changes make the build and test automation more robust, secure, and configurable for both CI and local development.
2026-02-05 13:44:29 -03:00

91 lines
3.3 KiB
Text

# syntax=docker/dockerfile:1.7
# Stage 1: Download all dependencies
FROM ubuntu:24.04 AS dependencies
ARG DEBIAN_FRONTEND=noninteractive
ENV DEBIAN_FRONTEND=${DEBIAN_FRONTEND}
ENV TZ=Etc/UTC
ARG VCPKG_FEED_URL
ARG VCPKG_FEED_USERNAME
ARG VCPKG_BINARY_SOURCES
ENV VCPKG_BINARY_SOURCES=${VCPKG_BINARY_SOURCES}
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
apt-get update && apt-get install -y --no-install-recommends cmake git \
unzip build-essential ca-certificates curl zip unzip tar \
pkg-config ninja-build autoconf automake libtool glibc-tools \
python3 mono-complete tzdata \
&& ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime \
&& echo "${TZ}" > /etc/timezone \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /opt
COPY vcpkg.json /opt
RUN vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ' | tr -d '\r\n') \
&& echo "vcpkg commit ID: '$vcpkgCommitId'" \
&& git clone https://github.com/microsoft/vcpkg.git \
&& cd vcpkg \
&& git fetch origin \
&& git checkout "$vcpkgCommitId" \
&& ./bootstrap-vcpkg.sh
# Install dependencies using manifest mode standalone
WORKDIR /opt/vcpkg_manifest
COPY vcpkg.json /opt/vcpkg_manifest/
RUN --mount=type=secret,id=github_token \
--mount=type=cache,target=/opt/vcpkg/downloads \
--mount=type=cache,target=/opt/vcpkg/buildtrees \
--mount=type=cache,target=/opt/vcpkg/packages \
--mount=type=cache,target=/root/.cache/vcpkg \
/bin/bash -euo pipefail -c '\
if [ ! -s /run/secrets/github_token ]; then \
echo "Missing /run/secrets/github_token" >&2; \
exit 1; \
fi; \
NUGET_AUTH_TOKEN=$(cat /run/secrets/github_token); \
NUGET_CONFIG=/tmp/nuget.config; \
printf "%s\n" \
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" \
"<configuration>" \
" <packageSources>" \
" <add key=\"GitHubPackages\" value=\"${VCPKG_FEED_URL}\" />" \
" </packageSources>" \
" <packageSourceCredentials>" \
" <GitHubPackages>" \
" <add key=\"Username\" value=\"${VCPKG_FEED_USERNAME}\" />" \
" <add key=\"ClearTextPassword\" value=\"${NUGET_AUTH_TOKEN}\" />" \
" </GitHubPackages>" \
" </packageSourceCredentials>" \
" <config>" \
" <add key=\"defaultPushSource\" value=\"GitHubPackages\" />" \
" </config>" \
"</configuration>" \
> "${NUGET_CONFIG}"; \
export VCPKG_NUGET_API_KEY="${NUGET_AUTH_TOKEN}"; \
export VCPKG_BINARY_SOURCES="clear;nugetconfig,${NUGET_CONFIG},readwrite;nugettimeout,1200"; \
/opt/vcpkg/vcpkg install --x-manifest-root=/opt/vcpkg_manifest --x-install-root=/opt/vcpkg_installed; \
rm -f "${NUGET_CONFIG}"; \
unset NUGET_AUTH_TOKEN'
# Stage 2: create build
FROM dependencies AS build
WORKDIR /srv/build
COPY src ./src
COPY cmake ./cmake
COPY recompile.sh CMakeLists.txt CMakePresets.json vcpkg.json ./
# Copy the vcpkg_installed directory from dependencies stage
COPY --from=dependencies /opt/vcpkg_installed ./vcpkg_installed
RUN export VCPKG_MANIFEST_INSTALL=OFF && export VCPKG_INSTALLED_DIR=/srv/build/vcpkg_installed && ./recompile.sh "/opt"
# Stage 3: execute
FROM ubuntu:24.04 AS prod
COPY --from=build /srv/build/build/linux-release/bin/canary /bin/canary
WORKDIR /srv/canary
ENTRYPOINT ["/srv/canary/start.sh", "canary"]