Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
82 lines (67 loc) · 2.87 KB
/
Copy pathDockerfile
File metadata and controls
82 lines (67 loc) · 2.87 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
# ============================================================================
# Stage 1: Builder - Contains all build tools and dependencies
# ============================================================================
FROM alpine:3.20 AS builder
# Install build dependencies
# - openjdk21-jre-headless: Minimal Java runtime (no GUI, no JDK tools)
# - bash: Required for build scripts
# - git: For submodule management
# - wget & unzip: For downloading Groovy
# - pandoc: Document converter (already in Alpine repos!)
# - cmark: CommonMark markdown validator
RUN apk add --no-cache \
openjdk21-jre-headless \
bash \
git \
wget \
unzip \
pandoc \
cmark
# Install Groovy
RUN wget -q https://groovy.jfrog.io/artifactory/dist-release-local/groovy-zips/apache-groovy-binary-5.0.3.zip && \
unzip -q apache-groovy-binary-5.0.3.zip -d /opt/ && \
rm apache-groovy-binary-5.0.3.zip && \
ln -s /opt/groovy-5.0.3 /opt/groovy
# Set environment variables for builder
ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk
ENV GROOVY_HOME=/opt/groovy
ENV PATH="${GROOVY_HOME}/bin:${JAVA_HOME}/bin:${PATH}"
WORKDIR /workspace
# Copy project files
COPY . /workspace
# Pre-download Groovy dependencies to cache them in the image
# Then clean up unnecessary files (source JARs, javadocs) to save space
RUN groovy ./init-groovy-deps.groovy 2>&1 && \
echo "Cleaning up Groovy Grape cache..." && \
find /root/.groovy/grapes -name "*-sources.jar" -delete 2>/dev/null || true && \
find /root/.groovy/grapes -name "*-javadoc.jar" -delete 2>/dev/null || true && \
find /root/.groovy/grapes -type d -name "cache" -exec rm -rf {} + 2>/dev/null || true && \
echo "Cleanup complete" || echo "Warning: Could not pre-cache dependencies"
# ============================================================================
# Stage 2: Runtime - Minimal image with only what's needed to run builds
# ============================================================================
FROM alpine:3.20
# Install only runtime dependencies (no wget/unzip needed)
RUN apk add --no-cache \
openjdk21-jre-headless \
bash \
git \
pandoc \
cmark
# Fix Git ownership for mounted volumes (Codespaces/CI environments)
RUN git config --global --add safe.directory '*'
# Copy Groovy installation from builder
COPY --from=builder /opt/groovy-5.0.3 /opt/groovy-5.0.3
RUN ln -s /opt/groovy-5.0.3 /opt/groovy
# Copy cached Groovy dependencies from builder
COPY --from=builder /root/.groovy /root/.groovy
# Set environment variables
ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk
ENV GROOVY_HOME=/opt/groovy
ENV PATH="${GROOVY_HOME}/bin:${JAVA_HOME}/bin:${PATH}"
WORKDIR /workspace
# Copy only necessary project files (build scripts and source)
COPY build.groovy buildconfig.groovy init-groovy-deps.groovy build-arc42.sh ./
COPY lib/ ./lib/
# Default command: run the build script
CMD ["/bin/bash", "./build-arc42.sh"]