Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.cache
.git
.vscode
build
coverage
vcpkg_installed
65 changes: 49 additions & 16 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

name: Docker Image CI

on: # yamllint disable-line rule:truthy
Expand All @@ -15,9 +14,8 @@ env:
ARTIFACT_NAME: algorithm-exercises-cpp_${{ github.sha }}

jobs:

build:
name: "Build Docker images"
build-lint:
name: "Build Docker LINT image"
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
Expand All @@ -39,6 +37,14 @@ jobs:
with:
name: ${{ env.ARTIFACT_NAME }}_lint
path: /tmp/${{ env.ARTIFACT_NAME }}_lint.tar
build-test:
name: "Build Docker TEST image"
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: "TEST: Build and push"
uses: docker/build-push-action@v7
Expand All @@ -55,6 +61,14 @@ jobs:
name: ${{ env.ARTIFACT_NAME }}_test
path: /tmp/${{ env.ARTIFACT_NAME }}_test.tar

build-prod:
name: "Build Docker PRODUCTION image"
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: "PRODUCTION: Build and push"
uses: docker/build-push-action@v7
with:
Expand All @@ -71,10 +85,30 @@ jobs:
name: ${{ env.ARTIFACT_NAME }}_prod
path: /tmp/${{ env.ARTIFACT_NAME }}_prod.tar

lint:
run-lint-markdown:
name: "Run in docker: Markdown LINT"
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Run markdown lint
run: >
make compose/lint/markdown

run-lint-yaml:
name: "Run in docker: YAML LINT"
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Run YAML lint
run: >
make compose/lint/yaml

run-lint:
name: "Run in docker: LINT"
runs-on: ubuntu-26.04
needs: build
needs: build-lint
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

Expand All @@ -94,12 +128,12 @@ jobs:
docker
compose --profile lint
run --rm ${{ env.IMAGE_NAME }}-lint
make lint
make lint-no-deps

test:
run-test:
name: "Run in docker: TEST"
runs-on: ubuntu-26.04
needs: build
needs: build-test
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

Expand All @@ -121,12 +155,11 @@ jobs:
run --rm ${{ env.IMAGE_NAME }}-test
make test


# yamllint disable rule:line-length
# security:
# name: "Snyk Container"
# runs-on: ubuntu-26.04
# needs: build
# needs: build-prod
# permissions:
# actions: read
# contents: read
Expand Down Expand Up @@ -175,7 +208,7 @@ jobs:
scan:
name: "Trivy"
runs-on: ubuntu-26.04
needs: build
needs: build-prod
permissions:
actions: read
contents: read
Expand All @@ -196,20 +229,20 @@ jobs:
uses: aquasecurity/trivy-action@v0.36.0
with:
image-ref: ${{ env.IMAGE_NAME }}:${{ github.sha }}
format: 'table'
format: "table"
env:
TRIVY_DB_REPOSITORY: ${{ vars.TRIVY_DB_REPOSITORY }}

- name: Run Trivy vulnerability scanner (sarif report)
uses: aquasecurity/trivy-action@v0.36.0
with:
image-ref: ${{ env.IMAGE_NAME }}:${{ github.sha }}
format: 'sarif'
output: 'trivy-results.sarif'
format: "sarif"
output: "trivy-results.sarif"
env:
TRIVY_DB_REPOSITORY: ${{ vars.TRIVY_DB_REPOSITORY }}

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: 'trivy-results.sarif'
sarif_file: "trivy-results.sarif"
26 changes: 23 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
cmake_minimum_required(VERSION 3.21)

project(algoritm-exercises-cpp CXX C ASM)
project(algorithm-exercises-cpp CXX C ASM)

# Option to control whether compiler should save intermediate temps (assembly files)
option(GENERATE_ASM "Generate assembly outputs (*.s) during the build" OFF)

# Allow overriding from environment variable GENERATE_ASM (1/ON to enable)
if(DEFINED ENV{GENERATE_ASM})
if("$ENV{GENERATE_ASM}" STREQUAL "1" OR "$ENV{GENERATE_ASM}" STREQUAL "ON")
set(GENERATE_ASM ON CACHE BOOL "Generate assembly outputs" FORCE)
endif()
endif()

# Must be set before including CTest so that these arguments are applied when
# running `$ ninja test` or `$ make test`.
Expand All @@ -19,10 +29,20 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# -fsanitize=address causes SIGILL on macOS (Clang 17 + macOS 26 Intel) due to
# ASan runtime incompatibility. Coverage instrumentation still works without it.
if(APPLE)
SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage -g -O0 -save-temps")
if(GENERATE_ASM)
SET(SAVE_TEMPS_FLAG "-save-temps")
else()
SET(SAVE_TEMPS_FLAG "")
endif()
SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage -g -O0 ${SAVE_TEMPS_FLAG}")
SET(GCC_COVERAGE_LINK_FLAGS "--coverage")
else()
SET(GCC_COVERAGE_COMPILE_FLAGS "-fsanitize=address -fprofile-arcs -ftest-coverage -g -O0 -save-temps")
if(GENERATE_ASM)
SET(SAVE_TEMPS_FLAG "-save-temps")
else()
SET(SAVE_TEMPS_FLAG "")
endif()
SET(GCC_COVERAGE_COMPILE_FLAGS "-fsanitize=address -fprofile-arcs -ftest-coverage -g -O0 ${SAVE_TEMPS_FLAG}")
SET(GCC_COVERAGE_LINK_FLAGS "--coverage")
endif()

