mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
Both native Dockerfiles wrote the ~196 MB binary into the image twice. A RUN that
renames or chmods a large file rewrites the whole file into a new layer, so the
published image carried two copies of it:
110 MB ubi9-minimal base
18.8 MB microdnf install
196 MB COPY --chown=1001:root native/<arch>/ /app/
196 MB RUN mv /app/*-runner /app/application && chmod +x /app/application
Set the mode in the COPY itself and move the rename out of the image and into the
build pipeline, which now stages the binary as native/<arch>/application.
Dockerfile.native does the same with a single COPY --chmod=755 --from=build.
Measured on linux/arm64 against floci/floci:1.5.34, with a 196 MB binary on both
sides so the comparison is like for like:
uncompressed 521 MB -> 325 MB
compressed 168 MB -> 104 MB (sum of gzip -6 layer blobs; Docker Hub
reports 166.1 MB for 1.5.34)
layers 8 -> 6
No behaviour change. The only filesystem difference in the resulting image is
quarkus-artifact.properties, now 0755 rather than 0644, because --chmod applies to
every file in the staged directory. /app and /app/data keep 0775 and uid 1001:0 for
arbitrary-uid (OpenShift) runs, and /app/application keeps 0755 — docker/entrypoint.sh
gates its default command on [ -x /app/application ].
72 lines
2.6 KiB
Docker
72 lines
2.6 KiB
Docker
# Stage 1: Build native executable
|
|
FROM quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-25 AS build
|
|
USER root
|
|
WORKDIR /app
|
|
|
|
# Install Maven 3.9.x (system Maven is too old for Quarkus 3.31)
|
|
RUN curl -fsSL https://archive.apache.org/dist/maven/maven-3/3.9.12/binaries/apache-maven-3.9.12-bin.tar.gz | tar xz -C /opt \
|
|
&& ln -sf /opt/apache-maven-3.9.12/bin/mvn /usr/local/bin/mvn
|
|
|
|
COPY pom.xml .
|
|
RUN mvn dependency:go-offline -B
|
|
COPY src ./src
|
|
|
|
RUN mvn clean package -Dnative -DskipTests -B
|
|
|
|
# See: https://www.redhat.com/en/blog/build-ubi-micro-images
|
|
FROM registry.access.redhat.com/ubi9:9.7 AS tools
|
|
|
|
ENV GOSU_VERSION=1.17
|
|
ENV GOSU_AMD64_SHA256=bbc4136d03ab138b1ad66fa4fc051bafc6cc7ffae632b069a53657279a450de3
|
|
ENV GOSU_ARM64_SHA256=c3805a85d17f4454c23d7059bcb97e1ec1af272b90126e79ed002342de08389b
|
|
|
|
RUN set -eux; \
|
|
mkdir -p /toolsroot; \
|
|
dnf install -y --installroot=/toolsroot --releasever=9 \
|
|
--setopt=install_weak_deps=0 --nodocs \
|
|
shadow-utils; \
|
|
dnf -y --installroot=/toolsroot clean all; \
|
|
rm -rf /toolsroot/var/cache/* /toolsroot/var/log/dnf* /toolsroot/var/log/yum* \
|
|
/toolsroot/var/lib/rpm /toolsroot/var/lib/dnf; \
|
|
arch="$(uname -m)"; \
|
|
case "$arch" in \
|
|
x86_64) gosuArch='amd64'; gosuSha256="$GOSU_AMD64_SHA256" ;; \
|
|
aarch64) gosuArch='arm64'; gosuSha256="$GOSU_ARM64_SHA256" ;; \
|
|
*) echo >&2 "unsupported arch: $arch"; exit 1 ;; \
|
|
esac; \
|
|
mkdir -p /toolsroot/usr/local/bin; \
|
|
curl -fsSL -o /toolsroot/usr/local/bin/gosu \
|
|
"https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${gosuArch}"; \
|
|
echo "${gosuSha256} /toolsroot/usr/local/bin/gosu" | sha256sum -c -; \
|
|
chmod +x /toolsroot/usr/local/bin/gosu
|
|
|
|
# Stage 3: Minimal runtime
|
|
FROM quay.io/quarkus/quarkus-micro-image:2.0
|
|
|
|
USER root
|
|
WORKDIR /app
|
|
COPY --from=tools /toolsroot/ /
|
|
|
|
RUN useradd -r -u 1001 -g root -d /app -s /sbin/nologin floci
|
|
|
|
RUN mkdir -p /app/data \
|
|
&& chown -R 1001:root /app \
|
|
&& chmod -R g+rwX /app
|
|
VOLUME /app/data
|
|
|
|
EXPOSE 4566
|
|
|
|
HEALTHCHECK --interval=5s --timeout=3s --retries=5 \
|
|
CMD bash -c 'echo -e "GET /_floci/health HTTP/1.0\r\nHost: localhost\r\n\r\n" > /dev/tcp/localhost/4566' || exit 1
|
|
|
|
ARG VERSION=latest
|
|
ENV FLOCI_VERSION=${VERSION}
|
|
ENV FLOCI_STORAGE_PERSISTENT_PATH=/app/data
|
|
|
|
COPY --chmod=755 --from=build /app/target/*-runner /app/application
|
|
COPY --chmod=755 docker/entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
|
COPY --chmod=755 docker/localstack-parity.sh /usr/local/bin/localstack-parity.sh
|
|
|
|
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
|
CMD ["/app/application"]
|