-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.build
More file actions
136 lines (123 loc) · 3.92 KB
/
Dockerfile.build
File metadata and controls
136 lines (123 loc) · 3.92 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Multi-stage Dockerfile for building ChatrixCD with Nuitka
# This Dockerfile uses BuildKit for better caching and build optimization
# Supports x86_64, i686, and arm64 architectures
# Builds Python from source with static libraries to fix symbol resolution issues
FROM alpine:3.21 AS python-builder
# Install dependencies needed to build Python from source
RUN apk add --no-cache \
build-base \
gcc \
g++ \
musl-dev \
linux-headers \
libffi-dev \
openssl-dev \
zlib-dev \
bzip2-dev \
readline-dev \
sqlite-dev \
xz-dev \
ncurses-dev \
tk-dev \
expat-dev \
gdbm-dev \
wget \
ca-certificates
# Download and build Python with static libraries
# Using Python 3.12.x for consistency with the project
ARG PYTHON_VERSION=3.12.8
ARG PYTHON_OPTIMIZE=no
RUN --mount=type=cache,target=/tmp/python-build \
cd /tmp && \
if [ ! -f /tmp/python-build/Python-${PYTHON_VERSION}.tar.xz ]; then \
wget -O /tmp/python-build/Python-${PYTHON_VERSION}.tar.xz \
https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz; \
fi && \
tar xf /tmp/python-build/Python-${PYTHON_VERSION}.tar.xz && \
cd Python-${PYTHON_VERSION} && \
# Configure Python with static libraries
# Note: --enable-optimizations and --with-lto significantly increase build time
# They can be disabled for faster builds by setting PYTHON_OPTIMIZE=no
if [ "${PYTHON_OPTIMIZE}" = "yes" ]; then \
./configure \
--prefix=/opt/python-static \
--enable-optimizations \
--with-lto \
--disable-shared \
--enable-static=yes \
--with-static-libpython \
LDFLAGS="-static-libgcc"; \
else \
./configure \
--prefix=/opt/python-static \
--disable-shared \
--enable-static=yes \
--with-static-libpython \
LDFLAGS="-static-libgcc"; \
fi && \
make -j$(nproc) && \
make install && \
cd / && \
rm -rf /tmp/Python-${PYTHON_VERSION}
FROM alpine:3.21 AS builder
# Install build dependencies
RUN apk add --no-cache \
build-base \
gcc \
g++ \
musl-dev \
patchelf \
ccache \
linux-headers \
libffi-dev \
openssl-dev \
zlib-dev \
bzip2-dev \
readline-dev \
sqlite-dev \
xz-dev \
ncurses-dev \
rust \
cargo \
git \
make
# Copy static Python from python-builder stage
COPY --from=python-builder /opt/python-static /opt/python-static
# Set up ccache for faster rebuilds
ENV CCACHE_DIR=/root/.ccache
ENV PATH=/usr/lib/ccache/bin:$PATH
# Use the static Python installation
ENV PATH="/opt/python-static/bin:$PATH"
ENV PYTHONHOME="/opt/python-static"
# Copy requirements and install Python dependencies
WORKDIR /src
COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
python3 -m pip install --upgrade pip && \
python3 -m pip install -r requirements.txt && \
python3 -m pip install nuitka ordered-set
# Copy source code
COPY . .
# Build with Nuitka - using standalone mode for all architectures for consistency
# Using static Python to fix symbol resolution issues with musl libc
ARG ARCH
ARG ENABLE_LTO=yes
RUN --mount=type=cache,target=/root/.ccache \
python3 -m nuitka --mode=standalone \
--output-dir=. \
--enable-plugin=anti-bloat \
--assume-yes-for-downloads \
--static-libpython=yes \
--python-flag=no_site \
--lto=${ENABLE_LTO} \
--jobs=4 \
--linux-icon=assets/icon.png \
--include-data-dir=assets=assets \
chatrixcd/main.py && \
# Rename the output executable and directory for consistency \
mv main.dist chatrixcd-linux-${ARCH}.dist && \
mv chatrixcd-linux-${ARCH}.dist/main.bin chatrixcd-linux-${ARCH}.dist/chatrixcd
# Final stage - copy the standalone directory
FROM scratch AS export
ARG ARCH
COPY --from=builder /src/chatrixcd-linux-${ARCH}.dist /chatrixcd-linux-${ARCH}.dist