Skip to content

Commit 0916e9c

Browse files
committed
Update CI configuration to use Docker
* switch to clang-20 Signed-off-by: drslebedev <[email protected]>
1 parent dee703a commit 0916e9c

File tree

6 files changed

+137
-54
lines changed

6 files changed

+137
-54
lines changed

.github/workflows/build_cmake.yml

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,44 @@ on:
88
types: [ created ]
99

1010
env:
11-
REFERENCE_CONFIG: 'Ubuntu gcc14' # configuration used for coverage etc
11+
REFERENCE_CONFIG: 'gcc14' # configuration used for coverage etc
1212

1313
jobs:
14+
buildKeycloakDockerImage:
15+
uses: ./.github/workflows/build_keycloak_docker.yml
16+
permissions:
17+
contents: read
18+
packages: write
19+
1420
build:
21+
needs: buildKeycloakDockerImage
1522
name: "${{ matrix.configurations.name }} | ${{ matrix.cmake-build-type }}"
1623
environment: configure coverage
17-
runs-on: ${{ matrix.configurations.os }}
24+
runs-on: "ubuntu-latest"
25+
container: "ghcr.io/fair-acc/gr4-build-container:latest"
1826
strategy:
1927
fail-fast: false
2028
matrix:
2129
configurations:
22-
- name: Ubuntu gcc14
23-
os: ubuntu-24.04
30+
- name: gcc14
2431
compiler: gcc14
25-
- name: Ubuntu clang18
26-
os: ubuntu-24.04
27-
compiler: clang18
28-
- name: ubuntu-22.04 emscripten
29-
os: ubuntu-24.04
32+
cc: gcc-14
33+
cxx: g++-14
34+
- name: clang20
35+
compiler: clang20
36+
cc: clang-20
37+
cxx: clang++-20
38+
- name: emscripten
3039
compiler: emscripten
31-
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
3240
cmake-build-type: [ Release, Debug ]
3341
env:
3442
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
43+
services:
44+
keycloak:
45+
image: ${{ needs.buildKeycloakDockerImage.outputs.image }}
46+
env:
47+
KEYCLOAK_ADMIN: admin
48+
KEYCLOAK_ADMIN_PASSWORD: admin
3549

3650
steps:
3751
- uses: actions/checkout@v6
@@ -46,56 +60,26 @@ jobs:
4660
path: ${{runner.workspace}}/build/_deps
4761
key: ${{ runner.os }}-${{ matrix.configurations.compiler }}-${{ matrix.cmake-build-type }}-${{ hashFiles('CMakeLists.txt') }}-${{ hashFiles('cmake/Dependencies.cmake') }}
4862

49-
- name: Install gcovr
50-
shell: bash
51-
if: matrix.configurations.name == env.REFERENCE_CONFIG && matrix.cmake-build-type == 'Debug'
52-
run: sudo apt-get install -y gcovr
53-
54-
- name: Install gcc-14
55-
if: matrix.configurations.compiler == 'gcc14'
56-
run: |
57-
sudo apt-get install -y gcc-14 g++-14
58-
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 110 --slave /usr/bin/g++ g++ /usr/bin/g++-14 --slave /usr/bin/gcov gcov /usr/bin/gcov-14
59-
60-
- name: Install clang-18
61-
if: matrix.configurations.compiler == 'clang18'
62-
run: |
63-
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
64-
sudo apt update
65-
sudo apt upgrade -y
66-
sudo apt install -y clang-18 libc++-18-dev libc++abi-18-dev
67-
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-18 110
68-
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-18 110
69-
70-
- name: Install emscripten
71-
if: matrix.configurations.compiler == 'emscripten'
72-
run: |
73-
cd
74-
git clone https://github.com/emscripten-core/emsdk.git
75-
cd emsdk
76-
# Download and install emscripten.
77-
./emsdk install 3.1.59
78-
# Make "active" for the current user. (writes .emscripten file)
79-
./emsdk activate 3.1.59
80-
8163
- name: Install sonar-scanner and build-wrapper
8264
if: matrix.configurations.name == env.REFERENCE_CONFIG && matrix.cmake-build-type == 'Debug'
8365
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v7
8466

