Skip to content

Commit 8b889ba

Browse files
committed
FIREFLY-1875: Multi-platform docker build
- optimize build stages - add platform logic
1 parent 655f5ef commit 8b889ba

File tree

3 files changed

+88
-66
lines changed

3 files changed

+88
-66
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
build/
2323
jars/build/
2424
.gradle/
25+
.env
2526

2627

2728
# ignore javascript dependencies

compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ services:
44
build:
55
context: ../
66
dockerfile: firefly/docker/Dockerfile
7+
args:
8+
BUILDPLATFORM: ${BUILDPLATFORM:-linux/amd64}
79
ports:
810
- "8080:8080"
911
env_file:

docker/Dockerfile

Lines changed: 85 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,90 @@
1-
ARG build_dir=firefly
2-
ARG target=firefly:warAll
3-
ARG env=local
4-
ARG BranchOverride=''
1+
ARG BUILDPLATFORM=linux/amd64
52

6-
FROM eclipse-temurin:21-jdk-jammy AS deps
3+
# ==============================
4+
# Stage 1: Base dependencies
5+
# ==============================
6+
FROM --platform=${BUILDPLATFORM} eclipse-temurin:21-jdk-jammy AS base
77

8-
RUN apt-get update && apt-get install -y curl git htmldoc unzip wget ca-certificates gnupg
9-
10-
RUN apt-get update \
11-
# use node v18.x (from https://github.com/nodesource/distributions because it may not be available via apt-get)
12-
&& curl -fsSL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh \
13-
&& bash nodesource_setup.sh \
8+
RUN apt-get update && apt-get install -y \
9+
curl git unzip wget ca-certificates gnupg htmldoc \
10+
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
1411
&& apt-get install -y nodejs \
15-
&& npm install yarn -g \
12+
&& npm install -g yarn \
1613
# gradle version 8.10 Not available via apt-get
1714
&& cd /usr/local \
18-
&& wget -q https://services.gradle.org/distributions/gradle-8.10-bin.zip \
15+
&& wget -q https://services.gradle.org/distributions/gradle-8.10-bin.zip \
1916
&& unzip -q gradle-8.10-bin.zip \
20-
&& ln -sf /usr/local/gradle-8.10/bin/gradle /usr/local/bin/ \
17+
&& ln -sf /usr/local/gradle-8.10/bin/gradle /usr/local/bin/gradle \
2118
&& rm gradle-8.10-bin.zip \
2219
# cleanup
2320
&& rm -rf /var/lib/apt/lists/*;
2421

25-
WORKDIR "/opt/work"
22+
WORKDIR /opt/work
23+
2624

27-
FROM deps AS node_module
25+
# =====================================
26+
# Stage 1: Node modules and maven cache
27+
# =====================================
28+
FROM --platform=${BUILDPLATFORM} base AS deps
2829

29-
WORKDIR "/opt/work/lib"
30+
WORKDIR /opt/work/lib
3031
COPY firefly/package.json firefly/yarn.lock ./
32+
# 900000= 15 minutes because QEMU(arm64 emulator) is super slow.
3133
RUN yarn install --ignore-platform --frozen-lockfile
3234

35+
# Copy only minimal build descriptors (no source) so we can resolve base
36+
WORKDIR /opt/work/firefly
37+
COPY firefly/settings.gradle firefly/gradle.properties firefly/build.gradle ./
38+
COPY firefly/buildScript/ ./buildScript
39+
COPY firefly/src/firefly/build.gradle src/firefly/build.gradle
40+
41+
# Warm up local Gradle/Maven caches (no build yet)
42+
# `gradle dependencies` downloads all declared jars
43+
RUN gradle --no-daemon --quiet --refresh-dependencies firefly:dependencies || true
44+
45+
46+
# =====================================
47+
# Stage 3: Builder (Gradle, amd64 only)
48+
# =====================================
49+
FROM --platform=${BUILDPLATFORM} base AS builder
50+
51+
ARG build_dir=firefly
52+
ARG target=firefly:warAll
53+
ARG env=local
54+
ARG BranchOverride=''
55+
ARG checkoutFirefly
56+
57+
WORKDIR /opt/work
58+
COPY . .
59+
COPY --from=deps /opt/work/lib/node_modules ./firefly/node_modules
60+
COPY --from=deps /root/.gradle /root/.gradle
61+
62+
63+
WORKDIR /opt/work/${build_dir}
64+
ENV GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false"
65+
RUN if [ -z "$checkoutFirefly" ] ; then echo skip checkout ; else gradle firefly:checkoutFirefly ; fi
66+
RUN gradle -Penv=${env} -PBranchOverride=${BranchOverride} ${target}
67+
3368

34-
FROM node_module AS dev_env
69+
# ==============================
70+
# Dev environment
71+
# ==============================
72+
FROM base AS dev_env
3573

36-
RUN apt-get update \
37-
&& apt-get install -y vim procps python3 \
74+
RUN apt-get update && apt-get install -y vim procps python3 \
3875
# cleanup
39-
&& rm -rf /var/lib/apt/lists/*;
76+
&& rm -rf /var/lib/apt/lists/*
4077

4178
COPY --from=tomcat:11.0.11-jre21-temurin-jammy /usr/local/tomcat /usr/local/tomcat
42-
79+
COPY --from=deps /opt/work/lib/node_modules ./firefly/node_modules
80+
COPY --from=deps /root/.gradle /root/.gradle
4381

4482
ENV CATALINA_HOME=/usr/local/tomcat \
4583
USE_ADMIN_AUTH=false \
46-
DEBUG=true
47-
48-
ENV work_dir=firefly
49-
ENV project=firefly
50-
ENV env=local
84+
DEBUG=true \
85+
work_dir=firefly \
86+
project=firefly \
87+
env=local
5188

5289
WORKDIR ${CATALINA_HOME}
5390

@@ -61,34 +98,15 @@ RUN mkdir -p /firefly/workarea /firefly/logs/statistics /firefly/alerts \
6198

6299
CMD ./devMode.sh
63100

64-
65-
FROM node_module AS builder
66-
67-
ARG build_dir
68-
ARG target
69-
ARG env
70-
ARG BranchOverride
71-
ARG checkoutFirefly
72-
73-
74-
WORKDIR /opt/work
75-
COPY . .
76-
COPY --from=node_module /opt/work/lib/node_modules ./firefly/node_modules
77-
78-
WORKDIR /opt/work/${build_dir}
79-
ENV GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false"
80-
RUN if [ -z "$checkoutFirefly" ] ; then echo skip checkout ; else gradle firefly:checkoutFirefly ; fi
81-
RUN gradle -Penv=${env} -PBranchOverride=${BranchOverride} ${target}
82-
83-
84-
# Beginning of runtime image script
85-
101+
# ==============================
102+
# Stage 4: Runtime image
103+
# ==============================
86104
# Description:
87105
# A tomcat application server running as UID 91(tomcat) by default.
88106
# It's designed to support running as a different user via -u or --user param.
89107
#
90108
#-----------------------------------------------------------------------------
91-
# To build: docker build -t ipac/firefly --build-arg IMAGE_NAME=ipac/firefly .
109+
# To build: docker build -t ipac/firefly
92110
# For help in running: docker run --rm ipac/firefly --help
93111
#-----------------------------------------------------------------------------
94112
#
@@ -108,20 +126,14 @@ RUN gradle -Penv=${env} -PBranchOverride=${BranchOverride} ${target}
108126

109127
FROM tomcat:11.0.11-jre21-temurin-jammy
110128

111-
ARG build_dir
129+
ARG build_dir=firefly
112130
ARG user=tomcat
113131
ARG group=tomcat
114132
ARG uid=91
115133
ARG gid=91
116-
117-
118-
# - add packages: vim, wget, etc
119-
# - add any other standard apt packages here
120-
# - this is a big part of the layer so do it early
121-
# - emacs removed because it is so big: to readd emacs: emacs-nox
122-
RUN apt-get update && apt-get install -y \
123-
vim procps wget unzip python3 \
124-
&& rm -rf /var/lib/apt/lists/*;
134+
ARG TARGETARCH
135+
ARG TARGETOS
136+
ARG DUCKDB_VERSION=v1.1.3
125137

126138
# These are the users replaceable environment variables, basically runtime arguments
127139
# - Set the available memory on the command line with --memory="4g"
@@ -144,14 +156,22 @@ ENV JVM_CORES=0\
144156
# ----------------------------------------------------------
145157
# ----------------------------------------------------------
146158

147-
ARG IMAGE_NAME=''
159+
# - add packages: vim, wget, etc
160+
# - add any other standard apt packages here
161+
# - this is a big part of the layer so do it early
162+
# - emacs removed because it is so big: to readd emacs: emacs-nox
163+
RUN apt-get update && apt-get install -y \
164+
vim procps wget unzip python3 \
165+
&& rm -rf /var/lib/apt/lists/*;
148166

149167
WORKDIR ${CATALINA_HOME}
150168

151169
# set up directory protections, copy stuff around, add tomcat user and group
152-
RUN mkdir -p conf/Catalina/localhost /local/www /firefly/config /firefly/workarea /firefly/shared-workarea /firefly/logs/statistics /firefly/alerts \
153-
&& groupadd -g ${gid} ${group} && useradd -u ${uid} -g ${group} -s /bin/sh ${user} \
154-
&& rm -r logs && ln -s /firefly/logs logs
170+
RUN mkdir -p conf/Catalina/localhost /local/www /firefly/config /firefly/workarea \
171+
/firefly/shared-workarea /firefly/logs/statistics /firefly/alerts \
172+
&& groupadd -g ${gid} ${group} \
173+
&& useradd -u ${uid} -g ${group} -s /bin/sh ${user} \
174+
&& rm -r logs && ln -s /firefly/logs logs
155175

156176
# These are the file that are executed at startup: start tomcat, logging, help, etc
157177
COPY firefly/docker/*.sh firefly/docker/*.txt firefly/docker/*.py ${CATALINA_HOME}/
@@ -172,14 +192,13 @@ RUN sed -i 's/<Connector port="8080" protocol="HTTP\/1.1"/<Connector port="8080"
172192
$CATALINA_HOME/conf/server.xml
173193

174194
# preinstall DuckDB extensions; remember to update version when DuckDB is updated
175-
ARG DUCKDB_TARGET=v1.1.3/linux_amd64_gcc4
195+
ENV DUCKDB_TARGET=${DUCKDB_VERSION}/${TARGETOS}_${TARGETARCH}
176196
RUN mkdir -p temp/$DUCKDB_TARGET \
177197
&& wget -P temp/$DUCKDB_TARGET http://community-extensions.duckdb.org/$DUCKDB_TARGET/magic.duckdb_extension.gz \
178198
&& gunzip -f temp/$DUCKDB_TARGET/magic.duckdb_extension.gz
179199

180200
# Add permission to files and directories needed for runtime
181201
# increase max header size to avoid failing on large auth token
182-
WORKDIR ${CATALINA_HOME}
183202
RUN chmod a+x *.sh \
184203
&& chmod -R a+w *.txt temp work /local/www /firefly ${CATALINA_HOME}/webapps \
185204
&& sed -i 's/Connector port="8080"/Connector maxHttpHeaderSize="24576" port="8080"/g' ${CATALINA_HOME}/conf/server.xml

0 commit comments

Comments
 (0)