-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.layer2
More file actions
309 lines (267 loc) · 12.8 KB
/
Copy pathDockerfile.layer2
File metadata and controls
309 lines (267 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# syntax=docker/dockerfile:1.7
# Layer 2: Java Bench Image
# Extends Layer 1 (dev-bench-base) with Java specific tools
# Includes: OpenJDK 25, Maven, Gradle, Spring CLI, Java tools
ARG BASE_IMAGE=dev-bench-base:latest
FROM ${BASE_IMAGE}
ARG JACOCO_VERSION=0.8.15
ARG SONAR_MAVEN_PLUGIN_VERSION=5.7.0.6970
ARG SONAR_GRADLE_PLUGIN_VERSION=7.3.1.8318
ARG SPRINGBOOT_VERSION=4.1.0
ARG KOTLIN_VERSION=2.4.0
ARG GROOVY_VERSION=6.0.0-alpha-1
ARG SCALA_VERSION=3.8.4
ARG QUARKUS_VERSION=3.37.1
ARG MICRONAUT_VERSION=5.0.3
# Container version labels
LABEL layer="2"
LABEL layer.name="java-bench"
LABEL layer.version="2.2.10"
LABEL layer.description="Java development tools and JDK (user-agnostic)"
LABEL bench.type="java"
# Everything runs as root
USER root
# ========================================
# JAVA JDK
# ========================================
# Install OpenJDK 25 (LTS) and zip (required by SDKMAN)
RUN apt-get update && apt-get install -y \
openjdk-25-jdk \
openjdk-25-jre \
zip \
&& rm -rf /var/lib/apt/lists/*
# Set JAVA_HOME
ENV JAVA_HOME=/usr/lib/jvm/java-25-openjdk-amd64
ENV PATH="$JAVA_HOME/bin:$PATH"
ENV JACOCO_VERSION=${JACOCO_VERSION}
ENV JACOCO_CLI_JAR=/opt/jacoco/jacococli.jar
ENV JACOCO_AGENT_JAR=/opt/jacoco/jacocoagent.jar
ENV SONAR_MAVEN_PLUGIN_VERSION=${SONAR_MAVEN_PLUGIN_VERSION}
ENV SONAR_GRADLE_PLUGIN_VERSION=${SONAR_GRADLE_PLUGIN_VERSION}
ENV SPRINGBOOT_VERSION=${SPRINGBOOT_VERSION}
ENV KOTLIN_VERSION=${KOTLIN_VERSION}
ENV GROOVY_VERSION=${GROOVY_VERSION}
ENV SCALA_VERSION=${SCALA_VERSION}
ENV QUARKUS_VERSION=${QUARKUS_VERSION}
ENV MICRONAUT_VERSION=${MICRONAUT_VERSION}
# ========================================
# BUILD TOOLS
# ========================================
# Install Maven
RUN apt-get update && apt-get install -y \
maven \
&& rm -rf /var/lib/apt/lists/*
# Install a resumable, multi-connection downloader for large tool distributions.
RUN apt-get update && apt-get install -y --no-install-recommends \
aria2 \
&& rm -rf /var/lib/apt/lists/*
# Install Gradle
RUN aria2c --allow-overwrite=true --auto-file-renaming=false --continue=true \
--max-connection-per-server=8 --split=8 --min-split-size=8M \
--max-tries=10 --retry-wait=5 --connect-timeout=30 --timeout=120 \
--summary-interval=30 --console-log-level=warn \
-d /tmp -o gradle-9.6.1-bin.zip \
https://downloads.gradle.org/distributions/gradle-9.6.1-bin.zip \
&& unzip -d /opt/gradle /tmp/gradle-9.6.1-bin.zip \
&& rm /tmp/gradle-9.6.1-bin.zip \
&& ln -s /opt/gradle/gradle-9.6.1/bin/gradle /usr/local/bin/gradle
ENV GRADLE_HOME=/opt/gradle/gradle-9.6.1
ENV PATH="$GRADLE_HOME/bin:$PATH"
ENV CURL_RETRY_OPTS="--retry 5 --retry-delay 5 --connect-timeout 30 --max-time 600"
ENV ARIA2_RETRY_OPTS="--allow-overwrite=true --auto-file-renaming=false --continue=true --max-connection-per-server=8 --split=8 --min-split-size=1M --max-tries=10 --retry-wait=5 --connect-timeout=30 --timeout=120 --summary-interval=30 --console-log-level=warn"
# ========================================
# JAVA DEVELOPMENT TOOLS
# ========================================
# Install SDKMan system-wide
RUN curl -fsSL $CURL_RETRY_OPTS "https://get.sdkman.io" | bash \
&& bash -c "source $HOME/.sdkman/bin/sdkman-init.sh" \
&& mv /root/.sdkman /opt/sdkman \
&& chmod -R a+rx /opt/sdkman
ENV SDKMAN_DIR=/opt/sdkman
# Install SDKMAN-hosted JVM CLIs with resumable downloads. Calling `sdk install`
# directly can fall back to a slow single-stream downloader inside Docker.
RUN --mount=type=cache,target=/var/cache/sdkman-downloads,sharing=locked set -eux; \
install_sdkman_archive() { \
candidate="$1"; \
version="$2"; \
install_dir="/opt/${candidate}-${version}"; \
download_dir="/var/cache/sdkman-downloads"; \
archive="${download_dir}/${candidate}-${version}.zip"; \
extract_dir="/tmp/${candidate}-${version}-extract"; \
rm -rf "$install_dir" "$extract_dir"; \
mkdir -p "$download_dir" "$extract_dir"; \
aria2c $ARIA2_RETRY_OPTS -d "$download_dir" -o "$(basename "$archive")" \
"https://api.sdkman.io/2/broker/download/${candidate}/${version}/linuxx64"; \
unzip -q "$archive" -d "$extract_dir"; \
first_entry="$(find "$extract_dir" -mindepth 1 -maxdepth 1 | head -n1)"; \
entry_count="$(find "$extract_dir" -mindepth 1 -maxdepth 1 | wc -l)"; \
mkdir -p "$install_dir"; \
if [ "$entry_count" = "1" ] && [ -d "$first_entry" ]; then \
cp -a "$first_entry"/. "$install_dir"/; \
else \
cp -a "$extract_dir"/. "$install_dir"/; \
fi; \
chmod -R a+rX "$install_dir"; \
if [ -d "$install_dir/bin" ]; then \
find "$install_dir/bin" -maxdepth 1 -type f -perm /111 -printf '%f\n' | \
while read -r tool; do \
ln -sf "$install_dir/bin/$tool" "/usr/local/bin/$tool"; \
done; \
fi; \
rm -rf "$extract_dir"; \
}; \
install_sdkman_archive springboot "$SPRINGBOOT_VERSION"; \
install_sdkman_archive kotlin "$KOTLIN_VERSION"; \
install_sdkman_archive groovy "$GROOVY_VERSION"; \
install_sdkman_archive scala "$SCALA_VERSION"; \
install_sdkman_archive quarkus "$QUARKUS_VERSION"; \
install_sdkman_archive micronaut "$MICRONAUT_VERSION"; \
spring --version; \
kotlin -version; \
groovy --version; \
scala -version; \
quarkus --version; \
mn --version
# ========================================
# CONTAINER TOOLING
# ========================================
# Install Docker CLI (client only, daemon runs on host via socket mount)
RUN apt-get update && apt-get install -y \
ca-certificates gnupg lsb-release \
&& install -m 0755 -d /etc/apt/keyrings \
&& curl -fsSL $CURL_RETRY_OPTS https://download.docker.com/linux/ubuntu/gpg | gpg --batch --yes --dearmor -o /etc/apt/keyrings/docker.gpg \
&& chmod a+r /etc/apt/keyrings/docker.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list \
&& apt-get update && apt-get install -y docker-ce-cli docker-compose-plugin \
&& rm -rf /var/lib/apt/lists/*
# ========================================
# DATABASE CLIENTS
# ========================================
RUN apt-get update && apt-get install -y \
postgresql-client \
default-mysql-client \
sqlite3 \
redis-tools \
&& rm -rf /var/lib/apt/lists/*
# ========================================
# CODE QUALITY / STATIC ANALYSIS TOOLS
# ========================================
# Checkstyle
RUN mkdir -p /opt/checkstyle \
&& aria2c $ARIA2_RETRY_OPTS -d /opt/checkstyle -o checkstyle.jar \
https://github.com/checkstyle/checkstyle/releases/download/checkstyle-13.7.0/checkstyle-13.7.0-all.jar \
&& printf '%s\n' '#!/usr/bin/env sh' \
'exec java -jar /opt/checkstyle/checkstyle.jar "$@"' \
> /usr/local/bin/checkstyle \
&& chmod +x /usr/local/bin/checkstyle
# SpotBugs
RUN aria2c $ARIA2_RETRY_OPTS -d /tmp -o spotbugs.tgz \
https://github.com/spotbugs/spotbugs/releases/download/4.10.2/spotbugs-4.10.2.tgz \
&& tar -xzf /tmp/spotbugs.tgz -C /opt \
&& chmod +x /opt/spotbugs-4.10.2/bin/spotbugs \
&& ln -s /opt/spotbugs-4.10.2/bin/spotbugs /usr/local/bin/spotbugs \
&& rm /tmp/spotbugs.tgz
# PMD
RUN aria2c $ARIA2_RETRY_OPTS -d /tmp -o pmd.zip \
https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.26.0/pmd-dist-7.26.0-bin.zip \
&& unzip -q /tmp/pmd.zip -d /opt \
&& ln -s /opt/pmd-bin-7.26.0/bin/pmd /usr/local/bin/pmd \
&& rm /tmp/pmd.zip
# JaCoCo coverage tools for manual Java coverage workflows.
COPY files/jacoco-cli /usr/local/bin/jacoco-cli
COPY files/sonarcloud-java-maven /usr/local/bin/sonarcloud-java-maven
COPY files/sonarcloud-java-gradle /usr/local/bin/sonarcloud-java-gradle
RUN mkdir -p /opt/jacoco \
&& aria2c $ARIA2_RETRY_OPTS -d /opt/jacoco -o jacococli.jar \
"https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/${JACOCO_VERSION}/org.jacoco.cli-${JACOCO_VERSION}-nodeps.jar" \
&& aria2c $ARIA2_RETRY_OPTS -d /opt/jacoco -o jacocoagent.jar \
"https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/${JACOCO_VERSION}/org.jacoco.agent-${JACOCO_VERSION}-runtime.jar" \
&& chmod +x /usr/local/bin/jacoco-cli /usr/local/bin/sonarcloud-java-maven /usr/local/bin/sonarcloud-java-gradle
# SonarScanner CLI is inherited from dev-bench-base.
RUN sonar-scanner --version
# ========================================
# JVM COMPANION LANGUAGES
# ========================================
# ========================================
# SYSTEM UTILITIES
# ========================================
RUN apt-get update && apt-get install -y \
htop \
tree \
less \
ant \
&& rm -rf /var/lib/apt/lists/*
# ========================================
# FRAMEWORK CLIs
# ========================================
# ========================================
# PERFORMANCE TESTING
# ========================================
# Apache JMeter 5.6.3
RUN aria2c $ARIA2_RETRY_OPTS -d /tmp -o jmeter.tgz \
https://dlcdn.apache.org/jmeter/binaries/apache-jmeter-5.6.3.tgz \
&& tar -xzf /tmp/jmeter.tgz -C /opt \
&& ln -s /opt/apache-jmeter-5.6.3/bin/jmeter /usr/local/bin/jmeter \
&& rm /tmp/jmeter.tgz
ENV JMETER_HOME=/opt/apache-jmeter-5.6.3
# Gatling standalone bundle
RUN aria2c $ARIA2_RETRY_OPTS -d /tmp -o gatling.zip \
https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/3.15.1/gatling-charts-highcharts-bundle-3.15.1-bundle.zip \
&& unzip -q /tmp/gatling.zip -d /opt \
&& chmod +x /opt/gatling-charts-highcharts-bundle-3.15.1/mvnw \
&& printf '%s\n' '#!/usr/bin/env bash' \
'set -euo pipefail' \
'cd "${GATLING_HOME:-/opt/gatling-charts-highcharts-bundle-3.15.1}"' \
'exec ./mvnw gatling:test "$@"' > /usr/local/bin/gatling \
&& printf '%s\n' '#!/usr/bin/env bash' \
'set -euo pipefail' \
'cd "${GATLING_HOME:-/opt/gatling-charts-highcharts-bundle-3.15.1}"' \
'exec ./mvnw gatling:recorder "$@"' > /usr/local/bin/gatling-recorder \
&& chmod +x /usr/local/bin/gatling /usr/local/bin/gatling-recorder \
&& rm /tmp/gatling.zip
ENV GATLING_HOME=/opt/gatling-charts-highcharts-bundle-3.15.1
# ========================================
# WORKSPACE SETUP
# ========================================
# Create common Java project directories
RUN mkdir -p /workspace/projects \
&& mkdir -p /workspace/m2repo \
&& mkdir -p /workspace/.gradle
# Configure Maven to use workspace m2repo (in /etc/skel)
RUN mkdir -p /etc/skel/.m2 \
&& echo '<?xml version="1.0" encoding="UTF-8"?>' > /etc/skel/.m2/settings.xml \
&& echo '<settings>' >> /etc/skel/.m2/settings.xml \
&& echo ' <localRepository>/workspace/m2repo</localRepository>' >> /etc/skel/.m2/settings.xml \
&& echo '</settings>' >> /etc/skel/.m2/settings.xml
# ========================================
# SHELL CONFIGURATION (into /etc/skel)
# ========================================
# Add Java development aliases and environment to /etc/skel/.zshrc
RUN echo '' >> /etc/skel/.zshrc && \
echo '# Java Development Environment' >> /etc/skel/.zshrc && \
echo 'export JAVA_HOME=/usr/lib/jvm/java-25-openjdk-amd64' >> /etc/skel/.zshrc && \
echo 'export GRADLE_HOME=/opt/gradle/gradle-9.6.1' >> /etc/skel/.zshrc && \
echo 'export PATH="$JAVA_HOME/bin:$GRADLE_HOME/bin:$PATH"' >> /etc/skel/.zshrc && \
echo '' >> /etc/skel/.zshrc && \
echo '# Java Build aliases' >> /etc/skel/.zshrc && \
echo 'alias mvn-clean="mvn clean"' >> /etc/skel/.zshrc && \
echo 'alias mvn-package="mvn clean package"' >> /etc/skel/.zshrc && \
echo 'alias mvn-install="mvn clean install"' >> /etc/skel/.zshrc && \
echo 'alias mvn-test="mvn test"' >> /etc/skel/.zshrc && \
echo 'alias mvn-sonar-coverage="sonarcloud-java-maven"' >> /etc/skel/.zshrc && \
echo 'alias gradle-build="gradle build"' >> /etc/skel/.zshrc && \
echo 'alias gradle-clean="gradle clean"' >> /etc/skel/.zshrc && \
echo 'alias gradle-test="gradle test"' >> /etc/skel/.zshrc && \
echo 'alias gradle-sonar-coverage="sonarcloud-java-gradle"' >> /etc/skel/.zshrc && \
echo 'alias spring-run="./mvnw spring-boot:run"' >> /etc/skel/.zshrc && \
echo '' >> /etc/skel/.zshrc && \
echo '# Performance Testing aliases' >> /etc/skel/.zshrc && \
echo 'alias jmeter-cli="jmeter -n"' >> /etc/skel/.zshrc && \
echo 'alias jmeter-report="jmeter -g"' >> /etc/skel/.zshrc
# Add SDKMan initialization
RUN echo '' >> /etc/skel/.zshrc && \
echo '# SDKMan initialization' >> /etc/skel/.zshrc && \
echo 'export SDKMAN_DIR="/opt/sdkman"' >> /etc/skel/.zshrc && \
echo '[[ -s "/opt/sdkman/bin/sdkman-init.sh" ]] && source "/opt/sdkman/bin/sdkman-init.sh"' >> /etc/skel/.zshrc
# Default command
CMD ["sleep", "infinity"]