8567
- name: Configure CMake
8668
if: matrix.configurations.compiler != 'emscripten'
87-
# Use a bash shell, so we can use the same syntax for environment variable access regardless of the host operating system
8869
shell: bash
70+
env:
71+
CC: "${{ matrix.configurations.cc }}"
72+
CXX: "${{ matrix.configurations.cxx }}"
73+
CMAKE_EXPORT_COMPILE_COMMANDS: "ON"
8974
run: cmake -S . -B ../build -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} -DOPENCMW_ENABLE_COVERAGE=${{ matrix.configurations.name == env.REFERENCE_CONFIG && matrix.cmake-build-type == 'Debug' }}
9075

9176
- name: Configure CMake Emscripten
9277
if: matrix.configurations.compiler == 'emscripten'
93-
# Use a bash shell, so we can use the same syntax for environment variable access regardless of the host operating system
9478
shell: bash
9579
run: |
9680
export SYSTEM_NODE=`which node` # use system node instead of old version distributed with emsdk for threading support
97-
source ~/emsdk/emsdk_env.sh
98-
emcmake cmake -S . -B ../build -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} -DENABLE_TESTING=ON -DCMAKE_CROSSCOMPILING_EMULATOR=${SYSTEM_NODE}
81+
source $EMSDK_HOME/emsdk_env.sh
82+
emcmake cmake -S . -B ../build -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} -DCMAKE_CROSSCOMPILING_EMULATOR=${SYSTEM_NODE}
9983
10084
- name: Build
10185
if: matrix.configurations.name != env.REFERENCE_CONFIG || matrix.cmake-build-type != 'Debug'
@@ -107,14 +91,27 @@ jobs:
10791
shell: bash
10892
run: build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build ../build --config ${{ matrix.cmake-build-type }}
10993

