Skip to content

Commit e9d7f15

Browse files
committed
Minimize container image, split out HERE docs to local files
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 0ea4e97 commit e9d7f15

File tree

3 files changed

+88
-82
lines changed

3 files changed

+88
-82
lines changed

Dockerfile

Lines changed: 26 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
# Build stage
2+
FROM alpine:latest AS builder
3+
4+
RUN apk add --no-cache \
5+
gcc \
6+
musl-dev \
7+
make \
8+
pkgconf \
9+
sdl2-dev \
10+
sdl2_ttf-dev \
11+
sdl2_image-dev \
12+
sdl2_mixer-dev
13+
14+
WORKDIR /build
15+
16+
COPY demo.c Makefile topaz-8.otf *.png music.mod* ./
17+
18+
RUN make
19+
20+
# Runtime stage
121
FROM alpine:latest
222

323
RUN apk add --no-cache \
424
sdl2 \
5-
sdl2-dev \
625
sdl2_ttf \
7-
sdl2_ttf-dev \
826
sdl2_image \
9-
sdl2_image-dev \
1027
sdl2_mixer \
11-
sdl2_mixer-dev \
1228
libpulse \
1329
libxmp \
1430
libdrm \
@@ -21,88 +37,16 @@ RUN apk add --no-cache \
2137
xf86-video-modesetting \
2238
xf86-input-libinput \
2339
xdpyinfo \
24-
xinit \
25-
gcc \
26-
musl-dev \
27-
make \
28-
vim
40+
xinit
2941

3042
WORKDIR /app
3143

32-
COPY demo.c Makefile topaz-8.otf *.png music.mod* ./
33-
34-
RUN make
35-
36-
# Create minimal X config for GPU acceleration
37-
RUN mkdir -p /etc/X11 && cat > /etc/X11/xorg.conf << 'EOF'
38-
Section "ServerFlags"
39-
Option "DontVTSwitch" "true"
40-
Option "BlankTime" "0"
41-
Option "StandbyTime" "0"
42-
Option "SuspendTime" "0"
43-
Option "OffTime" "0"
44-
EndSection
45-
46-
Section "Device"
47-
Identifier "Card0"
48-
Driver "modesetting"
49-
EndSection
50-
51-
Section "Screen"
52-
Identifier "Screen0"
53-
Device "Card0"
54-
EndSection
55-
EOF
56-
57-
# Create startup script
58-
RUN cat > /app/start.sh << 'EOF'
59-
#!/bin/sh
60-
# Smart startup: use existing X or start our own
61-
62-
cleanup()
63-
{
64-
echo "Shutting down..."
65-
if [ -n "$DEMOPID" ]; then
66-
kill $DEMOPID 2>/dev/null
67-
wait $DEMOPID 2>/dev/null
68-
fi
69-
if [ -n "$XPID" ]; then
70-
kill $XPID 2>/dev/null
71-
wait $XPID 2>/dev/null
72-
fi
73-
exit 0
74-
}
75-
76-
# Set up signal handlers
77-
trap cleanup TERM INT
78-
79-
# Check if X server is already available
80-
if xdpyinfo -display "${DISPLAY:-:0}" >/dev/null 2>&1; then
81-
echo "Using existing X server on $DISPLAY"
82-
exec ./demo "$@"
83-
else
84-
echo "No X server found, starting embedded X server..."
85-
# Start X server in background
86-
Xorg -noreset +extension GLX +extension RANDR +extension RENDER -logfile /tmp/xorg.log -config /etc/X11/xorg.conf :0 &
87-
XPID=$!
88-
sleep 2
89-
90-
# Run demo in background so we can handle signals
91-
DISPLAY=:0 ./demo "$@" &
92-
DEMOPID=$!
93-
94-
# Wait for demo to finish
95-
wait $DEMOPID
96-
EXITCODE=$?
97-
98-
# Clean up X server
99-
kill $XPID 2>/dev/null
100-
wait $XPID 2>/dev/null
101-
exit $EXITCODE
102-
fi
103-
EOF
44+
# Copy compiled binary from builder
45+
COPY --from=builder /build/demo .
10446

105-
RUN chmod +x /app/start.sh
47+
# Copy X11 config and startup script
48+
COPY xorg.conf /etc/X11/xorg.conf
49+
COPY start.sh /app/start.sh
10650

10751
ENV DISPLAY=:0
10852

start.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
# Smart startup: use existing X or start our own
3+
4+
cleanup()
5+
{
6+
echo "Shutting down..."
7+
if [ -n "$DEMOPID" ]; then
8+
kill $DEMOPID 2>/dev/null
9+
wait $DEMOPID 2>/dev/null
10+
fi
11+
if [ -n "$XPID" ]; then
12+
kill $XPID 2>/dev/null
13+
wait $XPID 2>/dev/null
14+
fi
15+
exit 0
16+
}
17+
18+
# Set up signal handlers
19+
trap cleanup TERM INT
20+
21+
# Check if X server is already available
22+
if xdpyinfo -display "${DISPLAY:-:0}" >/dev/null 2>&1; then
23+
echo "Using existing X server on $DISPLAY"
24+
exec ./demo "$@"
25+
else
26+
echo "No X server found, starting embedded X server..."
27+
# Start X server in background
28+
Xorg -noreset +extension GLX +extension RANDR +extension RENDER \
29+
-logfile /tmp/xorg.log -config /etc/X11/xorg.conf :0 &
30+
XPID=$!
31+
sleep 2
32+
33+
# Run demo in background so we can handle signals
34+
DISPLAY=:0 ./demo "$@" &
35+
DEMOPID=$!
36+
37+
# Wait for demo to finish
38+
wait $DEMOPID
39+
EXITCODE=$?
40+
41+
# Clean up X server
42+
kill $XPID 2>/dev/null
43+
wait $XPID 2>/dev/null
44+
exit $EXITCODE
45+
fi

xorg.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Section "ServerFlags"
2+
Option "DontVTSwitch" "true"
3+
Option "BlankTime" "0"
4+
Option "StandbyTime" "0"
5+
Option "SuspendTime" "0"
6+
Option "OffTime" "0"
7+
EndSection
8+
9+
Section "Device"
10+
Identifier "Card0"
11+
Driver "modesetting"
12+
EndSection
13+
14+
Section "Screen"
15+
Identifier "Screen0"
16+
Device "Card0"
17+
EndSection

0 commit comments

Comments
 (0)