From 3ffab112548f929b534dc65988abdd7510e7e0e6 Mon Sep 17 00:00:00 2001 From: Iason Nikolas Date: Sat, 5 Mar 2022 13:57:49 +0200 Subject: [PATCH 01/12] Add clang-format along with the llvm installation and set the correct version --- .devcontainer/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index e948180e..bbdf6e1f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -50,11 +50,14 @@ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - 2>/dev/ apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ apt-get install -y --no-install-recommends \ clang-${LLVM_VER} lldb-${LLVM_VER} lld-${LLVM_VER} clangd-${LLVM_VER} \ - llvm-${LLVM_VER}-dev libclang-${LLVM_VER}-dev clang-tidy-${LLVM_VER} + llvm-${LLVM_VER}-dev libclang-${LLVM_VER}-dev clang-tidy-${LLVM_VER} clang-format-${LLVM_VER} # Set the default clang-tidy, so CMake can find it RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy $(which clang-tidy-${LLVM_VER}) 1 +# Set the default clang-format +RUN update-alternatives --install /usr/bin/clang-format clang-format $(which clang-format-${LLVM_VER}) 1 + # Set clang-${LLVM_VER} as default clang RUN update-alternatives --install /usr/bin/clang clang $(which clang-${LLVM_VER}) 100 RUN update-alternatives --install /usr/bin/clang++ clang++ $(which clang++-${LLVM_VER}) 100 From 56033114e133bbc8326400bcb1b5762c07d39527 Mon Sep 17 00:00:00 2001 From: Iason Nikolas Date: Sat, 5 Mar 2022 13:15:39 +0200 Subject: [PATCH 02/12] Add cmake_format python package to the docker container --- .devcontainer/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index bbdf6e1f..29df2003 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -13,9 +13,9 @@ RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ make ninja-build git \ python3 python3-pip -# Install conan +# Install conan and cmake format RUN python3 -m pip install --upgrade pip setuptools && \ - python3 -m pip install conan && \ + python3 -m pip install conan cmake_format && \ conan --version # By default, anything you run in Docker is done as superuser. From b3764f3b1f472fee97b055c1c0080955346abdaf Mon Sep 17 00:00:00 2001 From: Dave Dalcino Date: Sat, 2 Apr 2022 18:15:02 -0700 Subject: [PATCH 03/12] Fix CMake installation process per https://apt.kitware.com/ Related to: https://github.com/cpp-best-practices/cpp_starter_project/issues/210 --- .devcontainer/Dockerfile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 29df2003..1ae47cf0 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -63,12 +63,15 @@ RUN update-alternatives --install /usr/bin/clang clang $(which clang-${LLVM_VER} RUN update-alternatives --install /usr/bin/clang++ clang++ $(which clang++-${LLVM_VER}) 100 # Add current cmake/ccmake, from Kitware -ARG CMAKE_URL="https://apt.kitware.com/ubuntu/" -ARG CMAKE_PKG=${VARIANT} +ENV KEYRING_FILE="/usr/share/keyrings/kitware-archive-keyring.gpg" RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null \ - | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \ - apt-add-repository -y "deb ${CMAKE_URL} ${CMAKE_PKG} main" && \ - apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ + | gpg --dearmor - | tee "${KEYRING_FILE}" >/dev/null && \ + echo "deb [signed-by=${KEYRING_FILE}] https://apt.kitware.com/ubuntu/ ${VARIANT} main" \ + | tee /etc/apt/sources.list.d/kitware.list >/dev/null && \ + apt-get update && \ + rm "${KEYRING_FILE}" && \ + apt-get install kitware-archive-keyring && \ + export DEBIAN_FRONTEND=noninteractive && \ apt-get install -y --no-install-recommends cmake cmake-curses-gui # Install editors From fc99d63862a22c184b4c54834172595f3b1b461d Mon Sep 17 00:00:00 2001 From: Dave Dalcino Date: Sun, 3 Apr 2022 10:11:35 -0700 Subject: [PATCH 04/12] Move Dockerfile to dedicated folder --- {.devcontainer => docker}/Dockerfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {.devcontainer => docker}/Dockerfile (100%) diff --git a/.devcontainer/Dockerfile b/docker/Dockerfile similarity index 100% rename from .devcontainer/Dockerfile rename to docker/Dockerfile From 1f9538d137f81c2f7c847ed5b002abc491d24b98 Mon Sep 17 00:00:00 2001 From: Dave Dalcino Date: Sun, 3 Apr 2022 10:11:50 -0700 Subject: [PATCH 05/12] Add basic tests for installed programs. This causes the container build process to execute each of the programs, querying the version of each program. If any program cannot report its version, the build process fails. --- docker/Dockerfile | 7 +++++-- docker/print_versions.sh | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 docker/print_versions.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index 1ae47cf0..b367e28c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,8 +15,7 @@ RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ # Install conan and cmake format RUN python3 -m pip install --upgrade pip setuptools && \ - python3 -m pip install conan cmake_format && \ - conan --version + python3 -m pip install conan cmake_format # By default, anything you run in Docker is done as superuser. # Conan runs some install commands as superuser, and will prepend `sudo` to @@ -119,6 +118,10 @@ ENV CXX=${USE_CLANG:+"clang++"} ENV CC=${CC:-"gcc"} ENV CXX=${CXX:-"g++"} +# Check that all required programs have been installed. Fail if anything is missing. +COPY print_versions.sh . +RUN /bin/bash ./print_versions.sh + # Include project #ADD . /workspaces/cpp_starter_project #WORKDIR /workspaces/cpp_starter_project diff --git a/docker/print_versions.sh b/docker/print_versions.sh new file mode 100644 index 00000000..089882a2 --- /dev/null +++ b/docker/print_versions.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -ex +# Prints versions of all relevant installed tools. Fails if those tools do not exist. + +cat /etc/lsb-release +g++ --version +clang++ --version +clang-format --version +python3 --version +pip --version +conan --version +cmake --version +ccmake --version +cppcheck --version +doxygen --version +include-what-you-use --version +cmake-format --version + From 12532a6dbe3f20de6878dda883074795533af7c7 Mon Sep 17 00:00:00 2001 From: Dave Dalcino Date: Sat, 2 Apr 2022 23:36:08 -0700 Subject: [PATCH 06/12] Cleanup anything that should be added by users Users that need a CLI code editor can add it back in themselves. Users that are using the Dockerfile to build and deploy code can add their project themselves. --- docker/Dockerfile | 9 --------- 1 file changed, 9 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index b367e28c..984664ee 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -73,11 +73,6 @@ RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/nul export DEBIAN_FRONTEND=noninteractive && \ apt-get install -y --no-install-recommends cmake cmake-curses-gui -# Install editors -RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ - apt-get install -y --no-install-recommends \ - neovim emacs nano - # Install optional dependecies RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ apt-get install -y --no-install-recommends \ @@ -122,8 +117,4 @@ ENV CXX=${CXX:-"g++"} COPY print_versions.sh . RUN /bin/bash ./print_versions.sh -# Include project -#ADD . /workspaces/cpp_starter_project -#WORKDIR /workspaces/cpp_starter_project - CMD ["/bin/bash"] From 10cc4d2fe91005201407cf6a5ff4900b30039df3 Mon Sep 17 00:00:00 2001 From: Dave Dalcino Date: Sun, 3 Apr 2022 10:03:28 -0700 Subject: [PATCH 07/12] Use dependent container in .devcontainer --- .devcontainer/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .devcontainer/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..b048ec97 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,4 @@ +# FROM ghcr.io/cpp_best_practices/cpp:0.1.0 # TODO: activate +FROM ghcr.io/ddalcino/cpp:0.1.0 + +# Add your own modifications to the Docker environment here From c8e855cd1419e1804239142017a00522234b773a Mon Sep 17 00:00:00 2001 From: Dave Dalcino Date: Sat, 2 Apr 2022 19:05:26 -0700 Subject: [PATCH 08/12] add workflow to publish container --- .github/workflows/publish-dockerfile.yml | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/publish-dockerfile.yml diff --git a/.github/workflows/publish-dockerfile.yml b/.github/workflows/publish-dockerfile.yml new file mode 100644 index 00000000..bdd08f95 --- /dev/null +++ b/.github/workflows/publish-dockerfile.yml @@ -0,0 +1,40 @@ +name: CI/CD +on: + push: + paths: + - docker + pull_request: + paths: + - docker + workflow_dispatch: + + +jobs: + build: + name: Build and publish container + runs-on: ubuntu-latest + env: + IMAGE_NAME: cpp + VERSION: 0.1.0 + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.PAT }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + push: ${{ github.ref == 'refs/heads/main' }} + tags: | + ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest + ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} From 9d670861557161a5c20cd8715fc81095786116cd Mon Sep 17 00:00:00 2001 From: David Dalcino Date: Sun, 3 Apr 2022 11:41:34 -0700 Subject: [PATCH 09/12] Fix name of CI action --- .github/workflows/publish-dockerfile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dockerfile.yml b/.github/workflows/publish-dockerfile.yml index bdd08f95..147b000e 100644 --- a/.github/workflows/publish-dockerfile.yml +++ b/.github/workflows/publish-dockerfile.yml @@ -1,4 +1,4 @@ -name: CI/CD +name: Build/Publish Dockerfile on: push: paths: From dc14794906bc2e7543bad1624c278f20485d799d Mon Sep 17 00:00:00 2001 From: Dave Dalcino Date: Sun, 3 Apr 2022 12:30:09 -0700 Subject: [PATCH 10/12] fix CI errors --- .github/workflows/publish-dockerfile.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-dockerfile.yml b/.github/workflows/publish-dockerfile.yml index 147b000e..a7476e36 100644 --- a/.github/workflows/publish-dockerfile.yml +++ b/.github/workflows/publish-dockerfile.yml @@ -2,9 +2,11 @@ name: Build/Publish Dockerfile on: push: paths: + - .github/workflows/publish-dockerfile.yml - docker pull_request: paths: + - .github/workflows/publish-dockerfile.yml - docker workflow_dispatch: @@ -33,7 +35,8 @@ jobs: - name: Build and push uses: docker/build-push-action@v2 with: - context: . + file: ./docker/Dockerfile + context: ./docker push: ${{ github.ref == 'refs/heads/main' }} tags: | ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest From b0a362e6caa5141269048b93863b79f6ee1617d9 Mon Sep 17 00:00:00 2001 From: David Dalcino Date: Mon, 4 Apr 2022 03:44:19 -0700 Subject: [PATCH 11/12] Apply suggestions from code review Co-authored-by: Iason Nikolas --- docker/print_versions.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/print_versions.sh b/docker/print_versions.sh index 089882a2..ca01f500 100644 --- a/docker/print_versions.sh +++ b/docker/print_versions.sh @@ -12,6 +12,7 @@ pip --version conan --version cmake --version ccmake --version +cmake-format --version cppcheck --version doxygen --version include-what-you-use --version From 5db36c9b7eacec58b7494f56b5cafdc5a5364940 Mon Sep 17 00:00:00 2001 From: David Dalcino Date: Mon, 4 Apr 2022 03:54:50 -0700 Subject: [PATCH 12/12] Apply suggestions from code review Co-authored-by: Iason Nikolas --- docker/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 984664ee..4aa7b60d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -25,6 +25,7 @@ ENV CONAN_SYSREQUIRES_SUDO 0 # a few dependencies. This flag allows Conan to proceed with these installations; # leaving this flag undefined can cause some installation failures. ENV CONAN_SYSREQUIRES_MODE enabled +ENV CONAN_REVISIONS_ENABLED 1 # User-settable versions: # This Dockerfile should support gcc-[7, 8, 9, 10, 11] and clang-[10, 11, 12, 13] @@ -40,7 +41,7 @@ RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \ RUN update-alternatives --install /usr/bin/gcc gcc $(which gcc-${GCC_VER}) 100 RUN update-alternatives --install /usr/bin/g++ g++ $(which g++-${GCC_VER}) 100 -ARG LLVM_VER="13" +ARG LLVM_VER="14" # Add clang-${LLVM_VER} ARG LLVM_URL="http://apt.llvm.org/${VARIANT}/" ARG LLVM_PKG="llvm-toolchain-${VARIANT}-${LLVM_VER}" @@ -62,7 +63,7 @@ RUN update-alternatives --install /usr/bin/clang clang $(which clang-${LLVM_VER} RUN update-alternatives --install /usr/bin/clang++ clang++ $(which clang++-${LLVM_VER}) 100 # Add current cmake/ccmake, from Kitware -ENV KEYRING_FILE="/usr/share/keyrings/kitware-archive-keyring.gpg" +ENV KEYRING_FILE "/usr/share/keyrings/kitware-archive-keyring.gpg" RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null \ | gpg --dearmor - | tee "${KEYRING_FILE}" >/dev/null && \ echo "deb [signed-by=${KEYRING_FILE}] https://apt.kitware.com/ubuntu/ ${VARIANT} main" \