Skip to content

Commit 6ed0da0

Browse files
committed
WIP split builder and runtime images
1 parent 7f76474 commit 6ed0da0

File tree

6 files changed

+943
-0
lines changed

6 files changed

+943
-0
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# syntax=docker/dockerfile:1
2+
#
3+
# Invenio Base Docker Images
4+
#
5+
# Build targets:
6+
# docker build --target builder -t inveniosoftware/almalinux:1-builder .
7+
# docker build --target runtime -t inveniosoftware/almalinux:1-runtime .
8+
# docker build --target debug -t inveniosoftware/almalinux:1-debug .
9+
#
10+
# Copyright (C) 2018-2025 CERN.
11+
# Copyright (C) 2022 Graz University of Technology.
12+
# Copyright (C) 2022 University of Münster.
13+
# Copyright (C) 2023-2024 KTH Royal Institute of Technology.
14+
#
15+
# Invenio is free software; you can redistribute it and/or modify it
16+
# under the terms of the MIT License; see LICENSE file for more details.
17+
18+
ARG LINUX_VERSION=9
19+
ARG PYTHON_VERSION=3.14
20+
ARG NODE_VERSION=22
21+
22+
# =============================================================================
23+
# BASE: Common configuration shared by all variants
24+
# =============================================================================
25+
FROM almalinux:${LINUX_VERSION} AS base
26+
27+
ARG PYTHON_VERSION
28+
29+
# Locale configuration
30+
RUN dnf install -y glibc-langpack-en && \
31+
dnf clean all
32+
33+
ENV LANG=en_US.UTF-8 \
34+
LANGUAGE=en_US:en \
35+
LC_ALL=en_US.UTF-8
36+
37+
# Python configuration
38+
ENV PYTHONUNBUFFERED=1 \
39+
PYTHONDONTWRITEBYTECODE=1 \
40+
PYTHONFAULTHANDLER=1
41+
42+
# Working directory structure
43+
ENV WORKING_DIR=/opt/invenio \
44+
INVENIO_INSTANCE_PATH=/opt/invenio/var/instance
45+
46+
# Create invenio user (UID 1000 for compatibility with common setups)
47+
ARG INVENIO_USER_ID=1000
48+
RUN useradd --uid ${INVENIO_USER_ID} --gid 0 --create-home invenio
49+
50+
# Create directory structure
51+
RUN mkdir -p ${WORKING_DIR}/src \
52+
${INVENIO_INSTANCE_PATH}/data \
53+
${INVENIO_INSTANCE_PATH}/archive \
54+
${INVENIO_INSTANCE_PATH}/static && \
55+
chown -R invenio:0 ${WORKING_DIR} && \
56+
chmod -R g=u ${WORKING_DIR}
57+
58+
WORKDIR ${WORKING_DIR}/src
59+
60+
# Install uv for Python management
61+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
62+
63+
# Install Python via uv (standalone builds, works for any version)
64+
ENV UV_PYTHON_INSTALL_DIR=/opt/python
65+
RUN uv python install ${PYTHON_VERSION} && \
66+
ln -sfn $(uv python find ${PYTHON_VERSION}) /usr/local/bin/python && \
67+
ln -sfn $(uv python find ${PYTHON_VERSION}) /usr/local/bin/python3
68+
69+
# uv configuration
70+
ENV UV_PYTHON=${PYTHON_VERSION} \
71+
UV_COMPILE_BYTECODE=1 \
72+
UV_LINK_MODE=copy
73+
74+
# =============================================================================
75+
# RUNTIME: Minimal production image with only runtime dependencies
76+
# =============================================================================
77+
FROM base AS runtime
78+
79+
ARG TARGETARCH
80+
81+
# Enable EPEL and CRB for additional packages
82+
RUN dnf install -y dnf-plugins-core && \
83+
dnf config-manager --set-enabled crb && \
84+
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \
85+
dnf clean all
86+
87+
# Install runtime-only system libraries
88+
# Note: These are the RUNTIME packages (no -devel suffix)
89+
RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=dnf-${TARGETARCH} \
90+
dnf install -y --setopt=install_weak_deps=False \
91+
# Runtime libraries (shared objects only, no headers)
92+
cairo \
93+
libffi \
94+
libpq \
95+
libxml2 \
96+
libxslt \
97+
ImageMagick-libs \
98+
openssl-libs \
99+
bzip2-libs \
100+
xz-libs \
101+
sqlite-libs \
102+
xmlsec1 \
103+
xmlsec1-openssl \
104+
# Fonts for PDF/image generation
105+
dejavu-sans-fonts \
106+
# Git (often needed at runtime for editable installs)
107+
git
108+
109+
# Labels
110+
LABEL org.opencontainers.image.title="Invenio Base (Runtime)" \
111+
org.opencontainers.image.description="Minimal runtime image for Invenio applications" \
112+
org.opencontainers.image.vendor="Invenio Software" \
113+
org.opencontainers.image.licenses="MIT"
114+
115+
# =============================================================================
116+
# BUILDER: Full toolchain for compiling Python/Node.js packages
117+
# =============================================================================
118+
FROM base AS builder
119+
120+
ARG NODE_VERSION
121+
ARG TARGETARCH
122+
123+
# Enable EPEL and CRB
124+
RUN dnf install -y dnf-plugins-core && \
125+
dnf config-manager --set-enabled crb && \
126+
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \
127+
dnf clean all
128+
129+
# Install build tools and development libraries
130+
RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=dnf-${TARGETARCH} \
131+
dnf install -y --setopt=install_weak_deps=False \
132+
# Build essentials
133+
gcc \
134+
gcc-c++ \
135+
make \
136+
pkgconf \
137+
# Development libraries (headers + static libs for compilation)
138+
cairo-devel \
139+
libffi-devel \
140+
libpq-devel \
141+
libxml2-devel \
142+
libxslt-devel \
143+
ImageMagick-devel \
144+
openssl-devel \
145+
bzip2-devel \
146+
xz-devel \
147+
sqlite-devel \
148+
xmlsec1-devel \
149+
xmlsec1-openssl-devel \
150+
# Other build dependencies
151+
git \
152+
# Fonts
153+
dejavu-sans-fonts
154+
155+
# Install Node.js with npm for asset building
156+
RUN curl -fsSL https://rpm.nodesource.com/setup_${NODE_VERSION}.x | bash - && \
157+
dnf install -y --setopt=install_weak_deps=False nodejs && \
158+
dnf clean all && \
159+
rm -rf /var/cache/dnf && \
160+
corepack enable
161+
162+
# Labels
163+
LABEL org.opencontainers.image.title="Invenio Base (Builder)" \
164+
org.opencontainers.image.description="Full toolchain for building Invenio applications" \
165+
org.opencontainers.image.vendor="Invenio Software" \
166+
org.opencontainers.image.licenses="MIT"
167+
168+
# =============================================================================
169+
# DEBUG: Runtime + debugging/inspection tools
170+
# =============================================================================
171+
FROM runtime AS debug
172+
173+
ARG TARGETARCH
174+
175+
# Install debugging and inspection tools
176+
RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=dnf-${TARGETARCH} \
177+
dnf install -y --allowerasing --setopt=install_weak_deps=False \
178+
# Process inspection
179+
procps-ng \
180+
htop \
181+
strace \
182+
lsof \
183+
# File inspection
184+
file \
185+
less \
186+
vim-minimal \
187+
# Disk/IO monitoring
188+
iotop \
189+
iftop \
190+
# Network debugging
191+
tcpdump \
192+
bind-utils \
193+
net-tools \
194+
curl \
195+
wget
196+
197+
LABEL org.opencontainers.image.title="Invenio Base (Debug)" \
198+
org.opencontainers.image.description="Runtime image with debugging tools for troubleshooting" \
199+
org.opencontainers.image.vendor="Invenio Software" \
200+
org.opencontainers.image.licenses="MIT"
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# syntax=docker/dockerfile:1
2+
#
3+
# Invenio Base Docker Images (Debian variant)
4+
#
5+
# Build targets:
6+
# docker build --target builder -t inveniosoftware/debian:1-builder .
7+
# docker build --target runtime -t inveniosoftware/debian:1-runtime .
8+
# docker build --target debug -t inveniosoftware/debian:1-debug .
9+
#
10+
# Copyright (C) 2018-2025 CERN.
11+
#
12+
# Invenio is free software; you can redistribute it and/or modify it
13+
# under the terms of the MIT License; see LICENSE file for more details.
14+
15+
ARG PYTHON_VERSION=3.14
16+
ARG NODE_VERSION=22
17+
ARG DEBIAN_VERSION=bookworm
18+
19+
# =============================================================================
20+
# BASE: Common configuration shared by all variants
21+
# =============================================================================
22+
FROM debian:${DEBIAN_VERSION}-slim AS base
23+
24+
ARG PYTHON_VERSION
25+
26+
# Locale configuration
27+
RUN apt-get update && apt-get install -y --no-install-recommends locales ca-certificates && \
28+
sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
29+
locale-gen && \
30+
rm -rf /var/lib/apt/lists/*
31+
32+
ENV LANG=en_US.UTF-8 \
33+
LANGUAGE=en_US:en \
34+
LC_ALL=en_US.UTF-8
35+
36+
# Python configuration
37+
ENV PYTHONUNBUFFERED=1 \
38+
PYTHONDONTWRITEBYTECODE=1 \
39+
PYTHONFAULTHANDLER=1
40+
41+
# Working directory structure
42+
ENV WORKING_DIR=/opt/invenio \
43+
INVENIO_INSTANCE_PATH=/opt/invenio/var/instance
44+
45+
# Create invenio user
46+
ARG INVENIO_USER_ID=1000
47+
RUN useradd --uid ${INVENIO_USER_ID} --gid 0 --create-home invenio
48+
49+
# Create directory structure
50+
RUN mkdir -p ${WORKING_DIR}/src \
51+
${INVENIO_INSTANCE_PATH}/data \
52+
${INVENIO_INSTANCE_PATH}/archive \
53+
${INVENIO_INSTANCE_PATH}/static && \
54+
chown -R invenio:0 ${WORKING_DIR} && \
55+
chmod -R g=u ${WORKING_DIR}
56+
57+
WORKDIR ${WORKING_DIR}/src
58+
59+
# Install uv for Python management
60+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
61+
62+
# Install Python via uv (standalone builds, works for any version)
63+
ENV UV_PYTHON_INSTALL_DIR=/opt/python
64+
RUN uv python install ${PYTHON_VERSION} && \
65+
ln -sfn $(uv python find ${PYTHON_VERSION}) /usr/local/bin/python && \
66+
ln -sfn $(uv python find ${PYTHON_VERSION}) /usr/local/bin/python3
67+
68+
# uv configuration
69+
ENV UV_PYTHON=${PYTHON_VERSION} \
70+
UV_COMPILE_BYTECODE=1 \
71+
UV_LINK_MODE=copy
72+
73+
# =============================================================================
74+
# RUNTIME: Minimal production image with only runtime dependencies
75+
# =============================================================================
76+
FROM base AS runtime
77+
78+
ARG TARGETARCH
79+
80+
# Install runtime-only system libraries
81+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \
82+
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=apt-lib-${TARGETARCH} \
83+
apt-get update && apt-get install -y --no-install-recommends \
84+
# Runtime libraries only (no -dev packages)
85+
libcairo2 \
86+
libffi8 \
87+
libpq5 \
88+
libxml2 \
89+
libxslt1.1 \
90+
libmagickwand-6.q16-6 \
91+
libssl3 \
92+
libbz2-1.0 \
93+
liblzma5 \
94+
libsqlite3-0 \
95+
libxmlsec1 \
96+
libxmlsec1-openssl \
97+
# Fonts
98+
fonts-dejavu \
99+
# Utilities
100+
git \
101+
curl
102+
103+
LABEL org.opencontainers.image.title="Invenio Base Debian (Runtime)" \
104+
org.opencontainers.image.description="Minimal Debian-based runtime image for Invenio" \
105+
org.opencontainers.image.vendor="Invenio Software" \
106+
org.opencontainers.image.licenses="MIT"
107+
108+
# =============================================================================
109+
# BUILDER: Full toolchain for compiling Python/Node.js packages
110+
# =============================================================================
111+
FROM base AS builder
112+
113+
ARG NODE_VERSION
114+
ARG TARGETARCH
115+
116+
# Install build tools and development libraries
117+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \
118+
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=apt-lib-${TARGETARCH} \
119+
apt-get update && apt-get install -y --no-install-recommends \
120+
# Build essentials
121+
build-essential \
122+
pkg-config \
123+
# Development libraries (with headers)
124+
libcairo2-dev \
125+
libffi-dev \
126+
libpq-dev \
127+
libxml2-dev \
128+
libxslt1-dev \
129+
libmagickwand-dev \
130+
libssl-dev \
131+
libbz2-dev \
132+
liblzma-dev \
133+
libsqlite3-dev \
134+
libxmlsec1-dev \
135+
libxmlsec1-openssl \
136+
# Other
137+
git \
138+
curl \
139+
# Fonts
140+
fonts-dejavu
141+
142+
# Install Node.js
143+
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - && \
144+
apt-get install -y --no-install-recommends nodejs && \
145+
corepack enable && \
146+
rm -rf /var/lib/apt/lists/*
147+
148+
LABEL org.opencontainers.image.title="Invenio Base Debian (Builder)" \
149+
org.opencontainers.image.description="Full Debian-based toolchain for building Invenio" \
150+
org.opencontainers.image.vendor="Invenio Software" \
151+
org.opencontainers.image.licenses="MIT"
152+
153+
# =============================================================================
154+
# DEBUG: Runtime + debugging tools
155+
# =============================================================================
156+
FROM runtime AS debug
157+
158+
ARG TARGETARCH
159+
160+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-${TARGETARCH} \
161+
--mount=type=cache,target=/var/lib/apt,sharing=locked,id=apt-lib-${TARGETARCH} \
162+
apt-get update && apt-get install -y --no-install-recommends \
163+
# Process inspection
164+
procps \
165+
htop \
166+
strace \
167+
lsof \
168+
# File inspection
169+
file \
170+
less \
171+
vim-tiny \
172+
# Network debugging
173+
tcpdump \
174+
dnsutils \
175+
net-tools \
176+
wget \
177+
# I/O monitoring
178+
iotop \
179+
iftop
180+
181+
LABEL org.opencontainers.image.title="Invenio Base Debian (Debug)" \
182+
org.opencontainers.image.description="Debian runtime with debugging tools" \
183+
org.opencontainers.image.vendor="Invenio Software" \
184+
org.opencontainers.image.licenses="MIT"

0 commit comments

Comments
 (0)