-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.desktop
More file actions
133 lines (119 loc) · 4.18 KB
/
Dockerfile.desktop
File metadata and controls
133 lines (119 loc) · 4.18 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
# Stage 1: build js/bundle.js
FROM node:20-slim@sha256:7129e1780341f8dff603243d2b0cb9179c1716291ff6a86706946b629d3c544a AS builder
WORKDIR /build
COPY package.json package-lock.json* ./
# --ignore-scripts skips the nw postinstall (avoids downloading 200MB NW.js SDK in the build stage)
RUN npm ci --ignore-scripts
COPY js ./js
COPY src ./src
RUN npm run build
# Stage 2: desktop runtime
FROM ubuntu:22.04@sha256:c9672795a48854502d9dc0f1b719ac36dd99259a2f8ce425904a5cb4ae0d60d2
ARG NWJS_VERSION=0.109.1
ARG APP_VERSION=0.0.0
ARG TARGETARCH=amd64
LABEL maintainer="buzzcauldron <buzzcauldron@users.noreply.github.com>"
LABEL description="Visual Page Editor - Desktop application container"
LABEL org.opencontainers.image.title="Visual Page Editor"
LABEL org.opencontainers.image.version="${APP_VERSION}"
LABEL org.opencontainers.image.source="https://github.com/buzzcauldron/visual-page-editor"
# Install dependencies
RUN apt-get update --fix-missing && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
curl \
tar \
gzip \
ca-certificates \
libatomic1 \
libnss3 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libdbus-1-3 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
libpango-1.0-0 \
libcairo2 \
libatspi2.0-0 \
libxss1 \
libxtst6 \
x11-utils \
libgl1 \
libgl1-mesa-dri \
libgtk-3-0 \
xvfb \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Download and extract NW.js — selects linux-arm64 or linux-x64 based on TARGETARCH build arg
RUN case "${TARGETARCH}" in \
arm64) _nwjs_suffix="linux-arm64" ;; \
*) _nwjs_suffix="linux-x64" ;; \
esac && \
curl --retry 3 -fLSs -o /tmp/nwjs.tar.gz "https://dl.nwjs.io/v${NWJS_VERSION}/nwjs-sdk-v${NWJS_VERSION}-${_nwjs_suffix}.tar.gz" && \
tar -xzf /tmp/nwjs.tar.gz -C /tmp && \
mv /tmp/nwjs-sdk-v${NWJS_VERSION}-${_nwjs_suffix} /app/nwjs && \
rm -f /tmp/nwjs.tar.gz && \
chmod +x /app/nwjs/nw
# Copy application files
COPY package.json /app/
COPY html /app/html
COPY css /app/css
COPY js /app/js
COPY --from=builder /build/js/bundle.js /app/js/bundle.js
COPY examples /app/examples
COPY plugins /app/plugins
COPY xsd /app/xsd
COPY xslt /app/xslt
COPY bin /app/bin
# Some builds store XSD "pointers" instead of the actual schema files.
# Fetch the real schemas so the app can start without requiring a git submodule.
RUN mkdir -p /app/xsd/pageformat/old && \
if [ ! -s /app/xsd/pageformat/pagecontent_omnius.xsd ]; then \
curl --retry 3 -fLSs -o /app/xsd/pageformat/pagecontent_omnius.xsd \
"https://raw.githubusercontent.com/omni-us/pageformat/master/pagecontent_omnius.xsd"; \
fi && \
if [ ! -s /app/xsd/pageformat/old/pagecontent_searchink.xsd ]; then \
curl --retry 3 -fLSs -o /app/xsd/pageformat/old/pagecontent_searchink.xsd \
"https://raw.githubusercontent.com/omni-us/pageformat/master/old/pagecontent_searchink.xsd"; \
fi
# Create entrypoint script (avoid $(...) in heredoc to prevent shell syntax errors)
RUN cat > /app/entrypoint.sh << 'EOF' && chmod +x /app/entrypoint.sh
#!/bin/bash
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Visual Page Editor - Desktop Application"
echo "Usage: docker run --rm -it -e DISPLAY=... -v /tmp/.X11-unix:/tmp/.X11-unix -v YOUR_DIR:/workspace visual-page-editor [files...]"
exit 0
fi
# Use Xvfb if DISPLAY not set or unreachable
_need_xvfb=0
if [ -z "$DISPLAY" ]; then
_need_xvfb=1
elif ! xdpyinfo -display "$DISPLAY" >/dev/null 2>&1; then
_need_xvfb=1
fi
if [ "$_need_xvfb" = "1" ]; then
export DISPLAY=:99
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
XVFB_PID=$!
trap "kill $XVFB_PID 2>/dev/null || true" EXIT
_xvfb_tries=0
until xdpyinfo -display :99 >/dev/null 2>&1; do
_xvfb_tries=$((_xvfb_tries + 1))
[ "$_xvfb_tries" -ge 20 ] && echo "Warning: Xvfb did not start in time" >&2 && break
sleep 0.1
done
fi
# Run the application
/app/nwjs/nw --disable-gpu --disable-gpu-compositing /app "$@"
EOF
# Set environment variables
ENV NWJS_PATH=/app/nwjs/nw
ENV APP_PATH=/app
# Entrypoint
ENTRYPOINT ["/app/entrypoint.sh"]