diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 510edda..4a92a94 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -163,7 +163,7 @@ jobs: docker compose --profile test run --rm ${{ env.IMAGE_NAME }}-test - make test + make test-no-deps # yamllint disable rule:line-length # security: diff --git a/Dockerfile b/Dockerfile index d136e8b..206f288 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,61 +2,83 @@ FROM ubuntu:26.04 AS init ENV WORKDIR=/app WORKDIR ${WORKDIR} -ENV VCPKG_ROOT=/opt/vcpkg - -RUN apt-get -y update && \ - apt-get -y install --no-install-recommends --no-install-suggests ca-certificates make && \ - rm -rf /var/lib/apt/lists/* - -FROM init AS builder -ARG GENERATE_ASM=0 -ENV GENERATE_ASM=${GENERATE_ASM} ARG DEBIAN_FRONTEND=noninteractive ENV TZ=Etc/UTC -# build tools RUN apt-get update \ && apt-get -y install --no-install-recommends --no-install-suggests \ - curl gpg lsb-release \ + ## common permanent packages + "make=4.4.1-3" \ + && rm -rf /var/lib/apt/lists/* + +COPY ./Makefile ${WORKDIR}/ + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +RUN apt-get update \ && apt-get -y install --no-install-recommends --no-install-suggests \ - build-essential g++ gcc gpg \ - lsb-release make pkg-config \ + ## add ephemeral packages + "curl=8.18.0-1ubuntu2.5" \ + "gpg=2.4.8-4ubuntu3.1" \ + ## common permanent packages + "ca-certificates=20260601~26.04.1" \ # CMAKE from Kitware repository && curl --proto "=https" -fsSL https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null \ | gpg --dearmor -o /usr/share/keyrings/kitware-archive-keyring.gpg \ - && echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu $(lsb_release -cs) main" \ + && echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu resolute main" \ > /etc/apt/sources.list.d/kitware.list \ - && apt-get -y autoremove curl lsb-release gpg \ + # CMAKE from Kitware repository && apt-get update \ - && apt-get install -y --no-install-recommends cmake \ + && apt-get -y install --no-install-recommends --no-install-suggests \ + "cmake=4.4.3-0kitware1ubuntu26.04.1" \ + "cmake-data=4.4.3-0kitware1ubuntu26.04.1" \ + ## remove ephemeral packages + && apt-get -y autoremove curl gpg \ + ## clean up + && rm -rf /var/lib/apt/lists/* + +FROM init AS builder + +ARG GENERATE_ASM=0 +ENV GENERATE_ASM=${GENERATE_ASM} + +# # build tools +RUN apt-get update \ + && apt-get -y install --no-install-recommends --no-install-suggests \ + "build-essential=12.12ubuntu2.26.04.2" \ + "g++=4:15.2.0-5ubuntu1" \ + "gcc=4:15.2.0-5ubuntu1" \ + "pkg-config=2.5.1-4" \ ## clean up && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ - && make --version \ + ## test tools && gcc --version \ && g++ --version \ + && make --version \ && cmake --version -# vcpkg Package Manager +# # vcpkg Package Manager ENV VCPKG_FORCE_SYSTEM_BINARIES=1 ENV VCPKG_VERSION=2026.07.29 ENV VCPKG_ROOT=/opt/vcpkg # vcpkg Package Manager -RUN apt-get -y update && \ - apt-get -y install --no-install-recommends --no-install-suggests \ - curl \ +RUN apt-get -y update \ && apt-get -y install --no-install-recommends --no-install-suggests \ - git ninja-build unzip zip \ + "curl=8.18.0-1ubuntu2.5" \ + "git=1:2.53.0-1ubuntu1" \ + "ninja-build=1.13.2-1" \ + "unzip=6.0-29ubuntu1" \ + "zip=3.0-15ubuntu3" \ + "patchelf=0.18.0-1.4build1" \ && rm -rf /var/lib/apt/lists/* \ && mkdir /opt/vcpkg \ && git clone --branch "${VCPKG_VERSION}" https://github.com/microsoft/vcpkg "${VCPKG_ROOT}" \ && /opt/vcpkg/bootstrap-vcpkg.sh \ - && apt-get -y autoremove curl \ - && ln -s /opt/vcpkg/vcpkg /usr/local/bin/vcpkg && \ - rm -rf /var/lib/apt/lists/* && \ - vcpkg version + && ln -s /opt/vcpkg/vcpkg /usr/local/bin/vcpkg \ + && rm -rf /var/lib/apt/lists/* \ + && vcpkg version # sources COPY ./src ${WORKDIR}/src @@ -80,20 +102,25 @@ CMD ["make", "build"] FROM builder AS development -# CMD [] +CMD [] FROM init AS lint # Instala sólo lo mínimo necesario para linting (cmake, clang-format, cppcheck) RUN apt-get update && \ apt-get -y install --no-install-recommends --no-install-suggests \ - clang-format cmake cppcheck \ - && rm -rf /var/lib/apt/lists/* + "clang-format=1:21.1.6-71" \ + "cppcheck=2.19.0-3" && \ + rm -rf /var/lib/apt/lists/* + +LABEL lint-phase=enabled +LABEL clang-format=enabled +LABEL cppcheck=enabled # Tooling test RUN clang-format --version && \ cppcheck --version && \ - cmake --version + make --version # Copia sólo lo necesario para ejecutar las comprobaciones COPY ./src ${WORKDIR}/src @@ -103,15 +130,16 @@ COPY --from=builder ${WORKDIR}/build/compile_commands.json ${WORKDIR}/build/comp CMD ["make", "lint-no-deps"] -FROM development AS testing +FROM init AS testing RUN apt-get -y update && \ - apt-get -y install --no-install-recommends --no-install-suggests lcov && \ + apt-get -y install --no-install-recommends --no-install-suggests "lcov=2.4-3" && \ rm -rf /var/lib/apt/lists/* -COPY --from=builder ${WORKDIR}/build ${WORKDIR}/ +# COPY --from=builder ${WORKDIR}/build ${WORKDIR}/build +COPY --from=builder ${WORKDIR} ${WORKDIR} -CMD ["make", "test"] +CMD ["make", "test-no-deps"] FROM ubuntu:26.04 AS production @@ -122,8 +150,8 @@ WORKDIR ${WORKDIR} COPY --from=builder ${WORKDIR}/build/src/lib/exercises/*.a ${WORKDIR}/ -RUN useradd --user-group --system --create-home --no-log-init app -USER app +RUN useradd --uid 1001 --user-group --system --create-home --no-log-init app +USER 1001 RUN ls -alhR diff --git a/Makefile b/Makefile index db54e75..f938ad7 100644 --- a/Makefile +++ b/Makefile @@ -121,6 +121,9 @@ format: format/sources format/json test: env dependencies build clean/test cd build && make test +test-no-deps: + cd build && make test + coverage: test lcov ${COVERAGE_TOOL_OPTS} -o coverage/lcov.info \ --no-external --capture \ @@ -175,20 +178,20 @@ compose/lint/json: && echo '✔ Your code looks good.' compose/test/styling: compose/build - ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-c-lint make test/styling + ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-cpp-lint make test/styling compose/test/static: compose/build - ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-c-lint make test/static-no-deps + ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-cpp-lint make test/static-no-deps compose/lint: compose/test/styling compose/test/static compose/lint/all: compose/lint/markdown compose/lint/yaml compose/lint/json compose/test/styling compose/test/static -compose/test: compose/build - ${DOCKER_COMPOSE} --profile testing run --rm algorithm-exercises-c-test make test +compose/test: + ${DOCKER_COMPOSE} --profile testing run --rm algorithm-exercises-cpp-test make test-no-deps compose/run: compose/build - ${DOCKER_COMPOSE} --profile production run --rm algorithm-exercises-c ls -alhR + ${DOCKER_COMPOSE} --profile production run --rm algorithm-exercises-cpp ls -alhR compose/all: compose/rebuild compose/test compose/lint