Skip to content

Commit a68dbe2

Browse files
authored
Merge pull request #11 from bemanproject/test-container-ext
Introduce test containers
2 parents 9b88395 + 9532de6 commit a68dbe2

File tree

6 files changed

+121
-63
lines changed

6 files changed

+121
-63
lines changed
Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,80 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
name: Publish Beman devcontainers
3+
name: Publish Beman Containers
44

55
on:
66
push:
77
paths:
88
- ".github/workflows/build_devcontainer.yml"
9-
- "devcontainer/**"
9+
- "containers/**"
1010
workflow_dispatch:
1111

1212
env:
1313
REGISTRY: ghcr.io
14-
DEBUG_IMAGE_NAME: ${{ github.repository }}
15-
DEPLOY_IMAGE_NAME: bemanproject/devcontainers
14+
DEBUG_NAME: ${{ github.repository }}
15+
DEPLOY_DEV_NAME_PREFIX: bemanproject/devcontainers
16+
DEPLOY_TESTING_NAME_PREFIX: bemanproject/testingcontainers
17+
BASE_IMAGE_DEV: mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04
18+
BASE_IMAGE_TEST: ubuntu:24.04
1619

1720
permissions:
1821
packages: write
1922

2023
jobs:
21-
build-and-push-devcontainer-image:
24+
containers:
2225
runs-on: ubuntu-latest
2326
strategy:
2427
fail-fast: false
2528
matrix:
26-
include:
27-
- kind: gnu
29+
compilers:
30+
- kind: gcc
2831
version: 14
29-
- kind: llvm
32+
- kind: gcc
33+
version: 13
34+
- kind: gcc
35+
version: 12
36+
- kind: gcc
37+
version: 11
38+
- kind: clang
39+
version: 21
40+
- kind: clang
41+
version: 20
42+
- kind: clang
3043
version: 19
31-
name: "devcontainer: ${{ matrix.kind }}-${{ matrix.version }}"
44+
- kind: clang
45+
version: 18
46+
- kind: clang
47+
version: 17
48+
usage: [dev, test]
49+
name: "${{ matrix.usage }}: ${{ matrix.compilers.kind }}-${{ matrix.compilers.version }}"
3250
steps:
3351
- name: Compute Image Name
3452
id: image_name
3553
run: |
36-
image_name=${{ env.DEPLOY_IMAGE_NAME }}
3754
if [ "${{ github.repository }}/${{ github.ref }}" != "bemanproject/infra/refs/heads/main" ]; then
38-
image_name=${{ env.DEBUG_IMAGE_NAME }}
55+
image_name="${{ env.DEBUG_NAME }}"
56+
tag="${{ matrix.usage }}-${{ matrix.compilers.kind }}-${{ matrix.compilers.version }}"
57+
else
58+
if [ "${{ matrix.usage }}" = "dev" ]; then
59+
image_name="${{ env.DEPLOY_DEV_NAME_PREFIX }}-${{ matrix.compilers.kind }}"
60+
else
61+
image_name="${{ env.DEPLOY_TESTING_NAME_PREFIX }}-${{ matrix.compilers.kind }}"
62+
fi
63+
tag="${{ matrix.compilers.version }}"
3964
fi
40-
echo "computed image name: $image_name"
65+
66+
echo "Image Name: $image_name, Tag: $tag"
67+
4168
echo "image_name=$image_name" >> "$GITHUB_OUTPUT"
69+
echo "tag=$tag" >> "$GITHUB_OUTPUT"
70+
- name: Compute Image base
71+
id: image_base
72+
run: |
73+
if [ "${{ matrix.usage }}" == "dev" ]; then
74+
echo "image=${{ env.BASE_IMAGE_DEV }}" >> "$GITHUB_OUTPUT"
75+
else
76+
echo "image=${{ env.BASE_IMAGE_TEST }}" >> "$GITHUB_OUTPUT"
77+
fi
4278
- name: Checkout repository
4379
uses: actions/checkout@v4
4480
- name: Log in to the Container registry
@@ -50,11 +86,12 @@ jobs:
5086
- name: Build and push Docker image
5187
uses: docker/build-push-action@v6
5288
with:
53-
context: devcontainer
89+
context: containers
5490
build-args: |
55-
compiler_kind=${{ matrix.kind }}
56-
compiler_version=${{ matrix.version }}
91+
base_image=${{ steps.image_base.outputs.image }}
92+
compiler_kind=${{ matrix.compilers.kind }}
93+
compiler_version=${{ matrix.compilers.version }}
5794
push: true
58-
tags: ${{ env.REGISTRY }}/${{ steps.image_name.outputs.image_name }}:${{ matrix.kind }}-${{ matrix.version }}
95+
tags: ${{ env.REGISTRY }}/${{ steps.image_name.outputs.image_name }}:${{ steps.image_name.outputs.tag }}
5996
# https://github.com/docker/build-push-action/issues/894
6097
provenance: false

