Files
easy-wallet/contrib/windows/Dockerfile
Davide Grilli 9115faa6c8 fix(packaging): harden PyInstaller CLI bundling on Linux and Windows
- Add explicit hidden imports/collect rules for coincurve, bip_utils and src modules
- Introduce Docker smoke tests for hd_generate and p2pkh to fail fast on missing runtime deps
- Refactor cli.py to lazy-load command modules and avoid global startup crashes from optional deps
- Use pseudo-TTY script wrapper for Wine smoke tests to prevent Invalid handle failures
2026-03-10 12:26:19 +01:00

112 lines
4.5 KiB
Docker

FROM node:22.14.0-bookworm
ENV WINEPREFIX=/home/node/.wine
ENV WINEDEBUG=-all
# System dependencies + Wine + Xvfb
RUN dpkg --add-architecture i386 && \
apt-get update && apt-get install -y --no-install-recommends \
wine wine32 wine64 \
python3 python3-pip python3-venv libpython3.11 \
binutils wget xvfb xauth cabextract ca-certificates unzip \
&& rm -rf /var/lib/apt/lists/*
# Install winetricks manually (removed from Debian bookworm apt)
RUN wget -q https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks \
-O /usr/local/bin/winetricks && \
chmod +x /usr/local/bin/winetricks
WORKDIR /build
# Copy repo
COPY --chown=node:node . .
RUN chown -R node:node /build
# Wine/winetricks are unstable as root; use the image's non-root user.
USER node
# Python venv (Linux, for local tools only)
RUN python3 -m venv venv && \
venv/bin/pip install --no-cache-dir -r requirements.txt pyinstaller
# Pre-download Windows wheels so Wine Python can install fully offline.
RUN mkdir -p wheelhouse && \
venv/bin/pip freeze > win-lock.txt && \
printf "pip\nsetuptools\nwheel\n" >> win-lock.txt && \
while read -r pkg; do \
venv/bin/pip download \
--dest wheelhouse \
--platform win_amd64 --implementation cp --python-version 3.11 --abi cp311 \
--no-deps "$pkg"; \
done < win-lock.txt && \
# PyInstaller has Windows-only deps not present in Linux freeze output.
for win_pkg in pefile pywin32-ctypes colorama; do \
venv/bin/pip download \
--dest wheelhouse \
--platform win_amd64 --implementation cp --python-version 3.11 --abi cp311 \
--no-deps "$win_pkg"; \
done
# Bootstrap Wine prefix
RUN wineboot --init 2>/dev/null || true
# vcrun2019 currently returns status 243 on Wine 8 (Debian bookworm).
# Keep it best-effort so the build can proceed if Python installer already bundles needed runtime.
RUN xvfb-run -a winetricks -q vcrun2019 || true
# Install Python for Windows using embeddable zip (avoids installer/runtime failures under Wine)
RUN mkdir -p "$WINEPREFIX/drive_c/Python311" && \
wget -q "https://www.python.org/ftp/python/3.11.9/python-3.11.9-embed-amd64.zip" -O /tmp/pyembed.zip && \
unzip -q /tmp/pyembed.zip -d "$WINEPREFIX/drive_c/Python311" && \
rm /tmp/pyembed.zip && \
sed -i 's/^#import site/import site/' "$WINEPREFIX/drive_c/Python311/python311._pth" && \
wget -q "https://bootstrap.pypa.io/pip/pip.pyz" -O "$WINEPREFIX/drive_c/pip.pyz" && \
xvfb-run -a wine "C:\\Python311\\python.exe" --version
# Install Python packaging toolchain first (needed for sdist like crcmod).
RUN xvfb-run -a wine "C:\\Python311\\python.exe" "C:\\pip.pyz" install --no-index \
--find-links="Z:\\build\\wheelhouse" \
pip setuptools wheel
# Install Python deps + PyInstaller under Wine Python
RUN xvfb-run -a wine "C:\\Python311\\python.exe" "C:\\pip.pyz" install --no-index --no-build-isolation \
--find-links="Z:\\build\\wheelhouse" \
-r "Z:\\build\\win-lock.txt"
# Compile Python CLI into Windows binary
RUN xvfb-run -a wine "C:\\Python311\\python.exe" -m PyInstaller \
--onefile --name cli \
--hidden-import _cffi_backend \
--hidden-import coincurve._cffi_backend \
--hidden-import src.crypto \
--hidden-import src.hd_wallet \
--hidden-import src.p2pk \
--hidden-import src.p2pkh \
--hidden-import src.p2sh \
--hidden-import src.p2wpkh \
--hidden-import src.p2tr \
--hidden-import src.single_wallet \
--collect-data bip_utils \
--collect-submodules src \
--collect-submodules coincurve \
--collect-binaries coincurve \
--collect-data coincurve \
src/cli.py && \
script -qec 'xvfb-run -a wine cmd /c "Z:\\build\\dist\\cli.exe hd_generate {}"' /tmp/cli-hd-generate.log && \
cat /tmp/cli-hd-generate.log && \
grep -Eq '"ok"[[:space:]]*:[[:space:]]*true' /tmp/cli-hd-generate.log && \
script -qec 'xvfb-run -a wine cmd /c "Z:\\build\\dist\\cli.exe p2pkh {}"' /tmp/cli-p2pkh.log && \
cat /tmp/cli-p2pkh.log && \
grep -Eq '"ok"[[:space:]]*:[[:space:]]*true' /tmp/cli-p2pkh.log && \
mkdir -p frontend/resources && \
cp dist/cli.exe frontend/resources/cli.exe
# JS dependencies + electron-builder
RUN cd frontend && npm ci && npm install --no-save electron-builder
# Build Windows installer + standalone portable executable
RUN cd frontend && npx vite build && npx electron-builder --win nsis portable --publish never
# Export build artifacts
CMD cp frontend/release/*.exe /out/