diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index e948180e..b048ec97 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,120 +1,4 @@ -# [Choice] bionic (18.04), focal (20.04) -ARG VARIANT="focal" -FROM ubuntu:${VARIANT} +# FROM ghcr.io/cpp_best_practices/cpp:0.1.0 # TODO: activate +FROM ghcr.io/ddalcino/cpp:0.1.0 -# Restate the variant to use it later on in the llvm and cmake installations -ARG VARIANT - -# Install necessary packages available from standard repos -RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ - apt-get install -y --no-install-recommends \ - software-properties-common wget apt-utils file zip \ - openssh-client gpg-agent socat rsync \ - make ninja-build git \ - python3 python3-pip - -# Install conan -RUN python3 -m pip install --upgrade pip setuptools && \ - python3 -m pip install conan && \ - conan --version - -# By default, anything you run in Docker is done as superuser. -# Conan runs some install commands as superuser, and will prepend `sudo` to -# these commands, unless `CONAN_SYSREQUIRES_SUDO=0` is in your env variables. -ENV CONAN_SYSREQUIRES_SUDO 0 -# Some packages request that Conan use the system package manager to install -# 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 - -# User-settable versions: -# This Dockerfile should support gcc-[7, 8, 9, 10, 11] and clang-[10, 11, 12, 13] -# Earlier versions of clang will require significant modifications to the IWYU section -ARG GCC_VER="11" -# Add gcc-${GCC_VER} -RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \ - apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ - apt-get install -y --no-install-recommends \ - gcc-${GCC_VER} g++-${GCC_VER} gdb - -# Set gcc-${GCC_VER} as default gcc -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" -# Add clang-${LLVM_VER} -ARG LLVM_URL="http://apt.llvm.org/${VARIANT}/" -ARG LLVM_PKG="llvm-toolchain-${VARIANT}-${LLVM_VER}" -RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - 2>/dev/null && \ - add-apt-repository -y "deb ${LLVM_URL} ${LLVM_PKG} main" && \ - 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} - -# 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 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 - -# Add current cmake/ccmake, from Kitware -ARG CMAKE_URL="https://apt.kitware.com/ubuntu/" -ARG CMAKE_PKG=${VARIANT} -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 && \ - 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 \ - doxygen graphviz ccache cppcheck - -# Install include-what-you-use -ENV IWYU /home/iwyu -ENV IWYU_BUILD ${IWYU}/build -ENV IWYU_SRC ${IWYU}/include-what-you-use -RUN mkdir -p ${IWYU_BUILD} && \ - git clone --branch clang_${LLVM_VER} \ - https://github.com/include-what-you-use/include-what-you-use.git \ - ${IWYU_SRC} -RUN CC=clang-${LLVM_VER} CXX=clang++-${LLVM_VER} cmake -S ${IWYU_SRC} \ - -B ${IWYU_BUILD} \ - -G "Unix Makefiles" -DCMAKE_PREFIX_PATH=/usr/lib/llvm-${LLVM_VER} && \ - cmake --build ${IWYU_BUILD} -j && \ - cmake --install ${IWYU_BUILD} - -# Per https://github.com/include-what-you-use/include-what-you-use#how-to-install: -# `You need to copy the Clang include directory to the expected location before -# running (similarly, use include-what-you-use -print-resource-dir to learn -# exactly where IWYU wants the headers).` -RUN mkdir -p $(include-what-you-use -print-resource-dir 2>/dev/null) -RUN ln -s $(readlink -f /usr/lib/clang/${LLVM_VER}/include) \ - $(include-what-you-use -print-resource-dir 2>/dev/null)/include - -## Cleanup cached apt data we don't need anymore -RUN apt-get autoremove -y && apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# Allow the user to set compiler defaults -ARG USE_CLANG -# if --build-arg USE_CLANG=1, set CC to 'clang' or set to null otherwise. -ENV CC=${USE_CLANG:+"clang"} -ENV CXX=${USE_CLANG:+"clang++"} -# if CC is null, set it to 'gcc' (or leave as is otherwise). -ENV CC=${CC:-"gcc"} -ENV CXX=${CXX:-"g++"} - -# Include project -#ADD . /workspaces/cpp_starter_project -#WORKDIR /workspaces/cpp_starter_project - -CMD ["/bin/bash"] +# Add your own modifications to the Docker environment here diff --git a/.github/workflows/publish-dockerfile.yml b/.github/workflows/publish-dockerfile.yml new file mode 100644 index 00000000..a7476e36 --- /dev/null +++ b/.github/workflows/publish-dockerfile.yml @@ -0,0 +1,43 @@ +name: Build/Publish Dockerfile +on: + push: + paths: + - .github/workflows/publish-dockerfile.yml + - docker + pull_request: + paths: + - .github/workflows/publish-dockerfile.yml + - 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: + file: ./docker/Dockerfile + context: ./docker + 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 }} diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..4aa7b60d --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,121 @@ +# [Choice] bionic (18.04), focal (20.04) +ARG VARIANT="focal" +FROM ubuntu:${VARIANT} + +# Restate the variant to use it later on in the llvm and cmake installations +ARG VARIANT + +# Install necessary packages available from standard repos +RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ + apt-get install -y --no-install-recommends \ + software-properties-common wget apt-utils file zip \ + openssh-client gpg-agent socat rsync \ + make ninja-build git \ + python3 python3-pip + +# Install conan and cmake format +RUN python3 -m pip install --upgrade pip setuptools && \ + 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 +# these commands, unless `CONAN_SYSREQUIRES_SUDO=0` is in your env variables. +ENV CONAN_SYSREQUIRES_SUDO 0 +# Some packages request that Conan use the system package manager to install +# 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] +# Earlier versions of clang will require significant modifications to the IWYU section +ARG GCC_VER="11" +# Add gcc-${GCC_VER} +RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \ + apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ + apt-get install -y --no-install-recommends \ + gcc-${GCC_VER} g++-${GCC_VER} gdb + +# Set gcc-${GCC_VER} as default gcc +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="14" +# Add clang-${LLVM_VER} +ARG LLVM_URL="http://apt.llvm.org/${VARIANT}/" +ARG LLVM_PKG="llvm-toolchain-${VARIANT}-${LLVM_VER}" +RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - 2>/dev/null && \ + add-apt-repository -y "deb ${LLVM_URL} ${LLVM_PKG} main" && \ + 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} 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 + +# Add current cmake/ccmake, from Kitware +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" \ + | 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 optional dependecies +RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && \ + apt-get install -y --no-install-recommends \ + doxygen graphviz ccache cppcheck + +# Install include-what-you-use +ENV IWYU /home/iwyu +ENV IWYU_BUILD ${IWYU}/build +ENV IWYU_SRC ${IWYU}/include-what-you-use +RUN mkdir -p ${IWYU_BUILD} && \ + git clone --branch clang_${LLVM_VER} \ + https://github.com/include-what-you-use/include-what-you-use.git \ + ${IWYU_SRC} +RUN CC=clang-${LLVM_VER} CXX=clang++-${LLVM_VER} cmake -S ${IWYU_SRC} \ + -B ${IWYU_BUILD} \ + -G "Unix Makefiles" -DCMAKE_PREFIX_PATH=/usr/lib/llvm-${LLVM_VER} && \ + cmake --build ${IWYU_BUILD} -j && \ + cmake --install ${IWYU_BUILD} + +# Per https://github.com/include-what-you-use/include-what-you-use#how-to-install: +# `You need to copy the Clang include directory to the expected location before +# running (similarly, use include-what-you-use -print-resource-dir to learn +# exactly where IWYU wants the headers).` +RUN mkdir -p $(include-what-you-use -print-resource-dir 2>/dev/null) +RUN ln -s $(readlink -f /usr/lib/clang/${LLVM_VER}/include) \ + $(include-what-you-use -print-resource-dir 2>/dev/null)/include + +## Cleanup cached apt data we don't need anymore +RUN apt-get autoremove -y && apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Allow the user to set compiler defaults +ARG USE_CLANG +# if --build-arg USE_CLANG=1, set CC to 'clang' or set to null otherwise. +ENV CC=${USE_CLANG:+"clang"} +ENV CXX=${USE_CLANG:+"clang++"} +# if CC is null, set it to 'gcc' (or leave as is otherwise). +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 + +CMD ["/bin/bash"] diff --git a/docker/print_versions.sh b/docker/print_versions.sh new file mode 100644 index 00000000..ca01f500 --- /dev/null +++ b/docker/print_versions.sh @@ -0,0 +1,20 @@ +#!/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 +cmake-format --version +cppcheck --version +doxygen --version +include-what-you-use --version +cmake-format --version +