Skip to content

Commit f830835

Browse files
committed
plt-1858: update Jenkins images to support Java 17, add SDKMAN, and update agent configuration
1 parent a2c68f4 commit f830835

File tree

5 files changed

+115
-5
lines changed

5 files changed

+115
-5
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ jobs:
1313
matrix:
1414
remoting_tag:
1515
- 4.13.2-1-jdk11
16+
- 4.13.3-1-jdk17
1617
runs-on: ubuntu-latest
1718
steps:
1819
- name: Build and Push Docker Image
1920
uses: Dwolla/jenkins-agents-workflow/.github/actions/build@main
2021
with:
2122
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
2223
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
23-
BASE_TAG: ${{ matrix.REMOTING_TAG }}
24+
BASE_TAG: ${{ matrix.remoting_tag }}
2425
TAG_NAME: JENKINS_REMOTING_TAG
2526
IMAGE_NAME: dwolla/jenkins-agent-core
2627
build-complete:

Dockerfile

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ LABEL org.label-schema.vcs-url="https://github.com/Dwolla/jenkins-agent-docker-c
66
ENV JENKINS_HOME=/home/jenkins
77

88
COPY build/install-esh.sh /tmp/build/install-esh.sh
9+
COPY build/jenkins-agent-entrypoint.sh /usr/local/bin/jenkins-agent-entrypoint.sh
10+
COPY build/sdkman-init-wrapper.sh /usr/local/bin/sdkman-init-wrapper.sh
911

1012
WORKDIR ${JENKINS_HOME}
1113

1214
USER root
1315

1416
RUN set -ex && \
1517
apt-get update && \
16-
apt-get install -y \
18+
(apt-get install -y \
1719
asciidoctor \
1820
apt-transport-https \
1921
bash \
@@ -30,13 +32,31 @@ RUN set -ex && \
3032
python3-venv \
3133
shellcheck \
3234
zip \
33-
&& \
35+
|| (sleep 5 && apt-get update && apt-get install -y \
36+
asciidoctor \
37+
apt-transport-https \
38+
bash \
39+
bc \
40+
ca-certificates \
41+
curl \
42+
expect \
43+
git \
44+
gpg \
45+
jq \
46+
make \
47+
python3 \
48+
python3-pip \
49+
python3-venv \
50+
shellcheck \
51+
zip)) && \
3452
pip3 install --upgrade \
3553
awscli \
3654
virtualenv \
3755
&& \
3856
ln -s /usr/bin/python3 /usr/bin/python && \
3957
/tmp/build/install-esh.sh v0.3.2 && \
58+
chmod +x /usr/local/bin/jenkins-agent-entrypoint.sh && \
59+
chmod +x /usr/local/bin/sdkman-init-wrapper.sh && \
4060
rm -rf /tmp/build && \
4161
mkdir -p /usr/share/man/man1/ && \
4262
touch /usr/share/man/man1/sh.distrib.1.gz
@@ -53,4 +73,8 @@ RUN git config --global user.email "dev+jenkins@dwolla.com" && \
5373
git config --global 'credential.https://github.com.username' 'x-access-token' && \
5474
git config --global 'credential.https://github.com.helper' '!f() { if [ "$1" = get ]; then case "${GH_TOKEN-}" in (*[![:space:]]*) echo "password=${GH_TOKEN}";; (*) echo "error: GH_TOKEN is missing" >&2; exit 1;; esac; fi; }; f'
5575

56-
ENTRYPOINT ["jenkins-agent"]
76+
# Install SDKMAN
77+
RUN curl -s "https://get.sdkman.io" | bash && \
78+
bash -c "source $HOME/.sdkman/bin/sdkman-init.sh && sdk version"
79+
80+
ENTRYPOINT ["/usr/local/bin/jenkins-agent-entrypoint.sh"]

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@ JENKINS_REMOTING_TAG := 4.13.2-1-jdk11
22
JOB := remoting-${JENKINS_REMOTING_TAG}
33
CLEAN_JOB := clean-${CORE_TAG}
44

5+
# Default target builds Java 11 variant
6+
all: remoting-4.13.2-1-jdk11 remoting-4.13.3-1-jdk17
7+
58
clean: ${CLEAN_JOB}
6-
.PHONY: all clean ${JOB} ${CLEAN_JOB}
9+
.PHONY: all clean ${JOB} ${CLEAN_JOB} remoting-4.13.2-1-jdk11 remoting-4.13.3-1-jdk17
710

