Skip to content

Commit 3bf124b

Browse files
committed
Add C++ profile to Docker Compose and Updatecli
Fixes #376 Add a new profile in the Docker Compose file for building C++ source code with Jenkins. * **Docker Compose Files:** * Add a `cpp` profile in `docker-compose.yaml` and `build-docker-compose.yaml`. * Include necessary service definitions, dependencies, healthcheck, and volume configurations. * **Dockerfile:** * Create `dockerfiles/cpp/Dockerfile` with necessary C++ build tools including `build-essential`, `cmake`, `gcc`, `g++`, `clang`, `make`, `libstdc++-dev`, and `pkg-config`. * Set environment variables and ensure ownership of the Jenkins agent home directory. * **Updatecli Manifest:** * Add `updatecli/updatecli.d/cpp.yaml` for managing the C++ Dockerfile. * Ensure the manifest includes the necessary dependencies for the C++ build environment. * **GitHub Actions:** * Modify `.github/workflows/github-docker-registry-push.yml` to add a new job for building and pushing the C++ Docker image to ghcr. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/gounthar/quickstart-tutorials/issues/376?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 15cfa65 commit 3bf124b

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

.github/workflows/github-docker-registry-push.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,13 @@ jobs:
204204
platforms: linux/amd64, linux/arm64
205205
push: true
206206
tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:golang_${{ env.BRANCH }}
207+
208+
- name: Build and push the jenkins agent for cpp tutorial
209+
# This step builds and pushes the Jenkins agent for the C++ tutorial
210+
if: contains(env.files, 'dockerfiles/cpp/Dockerfile')
211+
uses: docker/build-push-action@v6
212+
with:
213+
context: ./dockerfiles/cpp
214+
platforms: linux/amd64, linux/aarch64
215+
push: true
216+
tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:cpp_agent_${{ env.BRANCH }}

build-docker-compose.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,23 @@ services:
205205
retries: 5
206206
volumes:
207207
- agent-ssh-dir:/home/jenkins/.ssh:ro # Mounts the agent-ssh-dir volume to the /home/jenkins/.ssh path inside the container as read-only
208+
cpp:
209+
build: dockerfiles/cpp/.
210+
container_name: desktop-jenkins_agent-1-cpp
211+
profiles:
212+
- cpp
213+
depends_on:
214+
sidekick_service:
215+
condition: service_completed_successfully
216+
jenkins_controller:
217+
condition: service_started
218+
healthcheck:
219+
test: ["CMD-SHELL", "[ -f /home/jenkins/.ssh/authorized_keys ] || exit 1"]
220+
interval: 5s
221+
timeout: 10s
222+
retries: 5
223+
volumes:
224+
- agent-ssh-dir:/home/jenkins/.ssh:ro
208225
volumes:
209226
jenkins_home: null
210227
agent-ssh-dir:

docker-compose.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,23 @@ services:
281281
retries: 5
282282
volumes:
283283
- agent-ssh-dir:/home/jenkins/.ssh:ro # Mounts the agent-ssh-dir volume to the /home/jenkins/.ssh path inside the container as read-only
284+
cpp:
285+
image: ${IMAGE_PREFIX}/${GHCR_USERNAME}/quickstart-tutorials/jenkinsci-tutorials:cpp_agent_${BRANCH_SUFFIX}
286+
container_name: desktop-jenkins_agent-1-cpp
287+
profiles:
288+
- cpp
289+
depends_on:
290+
sidekick_service:
291+
condition: service_completed_successfully
292+
jenkins_controller:
293+
condition: service_started
294+
healthcheck:
295+
test: ["CMD-SHELL", "[ -f /home/jenkins/.ssh/authorized_keys ] || exit 1"]
296+
interval: 5s
297+
timeout: 10s
298+
retries: 5
299+
volumes:
300+
- agent-ssh-dir:/home/jenkins/.ssh:ro
284301
volumes:
285302
jenkins_home: null
286303
empty_jenkins_home: null

dockerfiles/cpp/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM jenkins/ssh-agent:6.9.0
2+
3+
# Install necessary C++ build tools
4+
RUN apt-get update && apt-get install -y --no-install-recommends \
5+
build-essential \
6+
cmake \
7+
gcc \
8+
g++ \
9+
clang \
10+
make \
11+
libstdc++-dev \
12+
pkg-config \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Set environment variables
16+
ENV PATH="/usr/local/bin:$PATH"
17+
18+
# Ensure the ownership of the Jenkins agent home directory is set to the Jenkins user
19+
RUN chown -R jenkins:jenkins "${JENKINS_AGENT_HOME}"

updatecli/updatecli.d/cpp.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: "deps: update C++ build environment"
2+
3+
scms:
4+
default:
5+
kind: github
6+
spec:
7+
user: "{{ .github.user }}"
8+
email: "{{ .github.email }}"
9+
owner: "{{ .github.owner }}"
10+
repository: "{{ .github.repository }}"
11+
token: "{{ requiredEnv .github.token }}"
12+
username: "{{ .github.username }}"
13+
branch: "{{ .github.branch }}"
14+
15+
sources:
16+
cpp:
17+
name: Get latest C++ build environment dependencies
18+
kind: shell
19+
spec:
20+
command: echo "build-essential cmake gcc g++ clang make libstdc++-dev pkg-config"
21+
22+
targets:
23+
cpp:
24+
name: 'deps(dockerfile): update C++ build environment dependencies'
25+
scmid: default
26+
kind: dockerfile
27+
spec:
28+
file: dockerfiles/cpp/Dockerfile
29+
instruction:
30+
keyword: RUN
31+
matcher: apt-get install -y --no-install-recommends
32+
sourceid: cpp
33+
34+
actions:
35+
default:
36+
kind: github/pullrequest
37+
scmid: default
38+
title: Update C++ build environment dependencies to {{ source "cpp" }}
39+
spec:
40+
labels:
41+
- dependencies
42+
- cpp

0 commit comments

Comments
 (0)