Skip to content

Commit 2e3268b

Browse files
authored
Merge pull request #281 from objectionary/264
multi-stage docker setup
2 parents 79c489f + 03e8014 commit 2e3268b

File tree

5 files changed

+92
-74
lines changed

5 files changed

+92
-74
lines changed

src/main/java/org/eolang/hone/OptimizeMojo.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ public final class OptimizeMojo extends AbstractMojo {
129129
@Parameter(property = "hone.grep-in", defaultValue = ".*")
130130
private String grepIn;
131131

132+
/**
133+
* Print all commands of all Bash scripts.
134+
*
135+
* @since 0.11.0
136+
* @checkstyle MemberNameCheck (6 lines)
137+
*/
138+
@Parameter(property = "hone.debug", defaultValue = "false")
139+
private boolean debug;
140+
132141
/**
133142
* Small steps or big steps?
134143
*
@@ -198,6 +207,8 @@ public final class OptimizeMojo extends AbstractMojo {
198207
* @since 0.1.0
199208
* @checkstyle MemberNameCheck (7 lines)
200209
* @checkstyle VisibilityModifierCheck (10 lines)
210+
* @checkstyle JavaNCSSCheck (500 lines)
211+
* @checkstyle MethodLengthCheck (500 lines)
201212
*/
202213
@Parameter(property = "hone.cache")
203214
@SuppressWarnings("PMD.ImmutableField")
@@ -300,6 +311,11 @@ public void exec() throws IOException {
300311
"--env", String.format("VERBOSE=%s", Logger.isDebugEnabled(this))
301312
)
302313
);
314+
command.addAll(
315+
Arrays.asList(
316+
"--env", String.format("DEBUG=%s", this.debug)
317+
)
318+
);
303319
command.addAll(
304320
Arrays.asList(
305321
"--env", String.format("GREP_IN=%s", this.grepIn)

src/main/resources/org/eolang/hone/scaffolding/Dockerfile

Lines changed: 62 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,100 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Objectionary.com
22
# SPDX-License-Identifier: MIT
33

4-
FROM ubuntu:24.04
4+
FROM ubuntu:24.04 AS builder
55

6-
LABEL "repository"="https://github.com/objectionary/hone-maven-plugin"
7-
LABEL "maintainer"="Yegor Bugayenko"
8-
LABEL "version"="0.0.0"
6+
SHELL ["/bin/bash", "-e", "-c", "-o", "pipefail"]
97

108
ENV DEBIAN_FRONTEND=noninteractive
11-
12-
WORKDIR /hone
13-
14-
# To use UTF-8 locale:
159
ENV LC_ALL=en_US.UTF-8
1610
ENV LANG=en_US.UTF-8
1711
ENV LANGUAGE=en_US.UTF-8
18-
RUN apt-get update && apt-get install --yes --no-install-recommends locales=* \
19-
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
20-
&& locale-gen \
21-
&& update-locale LANG=en_US.UTF-8 \
22-
&& printf 'LC_ALL=en_US.UTF-8\nLANG=en_US.UTF-8\nLANGUAGE=en_US.UTF-8\n' > /etc/default/locale \
23-
&& printf 'export LC_ALL=en_US.UTF-8\n' >> "${HOME}/.profile" \
24-
&& printf 'export LANG=en_US.UTF-8\n' >> "${HOME}/.profile" \
25-
&& printf 'export LANGUAGE=en_US.UTF-8\n' >> "${HOME}/.profile" \
26-
&& apt-get clean \
27-
&& rm -rf /var/lib/apt/lists/*
2812

29-
# Install system dependencies:
30-
RUN apt-get update \
31-
&& apt-get install --yes --no-install-recommends \
13+
RUN apt-get update && apt-get install --yes --no-install-recommends \
14+
locales=* \
3215
build-essential=* \
3316
ca-certificates=* \
3417
curl=* \
35-
wget=* \
3618
gnupg2=* \
3719
libgmp-dev=* \
38-
libxml2-utils=* \
3920
lsb-release=* \
40-
openssl=* \
4121
software-properties-common=* \
42-
tree=* \
43-
unzip=* \
4422
zlib1g-dev=* \
23+
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
24+
&& locale-gen \
25+
&& update-locale LANG=en_US.UTF-8 \
4526
&& apt-get clean \
4627
&& rm -rf /var/lib/apt/lists/*
4728

48-
# Istall Java:
49-
ENV JAVA_OPTS=-Xmx1g
50-
ENV JAVA_VERSION=17
51-
ENV JAVA_HOME=/usr/lib/jvm/java-${JAVA_VERSION}
52-
RUN apt-get --yes --fix-missing update \
53-
&& apt-get --yes --no-install-recommends install ca-certificates-java=* ca-certificates=* "openjdk-${JAVA_VERSION}-jdk=*" \
54-
&& update-ca-certificates \
55-
&& ln -s "/usr/lib/jvm/$(find /usr/lib/jvm -name "java-1.${JAVA_VERSION}*" -exec basename {} \;)" "/usr/lib/jvm/java-${JAVA_VERSION}" \
56-
&& echo "export JAVA_HOME=/usr/lib/jvm/java-${JAVA_VERSION}" >> "${HOME}/.profile" \
57-
&& apt-get clean \
58-
&& rm -rf /var/lib/apt/lists/*
59-
60-
# Istall Maven
61-
ENV MAVEN_OPTS=-Xmx1g
62-
ENV MAVEN_VERSION=3.9.9
63-
ENV M2_HOME=/usr/local/apache-maven/apache-maven-${MAVEN_VERSION}
64-
RUN echo "export M2_HOME=/usr/local/apache-maven/apache-maven-${MAVEN_VERSION}" >> "${HOME}/.profile" \
65-
&& wget --quiet "https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz" \
66-
&& mkdir -p /usr/local/apache-maven \
67-
&& mv "apache-maven-${MAVEN_VERSION}-bin.tar.gz" /usr/local/apache-maven \
68-
&& tar xzvf "/usr/local/apache-maven/apache-maven-${MAVEN_VERSION}-bin.tar.gz" -C /usr/local/apache-maven/ \
69-
&& update-alternatives --install /usr/bin/mvn mvn "${M2_HOME}/bin/mvn" 1 \
70-
&& update-alternatives --config mvn \
71-
&& mvn dependency:get -Dartifact=junit:junit:4.11
72-
73-
# Install Cabal and GHC
7429
ARG GHC=9.6.7
7530
ARG CABAL=3.12.1.0
7631
RUN gpg --batch --recv-keys ECA44F5A172EDAD947F39E3D4275CDA6A29BED43 \
77-
&& wget --quiet https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup -O /usr/bin/ghcup \
32+
&& curl -sSL https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup -o /usr/bin/ghcup \
7833
&& chmod +x /usr/bin/ghcup \
7934
&& ghcup config set gpg-setting GPGStrict \
8035
&& ghcup -v install ghc --isolate /usr/local --force "${GHC}" \
8136
&& ghcup -v install cabal --isolate /usr/local/bin --force "${CABAL}" \
82-
&& cabal update \
83-
&& ghc --version \
84-
&& cabal --version
37+
&& cabal update
8538

86-
# The value to be set in BuildMojo or in default-phino-version.txt file:
8739
ARG PHINO_VERSION=0.0.0.0
88-
RUN cabal update \
89-
&& cabal install --disable-tests --disable-coverage --overwrite-policy=always "phino-${PHINO_VERSION}" \
90-
&& cp /root/.local/bin/phino /usr/bin \
91-
&& phino --version
92-
93-
# Remove unnecessary files to reduce image size
94-
RUN rm -rf /root/.cabal \
95-
&& rm -rf /root/.local/state/cabal \
96-
&& rm -rf /usr/local/bin/cabal \
97-
&& apt-get autoremove -y \
98-
&& apt-get clean \
99-
&& rm -rf /var/lib/apt/lists/*
40+
RUN cabal install --disable-tests --disable-coverage --overwrite-policy=always "phino-${PHINO_VERSION}" \
41+
&& find /root -name phino -type f 2>/dev/null | head -1 | xargs -I {} cp {} /usr/local/bin/phino \
42+
&& chmod +x /usr/local/bin/phino \
43+
&& /usr/local/bin/phino --version
10044

101-
COPY in-docker-pom.xml pom.xml
45+
FROM eclipse-temurin:17-jre-jammy
10246

47+
LABEL "repository"="https://github.com/objectionary/hone-maven-plugin"
48+
LABEL "maintainer"="Yegor Bugayenko"
49+
LABEL "version"="0.0.0"
50+
51+
ENV DEBIAN_FRONTEND=noninteractive
52+
ENV LC_ALL=en_US.UTF-8
53+
ENV LANG=en_US.UTF-8
54+
ENV LANGUAGE=en_US.UTF-8
55+
56+
# Install only essential runtime dependencies
57+
RUN apt-get update && apt-get install --yes --no-install-recommends \
58+
locales=* \
59+
ca-certificates=* \
60+
curl=* \
61+
wget=* \
62+
libgmp10=* \
63+
libxml2-utils=* \
64+
tree=* \
65+
unzip=* \
66+
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
67+
&& locale-gen \
68+
&& update-locale LANG=en_US.UTF-8 \
69+
&& apt-get clean \
70+
&& rm -rf /var/lib/apt/lists/*
71+
72+
# Install Maven (smaller footprint)
73+
ENV MAVEN_VERSION=3.9.9
74+
ENV MAVEN_HOME=/opt/maven
75+
ENV PATH="${MAVEN_HOME}/bin:${PATH}"
76+
RUN wget --quiet "https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz" \
77+
&& tar xzf "apache-maven-${MAVEN_VERSION}-bin.tar.gz" -C /opt \
78+
&& mv "/opt/apache-maven-${MAVEN_VERSION}" "${MAVEN_HOME}" \
79+
&& rm "apache-maven-${MAVEN_VERSION}-bin.tar.gz"
80+
81+
WORKDIR /hone
82+
83+
# Copy phino binary and its dependencies from builder:
84+
COPY --from=builder /usr/local/bin/phino /usr/bin/phino
85+
RUN phino --version
86+
87+
COPY in-docker-pom.xml pom.xml
10388
COPY extensions.xml ./.mvn/
10489
COPY settings.xml /hone/
90+
91+
# Pre-download Maven dependencies and clean up unnecessary plugins
10592
RUN mkdir -p /hone/.m2 \
106-
&& mvn --settings=/hone/settings.xml --update-snapshots --batch-mode --strict-checksums --errors -Dbuildtime.output.log=true eo:help jeo:help exec:help \
107-
&& chmod -R a+rwx /hone/.m2
93+
&& mvn --settings=/hone/settings.xml --update-snapshots --batch-mode --strict-checksums --errors -Dbuildtime.output.log=true eo:help jeo:help exec:help \
94+
&& chmod -R a+rwx /hone/.m2 \
95+
&& find /hone/.m2 -name "*.lastUpdated" -delete \
96+
&& find /hone/.m2 -name "_remote.repositories" -delete \
97+
&& find /hone/.m2 -name "*.sha1" -delete
10898

10999
ENV MAVEN_OPTS=-Xmx16g
110100
ENV JAVA_OPTS=-Xmx16g

src/main/resources/org/eolang/hone/scaffolding/entry.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
set -e -o pipefail
66

7+
if [ "${DEBUG}" == 'true' ]; then
8+
echo "We are in debug mode, printing all commands..."
9+
set -x
10+
fi
11+
712
SELF=$(dirname "$0")
813

914
if [ -z "${TARGET}" ]; then
@@ -86,7 +91,7 @@ printf 'Using Java: %s\n' "$(java --version | head -1)"
8691

8792
printf 'Using Maven: %s\n' "$(mvn --version | head -1)"
8893

89-
printf 'Using the following rules:\n\t%s\n' "${RULES// /\n\t/g}"
94+
printf 'Using the following rules:\n\t%b\n' "${RULES// /\n\t/g}"
9095

9196
declare -a jeo_opts=()
9297
if [ -n "${INCLUDES}" ]; then
@@ -108,6 +113,7 @@ fi
108113
exec:exec \
109114
"-Dexec.phino.script=${SELF}/normalize.sh" \
110115
"-Dexec.phino.verbose=${VERBOSE}" \
116+
"-Dexec.phino.debug=${DEBUG}" \
111117
"-Dexec.phino.rules=${RULES}" \
112118
"-Dexec.phino.grep-in=${GREP_IN}" \
113119
"-Dexec.phino.xmir-in=${TARGET}/generated-sources/jeo-disassemble" \

src/main/resources/org/eolang/hone/scaffolding/in-docker-pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<executable>${exec.phino.script}</executable>
4343
<environmentVariables>
4444
<HONE_VERBOSE>${exec.phino.verbose}</HONE_VERBOSE>
45+
<HONE_DEBUG>${exec.phino.debug}</HONE_DEBUG>
4546
<HONE_RULES>${exec.phino.rules}</HONE_RULES>
4647
<HONE_GREP_IN>${exec.phino.grep-in}</HONE_GREP_IN>
4748
<HONE_XMIR_IN>${exec.phino.xmir-in}</HONE_XMIR_IN>

src/main/resources/org/eolang/hone/scaffolding/normalize.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
set -e -o pipefail
66

7+
if [ "${HONE_DEBUG}" == 'true' ]; then
8+
echo "We are in debug mode, printing all commands..."
9+
set -x
10+
fi
11+
712
function verbose {
813
if [ "${HONE_VERBOSE}" == 'true' ]; then
914
echo "$@"
@@ -90,7 +95,7 @@ while IFS= read -r f; do
9095
fi
9196
s_size=$(du -sh "${xi}" | cut -f1)
9297
s_lines=$(wc -l < "${s}")
93-
per=$(perl -E "say int(${s_lines} / ( $(date '+%s.%N') - ${start} ))")
98+
per=$(perl -E "say int( ${s_lines} / ( $(date '+%s.%N') - ${start} ) )")
9499
if cmp -s "${r}" "${s}"; then
95100
echo "No changes in ${idx}/${total} $(basename "${s}"): ${s_size}, ${s_lines} lines, ${per} lps"
96101
else

0 commit comments

Comments
 (0)