110-
- name: Run Keycloak Docker
94+
- name: Setup Keycloak
95+
if: matrix.configurations.compiler != 'emscripten'
11196
shell: bash
112-
run: docker run -p 8090:8080 -d -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:26.0.5 start-dev && src/client/test/setup-keycloak.sh
97+
env:
98+
KEYCLOAK_URL: http://keycloak:8080
99+
KEYCLOAK_REDIRECT_URI: http://localhost:8091
100+
KEYCLOAK_ADMIN_PASSWORD: admin
101+
run: |
102+
if ! command -v jq >/dev/null 2>&1; then
103+
sudo apt-get update
104+
sudo apt-get install -y --no-install-recommends jq
105+
fi
106+
src/client/test/setup-keycloak.sh
113107
114108
- name: Run tests
115109
if: matrix.configurations.name != env.REFERENCE_CONFIG || matrix.cmake-build-type != 'Debug'
116110
working-directory: ${{runner.workspace}}/build
117111
shell: bash
112+
env:
113+
KEYCLOAK_URL: http://keycloak:8080
114+
KEYCLOAK_REDIRECT_URI: http://localhost:8091
118115
# Execute tests defined by the CMake configuration. The coverage target runs the autodiscovered catch2 tests using
119116
# ctest and records the coverage using gcov
120117
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
@@ -124,6 +121,9 @@ jobs:
124121
if: matrix.configurations.name == env.REFERENCE_CONFIG && matrix.cmake-build-type == 'Debug'
125122
working-directory: ${{runner.workspace}}/build
126123
shell: bash
124+
env:
125+
KEYCLOAK_URL: http://keycloak:8080
126+
KEYCLOAK_REDIRECT_URI: http://localhost:8091
127127
# Execute tests defined by the CMake configuration. The coverage target runs the autodiscovered catch2 tests using
128128
# ctest and records the coverage using gcov
129129
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This workflow builds and publishes a tiny Keycloak “wrapper” image that defaults to `kc.sh start-dev`.
2+
# GitHub Actions service containers cannot pass command arguments (like `start-dev`) to the upstream Keycloak image.
3+
# The image is rebuilt/pushed only when `docker/keycloak/Dockerfile` changes, otherwise CI reuses the existing tag.
4+
5+
name: Build Keycloak Docker Image
6+
7+
on:
8+
workflow_call:
9+
outputs:
10+
image:
11+
description: "Keycloak wrapper image tag"
12+
value: ${{ jobs.build.outputs.image }}
13+
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
image: ${{ steps.docker-label.outputs.label }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Check if Keycloak Dockerfile was modified
29+
id: changes
30+
uses: dorny/paths-filter@v3
31+
with:
32+
filters: |
33+
docker:
34+
- 'docker/keycloak/Dockerfile'
35+
36+
- name: Set up Docker Label
37+
id: docker-label
38+
shell: bash
39+
run: |
40+
if [ ${{ steps.changes.outputs.docker == 'true' && github.event_name != 'push' }} = "true" ]; then
41+
echo "label=ghcr.io/fair-acc/keycloak-start-dev:${GITHUB_HEAD_REF/\//-}" >> "$GITHUB_OUTPUT"
42+
else
43+
echo "label=ghcr.io/fair-acc/keycloak-start-dev:latest" >> "$GITHUB_OUTPUT"
44+
fi
45+
46+
- name: Set up Docker Buildx
47+
if: steps.changes.outputs.docker == 'true'
48+
uses: docker/setup-buildx-action@v3
49+
50+
- name: Login to GHCR
51+
if: steps.changes.outputs.docker == 'true'
52+
uses: docker/login-action@v3
53+
with:
54+
registry: ghcr.io
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
58+
- name: Build & push Keycloak wrapper image
59+
if: steps.changes.outputs.docker == 'true'
60+
uses: docker/build-push-action@v5
61+
with:
62+
context: "{{defaultContext}}:docker/keycloak"
63+
push: true
64+
tags: ${{ steps.docker-label.outputs.label }}

docker/keycloak/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM quay.io/keycloak/keycloak:26.0.5
2+
CMD ["start-dev"]

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ sonar.organization=fair-acc
1313

1414
# exclude benchmark which crashes the Analysis
1515
# sonar.exclusions=bench/bm_case1.cpp
16-
sonar.coverageReportPaths=/home/runner/work/opencmw-cpp/build/coverage_sonarcube.xml
16+
sonar.cfamily.gcovr.reportPaths=/home/runner/work/opencmw-cpp/build/coverage_sonarcube.xml

src/client/test/setup-keycloak.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#
77
# For more information see: https://www.keycloak.org/getting-started/getting-started-docker
88

9-
URL="http://localhost:8090"
10-
REDIRECT_URI="http://localhost:8091"
11-
ADMIN_PASSWORD="admin"
9+
URL="${KEYCLOAK_URL:-http://localhost:8090}"
10+
REDIRECT_URI="${KEYCLOAK_REDIRECT_URI:-http://localhost:8091}"
11+
ADMIN_PASSWORD="${KEYCLOAK_ADMIN_PASSWORD:-admin}"
1212

13-
while ! curl -s "$URL"; do
13+
while ! curl -s "$URL" >/dev/null; do
1414
echo "Waiting for $URL to be reachable..."
1515
sleep 1
1616
done

src/services/test/OAuthClient_tests.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,24 @@ bool loginAtUri(const opencmw::URI<opencmw::STRICT> &uri) {
9090

9191
TEST_CASE("Worker test", "[OAuth]") {
9292
opencmw::majordomo::Broker<> broker{ "/Broker", {} };
93-
opencmw::OAuthWorker oauthWorker{ opencmw::URI("http://localhost:8091"), opencmw::URI("http://localhost:8090/realms/testrealm/protocol/openid-connect/auth"), opencmw::URI("http://localhost:8090/realms/testrealm/protocol/openid-connect/token"), broker };
93+
94+
auto envOr = [](std::string_view name, std::string_view fallback) -> std::string {
95+
std::string key{name}; // ensures null-terminated
96+
if (const char* v = std::getenv(key.c_str()); v && *v) {
97+
return std::string(v);
98+
}
99+
return std::string(fallback);
100+
};
101+
102+
const std::string kcBase = envOr("KEYCLOAK_URL", "http://localhost:8090");
103+
const std::string redirectBase = envOr("KEYCLOAK_REDIRECT_URI", "http://localhost:8091");
104+
105+
opencmw::OAuthWorker oauthWorker{
106+
opencmw::URI(redirectBase),
107+
opencmw::URI(kcBase + "/realms/testrealm/protocol/openid-connect/auth"),
108+
opencmw::URI(kcBase + "/realms/testrealm/protocol/openid-connect/token"),
109+
broker
110+
};
94111

95112
REQUIRE(broker.bind(opencmw::URI<>("mds://127.0.0.1:12345")));
96113
REQUIRE(broker.bind(opencmw::URI<>("mdp://127.0.0.1:12346")));

0 commit comments

Comments
 (0)