Expand Down
76 changes: 25 additions & 51 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
ARG BASE_IMAGE_VERSION=ubuntu:26.04
FROM ${BASE_IMAGE_VERSION} AS init
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 make && \
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 \
build-essential ca-certificates curl g++ gcc gpg \
curl gpg lsb-release \
&& apt-get -y install --no-install-recommends --no-install-suggests \
build-essential g++ gcc gpg \
lsb-release make pkg-config \
# 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" \
> /etc/apt/sources.list.d/kitware.list \
&& apt-get -y autoremove curl lsb-release gpg \
&& apt-get update \
&& apt-get install -y --no-install-recommends cmake \
## clean up
&& apt-get -y autoremove curl lsb-release \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& make --version \
&& cmake --version \
&& g++ --version
&& gcc --version \
&& g++ --version \
&& cmake --version

# vcpkg Package Manager
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
Expand All @@ -42,7 +46,9 @@ ENV VCPKG_ROOT=/opt/vcpkg
# vcpkg Package Manager
RUN apt-get -y update && \
apt-get -y install --no-install-recommends --no-install-suggests \
ca-certificates curl git ninja-build unzip zip \
curl \
&& apt-get -y install --no-install-recommends --no-install-suggests \
git ninja-build unzip zip \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir /opt/vcpkg \
&& git clone --branch "${VCPKG_VERSION}" https://github.com/microsoft/vcpkg "${VCPKG_ROOT}" \
Expand Down Expand Up @@ -76,57 +82,26 @@ FROM builder AS development

# CMD []

FROM builder AS lint
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 gnupg software-properties-common && \
rm -rf /var/lib/apt/lists/*

RUN apt-get -y update \
&& apt-get -y install --no-install-recommends --no-install-suggests curl \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL --proto "=https" https://apt.llvm.org/llvm-snapshot.gpg.key \
| gpg --dearmor -o /etc/apt/keyrings/llvm-snapshot.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/llvm-snapshot.gpg] https://apt.llvm.org/resolute/ llvm-toolchain-resolute-22 main" \
| tee /etc/apt/sources.list.d/llvm.list \
&& apt-get -y update \
&& apt-get -y install --no-install-recommends --no-install-suggests clang-format-22 \
&& update-alternatives --install /usr/bin/clang-format clang-format $(which clang-format-22) 100 \
&& apt-get -y autoremove curl \
apt-get -y install --no-install-recommends --no-install-suggests \
clang-format cmake cppcheck \
&& rm -rf /var/lib/apt/lists/*

ADD https://deb.nodesource.com/setup_26.x nodesource_setup.sh
RUN bash nodesource_setup.sh && \
apt-get -y install --no-install-recommends --no-install-suggests nodejs && \
npm install -g --ignore-scripts markdownlint-cli@0.49.1 && \
apt-get -y install --no-install-recommends --no-install-suggests python3-minimal python3-pip && \
rm /usr/lib/python3.*/EXTERNALLY-MANAGED && \
apt-get -y install --no-install-recommends --no-install-suggests yamllint && \
apt-get -y install --no-install-recommends --no-install-suggests cppcheck && \
rm -rf /var/lib/apt/lists/*

# Tooling test
RUN clang-format --version && \
markdownlint --version && \
yamllint --version && \
cppcheck --version
cppcheck --version && \
cmake --version

# Code source
# Copia sólo lo necesario para ejecutar las comprobaciones
COPY ./src ${WORKDIR}/src
COPY ./vcpkg.json ${WORKDIR}/vcpkg.json
COPY ./CMakeLists.txt ${WORKDIR}/CMakeLists.txt
COPY ./CMakePresets.json ${WORKDIR}/CMakePresets.json
COPY ./Makefile ${WORKDIR}/
RUN mkdir -p "${WORKDIR}"/build
COPY --from=builder ${WORKDIR}/build/compile_commands.json ${WORKDIR}/build/compile_commands.json

# markdownlint conf
COPY ./.markdownlint.json ${WORKDIR}/

# yamllint conf
COPY ./.yamllint ${WORKDIR}/
COPY ./.yamlignore ${WORKDIR}/
COPY ./.gitignore ${WORKDIR}/

CMD ["make", "lint"]
CMD ["make", "lint-no-deps"]

FROM development AS testing

Expand All @@ -138,14 +113,13 @@ COPY --from=builder ${WORKDIR}/build ${WORKDIR}/

CMD ["make", "test"]

FROM ${BASE_IMAGE_VERSION} AS production
FROM ubuntu:26.04 AS production

ENV LOG_LEVEL=INFO
ENV BRUTEFORCE=false
ENV WORKDIR=/app
WORKDIR ${WORKDIR}

# COPY ./Makefile ${WORKDIR}/
COPY --from=builder ${WORKDIR}/build/src/lib/exercises/*.a ${WORKDIR}/

RUN useradd --user-group --system --create-home --no-log-init app
Expand Down
Loading
Loading