diff --git a/.github/workflows/build_devcontainer.yml b/.github/workflows/build_devcontainer.yml index 5de39eda..1f26fc7f 100644 --- a/.github/workflows/build_devcontainer.yml +++ b/.github/workflows/build_devcontainer.yml @@ -1,44 +1,80 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -name: Publish Beman devcontainers +name: Publish Beman Containers on: push: paths: - ".github/workflows/build_devcontainer.yml" - - "devcontainer/**" + - "containers/**" workflow_dispatch: env: REGISTRY: ghcr.io - DEBUG_IMAGE_NAME: ${{ github.repository }} - DEPLOY_IMAGE_NAME: bemanproject/devcontainers + DEBUG_NAME: ${{ github.repository }} + DEPLOY_DEV_NAME_PREFIX: bemanproject/devcontainers + DEPLOY_TESTING_NAME_PREFIX: bemanproject/testingcontainers + BASE_IMAGE_DEV: mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04 + BASE_IMAGE_TEST: ubuntu:24.04 permissions: packages: write jobs: - build-and-push-devcontainer-image: + containers: runs-on: ubuntu-latest strategy: fail-fast: false matrix: - include: - - kind: gnu + compilers: + - kind: gcc version: 14 - - kind: llvm + - kind: gcc + version: 13 + - kind: gcc + version: 12 + - kind: gcc + version: 11 + - kind: clang + version: 21 + - kind: clang + version: 20 + - kind: clang version: 19 - name: "devcontainer: ${{ matrix.kind }}-${{ matrix.version }}" + - kind: clang + version: 18 + - kind: clang + version: 17 + usage: [dev, test] + name: "${{ matrix.usage }}: ${{ matrix.compilers.kind }}-${{ matrix.compilers.version }}" steps: - name: Compute Image Name id: image_name run: | - image_name=${{ env.DEPLOY_IMAGE_NAME }} if [ "${{ github.repository }}/${{ github.ref }}" != "bemanproject/infra/refs/heads/main" ]; then - image_name=${{ env.DEBUG_IMAGE_NAME }} + image_name="${{ env.DEBUG_NAME }}" + tag="${{ matrix.usage }}-${{ matrix.compilers.kind }}-${{ matrix.compilers.version }}" + else + if [ "${{ matrix.usage }}" = "dev" ]; then + image_name="${{ env.DEPLOY_DEV_NAME_PREFIX }}-${{ matrix.compilers.kind }}" + else + image_name="${{ env.DEPLOY_TESTING_NAME_PREFIX }}-${{ matrix.compilers.kind }}" + fi + tag="${{ matrix.compilers.version }}" fi - echo "computed image name: $image_name" + + echo "Image Name: $image_name, Tag: $tag" + echo "image_name=$image_name" >> "$GITHUB_OUTPUT" + echo "tag=$tag" >> "$GITHUB_OUTPUT" + - name: Compute Image base + id: image_base + run: | + if [ "${{ matrix.usage }}" == "dev" ]; then + echo "image=${{ env.BASE_IMAGE_DEV }}" >> "$GITHUB_OUTPUT" + else + echo "image=${{ env.BASE_IMAGE_TEST }}" >> "$GITHUB_OUTPUT" + fi - name: Checkout repository uses: actions/checkout@v4 - name: Log in to the Container registry @@ -50,11 +86,12 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v6 with: - context: devcontainer + context: containers build-args: | - compiler_kind=${{ matrix.kind }} - compiler_version=${{ matrix.version }} + base_image=${{ steps.image_base.outputs.image }} + compiler_kind=${{ matrix.compilers.kind }} + compiler_version=${{ matrix.compilers.version }} push: true - tags: ${{ env.REGISTRY }}/${{ steps.image_name.outputs.image_name }}:${{ matrix.kind }}-${{ matrix.version }} + tags: ${{ env.REGISTRY }}/${{ steps.image_name.outputs.image_name }}:${{ steps.image_name.outputs.tag }} # https://github.com/docker/build-push-action/issues/894 provenance: false diff --git a/containers/Dockerfile b/containers/Dockerfile new file mode 100644 index 00000000..f5f5f9d0 --- /dev/null +++ b/containers/Dockerfile @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +ARG base_image=mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04 +FROM ${base_image} + +# Create the vscode user +RUN bash </dev/null; then + apt-get update && apt-get install -y sudo adduser + useradd -ms /bin/bash -p "" vscode && usermod -aG sudo vscode + fi +EOF + +USER vscode +WORKDIR /tmp + +COPY install_sys.sh . +RUN bash install_sys.sh + +# Newer gcc/ clang is needed to avoid ASAN Stalling, which is turned on by default across beman projects. +# See: https://github.com/google/sanitizers/issues/1614 +# Minimal version: clang-18.1.3, gcc-13.2 +ARG compiler_kind=gcc +ARG compiler_version=14 + +COPY install_compiler.sh . +RUN bash install_compiler.sh ${compiler_kind} ${compiler_version} + +# Common dependency: google-test +RUN sudo apt-get install -y libgtest-dev + +# Pre-commit is beman library's standard linting tool +RUN sudo apt-get install -y pipx +RUN pipx install pre-commit +ENV PATH="/home/vscode/.local/bin:${PATH}" + +ENTRYPOINT ["/usr/bin/bash"] diff --git a/devcontainer/README.md b/containers/README.md similarity index 71% rename from devcontainer/README.md rename to containers/README.md index d6e632f3..d85f6ec8 100644 --- a/devcontainer/README.md +++ b/containers/README.md @@ -1,28 +1,31 @@ -# Devcontainer +# Containers This folder contains the infrastructure for Beman project's -generic devcontainer image. You can checkout available images in beman's -[GitHub Packages page](https://github.com/orgs/bemanproject/packages/container/package/devcontainers). +generic container images. You can checkout available images in beman's +[GitHub Packages page](https://github.com/orgs/bemanproject/packages). -The image is build on top of GitHub's -[C++ devcontainer image](https://github.com/devcontainers/images/tree/main/src/cpp) -for Ubuntu 24.04. - -The image includes: +These images includes: - The latest CMake from kitware's apt repository -- Latest compiler based on build args (gnu or llvm) installed from the universe repository +- Latest compiler based on build args (gcc or clang) installed from the universe repository - [pre-commit](https://pre-commit.com/), the standard linter manager across Beman -## Example devcontainer setup + +## Devcontainer + +The image is build on top of GitHub's +[C++ devcontainer image](https://github.com/devcontainers/images/tree/main/src/cpp) +for Ubuntu 24.04. + +### Example devcontainer setup ```json // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception { "name": "Beman Generic Devcontainer", - "image": "ghcr.io/bemanproject/devcontainers:gnu-14", + "image": "ghcr.io/bemanproject/devcontainers-gcc:14", "postCreateCommand": "pre-commit", "customizations": { "vscode": { @@ -35,7 +38,7 @@ The image includes: } ``` -## Building your own image +### Building your own image You can build your own Beman devcontainer image with: diff --git a/devcontainer/install_compiler.sh b/containers/install_compiler.sh similarity index 77% rename from devcontainer/install_compiler.sh rename to containers/install_compiler.sh index ec53dec6..d2f96cca 100644 --- a/devcontainer/install_compiler.sh +++ b/containers/install_compiler.sh @@ -9,15 +9,17 @@ VERSION=$2 echo "Install ${TOOL} at: ${VERSION}" shopt -s nocasematch -if [ "$TOOL" = "gnu" ]; then +if [ "$TOOL" = "gcc" ]; then sudo apt-get remove -y gcc-"$VERSION" g++-"$VERSION" gcc g++ - sudo apt-get install -y gcc-"$VERSION" g++-"$VERSION" + sudo apt-get install -y gcc-"$VERSION" g++-"$VERSION" lcov sudo rm -f /usr/bin/gcc sudo rm -f /usr/bin/g++ + sudo rm -f /usr/bin/gcov sudo ln -s "$(which gcc-"$VERSION")" /usr/bin/gcc sudo ln -s "$(which g++-"$VERSION")" /usr/bin/g++ + sudo ln -s "$(which gcov-"$VERSION")" /usr/bin/gcov gcc --version else @@ -25,6 +27,7 @@ else wget https://apt.llvm.org/llvm.sh sudo bash llvm.sh "${VERSION}" + sudo apt-get install -y libc++-"$VERSION"-dev lcov sudo rm -f /usr/bin/clang sudo rm -f /usr/bin/clang++ @@ -34,3 +37,4 @@ else clang --version fi + diff --git a/containers/install_sys.sh b/containers/install_sys.sh new file mode 100644 index 00000000..272ab7bf --- /dev/null +++ b/containers/install_sys.sh @@ -0,0 +1,10 @@ +# Install Basic utilities +sudo apt-get install -y ca-certificates gpg wget git curl + +# Install Latest CMake +wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null +echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null +sudo apt-get update && sudo apt-get install -y cmake + +# Install Ninja +sudo apt-get install -y ninja-build \ No newline at end of file diff --git a/devcontainer/Dockerfile b/devcontainer/Dockerfile deleted file mode 100644 index 313e1297..00000000 --- a/devcontainer/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04 - -USER vscode -WORKDIR /tmp - -# Latest CMake needed for most of the beman libraries, -# so we need to install via kitware's apt repo -RUN bash </dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null - echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null - sudo apt-get update && sudo apt-get install -y cmake -EOF - -# Newer gcc/ llvm is needed to avoid ASAN Stalling, which is turned on by default across beman projects. -# See: https://github.com/google/sanitizers/issues/1614 -# Minimal version: clang-18.1.3, gcc-13.2 -ARG compiler_kind=gnu -ARG compiler_version=14 - -COPY install_compiler.sh . -RUN bash install_compiler.sh ${compiler_kind} ${compiler_version} - -# Needed for recent exemplar -RUN sudo apt-get install -y libgtest-dev - -# Pre-commit is beman library's standard linting tool -RUN sudo apt-get install -y pipx -RUN pipx install pre-commit -ENV PATH="/home/vscode/.local/bin:${PATH}" - -ENTRYPOINT ["/usr/bin/bash"]