containers/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
3+
ARG base_image=mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04
4+
FROM ${base_image}
5+
6+
# Create the vscode user
7+
RUN bash <<EOF
8+
if ! id "vscode" &>/dev/null; then
9+
apt-get update && apt-get install -y sudo adduser
10+
useradd -ms /bin/bash -p "" vscode && usermod -aG sudo vscode
11+
fi
12+
EOF
13+
14+
USER vscode
15+
WORKDIR /tmp
16+
17+
COPY install_sys.sh .
18+
RUN bash install_sys.sh
19+
20+
# Newer gcc/ clang is needed to avoid ASAN Stalling, which is turned on by default across beman projects.
21+
# See: https://github.com/google/sanitizers/issues/1614
22+
# Minimal version: clang-18.1.3, gcc-13.2
23+
ARG compiler_kind=gcc
24+
ARG compiler_version=14
25+
26+
COPY install_compiler.sh .
27+
RUN bash install_compiler.sh ${compiler_kind} ${compiler_version}
28+
29+
# Common dependency: google-test
30+
RUN sudo apt-get install -y libgtest-dev
31+
32+
# Pre-commit is beman library's standard linting tool
33+
RUN sudo apt-get install -y pipx
34+
RUN pipx install pre-commit
35+
ENV PATH="/home/vscode/.local/bin:${PATH}"
36+
37+
ENTRYPOINT ["/usr/bin/bash"]
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
# Devcontainer
1+
# Containers
22

33
<!-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -->
44

55
This folder contains the infrastructure for Beman project's
6-
generic devcontainer image. You can checkout available images in beman's
7-
[GitHub Packages page](https://github.com/orgs/bemanproject/packages/container/package/devcontainers).
6+
generic container images. You can checkout available images in beman's
7+
[GitHub Packages page](https://github.com/orgs/bemanproject/packages).
88

9-
The image is build on top of GitHub's
10-
[C++ devcontainer image](https://github.com/devcontainers/images/tree/main/src/cpp)
11-
for Ubuntu 24.04.
12-
13-
The image includes:
9+
These images includes:
1410

1511
- The latest CMake from kitware's apt repository
16-
- Latest compiler based on build args (gnu or llvm) installed from the universe repository
12+
- Latest compiler based on build args (gcc or clang) installed from the universe repository
1713
- [pre-commit](https://pre-commit.com/), the standard linter manager across Beman
1814

19-
## Example devcontainer setup
15+
16+
## Devcontainer
17+
18+
The image is build on top of GitHub's
19+
[C++ devcontainer image](https://github.com/devcontainers/images/tree/main/src/cpp)
20+
for Ubuntu 24.04.
21+
22+
### Example devcontainer setup
2023

2124
```json
2225
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2326
{
2427
"name": "Beman Generic Devcontainer",
25-
"image": "ghcr.io/bemanproject/devcontainers:gnu-14",
28+
"image": "ghcr.io/bemanproject/devcontainers-gcc:14",
2629
"postCreateCommand": "pre-commit",
2730
"customizations": {
2831
"vscode": {
@@ -35,7 +38,7 @@ The image includes:
3538
}
3639
```
3740

38-
## Building your own image
41+
### Building your own image
3942

4043
You can build your own Beman devcontainer image with:
4144

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@ VERSION=$2
99
echo "Install ${TOOL} at: ${VERSION}"
1010

1111
shopt -s nocasematch
12-
if [ "$TOOL" = "gnu" ]; then
12+
if [ "$TOOL" = "gcc" ]; then
1313
sudo apt-get remove -y gcc-"$VERSION" g++-"$VERSION" gcc g++
14-
sudo apt-get install -y gcc-"$VERSION" g++-"$VERSION"
14+
sudo apt-get install -y gcc-"$VERSION" g++-"$VERSION" lcov
1515

1616
sudo rm -f /usr/bin/gcc
1717
sudo rm -f /usr/bin/g++
18+
sudo rm -f /usr/bin/gcov
1819

1920
sudo ln -s "$(which gcc-"$VERSION")" /usr/bin/gcc
2021
sudo ln -s "$(which g++-"$VERSION")" /usr/bin/g++
22+
sudo ln -s "$(which gcov-"$VERSION")" /usr/bin/gcov
2123

2224
gcc --version
2325
else
2426
sudo apt-get install -y lsb-release wget software-properties-common gnupg
2527
wget https://apt.llvm.org/llvm.sh
2628

2729
sudo bash llvm.sh "${VERSION}"
30+
sudo apt-get install -y libc++-"$VERSION"-dev lcov
2831

2932
sudo rm -f /usr/bin/clang
3033
sudo rm -f /usr/bin/clang++
@@ -34,3 +37,4 @@ else
3437

3538
clang --version
3639
fi
40+

containers/install_sys.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Install Basic utilities
2+
sudo apt-get install -y ca-certificates gpg wget git curl
3+
4+
# Install Latest CMake
5+
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
6+
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
7+
sudo apt-get update && sudo apt-get install -y cmake
8+
9+
# Install Ninja
10+
sudo apt-get install -y ninja-build

devcontainer/Dockerfile

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)