811
${JOB}: remoting-%: Dockerfile
912
docker build \
1013
--build-arg JENKINS_REMOTING_TAG=$* \
1114
--tag dwolla/jenkins-agent-core:$*-SNAPSHOT \
1215
.
1316

17+
remoting-4.13.2-1-jdk11: Dockerfile
18+
docker build \
19+
--build-arg JENKINS_REMOTING_TAG=4.13.2-1-jdk11 \
20+
--tag dwolla/jenkins-agent-core:4.13.2-1-jdk11-SNAPSHOT \
21+
.
22+
23+
remoting-4.13.3-1-jdk17: Dockerfile
24+
docker build \
25+
--build-arg JENKINS_REMOTING_TAG=4.13.3-1-jdk17 \
26+
--tag dwolla/jenkins-agent-core:4.13.3-1-jdk17-SNAPSHOT \
27+
.
28+
1429
${CLEAN_JOB}: clean-%:
1530
docker rmi -f dwolla/jenkins-agent-core:$*-SNAPSHOT

build/jenkins-agent-entrypoint.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
set -o errexit -o nounset -o pipefail
3+
4+
# Custom entrypoint that supports privileged token with fallback to regular token
5+
# Priority: JENKINS_PRIVILEGED_SECRET > JENKINS_SECRET
6+
7+
# Determine which secret to use
8+
if [ -n "${JENKINS_PRIVILEGED_SECRET:-}" ]; then
9+
# Use privileged token if provided
10+
export JENKINS_SECRET="${JENKINS_PRIVILEGED_SECRET}"
11+
echo "Using privileged token for Jenkins agent connection"
12+
elif [ -n "${JENKINS_SECRET:-}" ]; then
13+
# Fall back to regular token if privileged token not provided
14+
echo "Using regular token for Jenkins agent connection"
15+
else
16+
echo "Error: Neither JENKINS_PRIVILEGED_SECRET nor JENKINS_SECRET is set" >&2
17+
exit 1
18+
fi
19+
20+
# Find the original jenkins-agent script (it should be in PATH from the base image)
21+
JENKINS_AGENT_SCRIPT=$(command -v jenkins-agent)
22+
if [ -z "${JENKINS_AGENT_SCRIPT}" ]; then
23+
echo "Error: jenkins-agent script not found in PATH" >&2
24+
exit 1
25+
fi
26+
27+
# Call the original jenkins-agent entrypoint with all arguments
28+
exec "${JENKINS_AGENT_SCRIPT}" "$@"
29+

build/sdkman-init-wrapper.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# SDKMAN initialization wrapper script
3+
# This script is designed to be used as BASH_ENV to automatically configure
4+
# SDKMAN when .sdkmanrc files are present in the workspace.
5+
#
6+
# When BASH_ENV is set to this script, it will be sourced by every non-interactive
7+
# bash shell, ensuring SDKMAN is configured before any commands run.
8+
9+
# Source SDKMAN initialization if it exists
10+
if [ -f "$HOME/.sdkman/bin/sdkman-init.sh" ]; then
11+
# SDKMAN requires errexit to be disabled during initialization
12+
set +o errexit +o xtrace
13+
14+
# Source SDKMAN initialization
15+
source "$HOME/.sdkman/bin/sdkman-init.sh"
16+
17+
# Check if .sdkmanrc exists in the current working directory or workspace
18+
# Jenkins workspace is typically in $WORKSPACE or current directory
19+
SDKMANRC_PATH=""
20+
if [ -f ".sdkmanrc" ]; then
21+
SDKMANRC_PATH=".sdkmanrc"
22+
elif [ -n "${WORKSPACE:-}" ] && [ -f "${WORKSPACE}/.sdkmanrc" ]; then
23+
SDKMANRC_PATH="${WORKSPACE}/.sdkmanrc"
24+
fi
25+
26+
if [ -n "$SDKMANRC_PATH" ]; then
27+
# Change to the directory containing .sdkmanrc for sdk env install
28+
SDKMANRC_DIR=$(dirname "$SDKMANRC_PATH")
29+
if [ "$SDKMANRC_DIR" != "." ]; then
30+
cd "$SDKMANRC_DIR" || true
31+
fi
32+
# Install Java version specified in .sdkmanrc
33+
sdk env install || true
34+
# Re-source to ensure the new Java is on PATH
35+
source "$HOME/.sdkman/bin/sdkman-init.sh"
36+
fi
37+
38+
# Re-enable errexit and xtrace
39+
set -o errexit -o xtrace
40+
fi
41+

0 commit comments

Comments
 (0)