code.pablomurad.com

bbs-hammer

SSH BBS with forums, chat, door games, retro terminals and a weather service, written in Go

Dockerfile raw
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# Lychee / DuckDB are pinned; bump ARG + SHA256 together.
# TARGETARCH is amd64 or arm64 (BuildKit).
# Lychee uses the musl build: the gnu artifact needs glibc 2.38+, Bookworm is 2.36.

# ---------------------------------------------------------------------------
# host-tools: download verified CLIs only (no rustc, no DuckDB source)
# ---------------------------------------------------------------------------
FROM debian:bookworm-slim AS host-tools

ARG TARGETARCH
ARG LYCHEE_VERSION=0.24.2
ARG DUCKDB_VERSION=1.5.5

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    curl \
    unzip \
    binutils \
    && rm -rf /var/lib/apt/lists/*

RUN set -eux; \
    case "${TARGETARCH}" in \
      amd64) \
        lychee_triple=x86_64-unknown-linux-musl; \
        lychee_sha256=73657a111819a30c47c08352896796f23d64e4eb2b3ed39b6d32149241566fc5; \
        duckdb_arch=amd64; \
        duckdb_sha256=08c0ca117111fcede14239d0093792352befdc174218c344d232c13279643d05; \
        ;; \
      arm64) \
        lychee_triple=aarch64-unknown-linux-musl; \
        lychee_sha256=5d0b0e3aeab240f41920c633a6eaf97599be6eedda034b36e858ede7dba5e535; \
        duckdb_arch=arm64; \
        duckdb_sha256=02163197027a42149147364d31fa67cac82108517a4be43304a1cc226eaef07a; \
        ;; \
      *) echo "unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
    esac; \
    curl -fsSL -o /tmp/lychee.tar.gz \
      "https://github.com/lycheeverse/lychee/releases/download/lychee-v${LYCHEE_VERSION}/lychee-${lychee_triple}.tar.gz"; \
    echo "${lychee_sha256}  /tmp/lychee.tar.gz" | sha256sum -c -; \
    mkdir -p /tmp/lychee && tar -xzf /tmp/lychee.tar.gz -C /tmp/lychee; \
    lychee_bin="$(find /tmp/lychee -type f -name lychee | head -n 1)"; \
    test -n "${lychee_bin}"; \
    install -m 0755 "${lychee_bin}" /usr/local/bin/lychee; \
    curl -fsSL -o /tmp/duckdb.zip \
      "https://github.com/duckdb/duckdb/releases/download/v${DUCKDB_VERSION}/duckdb_cli-linux-${duckdb_arch}.zip"; \
    echo "${duckdb_sha256}  /tmp/duckdb.zip" | sha256sum -c -; \
    unzip -q /tmp/duckdb.zip -d /tmp/duckdb; \
    install -m 0755 /tmp/duckdb/duckdb /usr/local/bin/duckdb; \
    strip /usr/local/bin/lychee /usr/local/bin/duckdb; \
    rm -rf /tmp/lychee.tar.gz /tmp/lychee /tmp/duckdb.zip /tmp/duckdb

# ---------------------------------------------------------------------------
# builder: fonts + cgo binary (production image only)
# ---------------------------------------------------------------------------
FROM golang:1.26-bookworm AS builder

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
    bash \
    rsync \
    gcc \
    libc6-dev \
    fontconfig \
    fonts-dejavu-core \
    fonts-noto-core \
    fonts-noto-cjk \
    fonts-wqy-zenhei \
    fonts-symbola \
    fonts-motoya-l-cedar \
    fonts-lexi-gulim \
    && rm -rf /var/lib/apt/lists/*

COPY go.mod go.sum ./
RUN go mod tidy && go mod download

COPY . .
RUN bash build.sh build

# ---------------------------------------------------------------------------
# live: golang + host CLIs, source bind-mounted (see compose.yaml)
# ---------------------------------------------------------------------------
FROM golang:1.26-bookworm AS live

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    iputils-ping \
    mtr-tiny \
    && rm -rf /var/lib/apt/lists/*

COPY --from=host-tools /usr/local/bin/lychee /usr/local/bin/lychee
COPY --from=host-tools /usr/local/bin/duckdb /usr/local/bin/duckdb

WORKDIR /app
EXPOSE 2222 2324 8080
CMD ["/app/srv", "srv", "config.local.yaml"]

# ---------------------------------------------------------------------------
# runtime: the default target, debian slim, no compiler
# ---------------------------------------------------------------------------
FROM debian:bookworm-slim AS runtime

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    iputils-ping \
    mtr-tiny \
    && rm -rf /var/lib/apt/lists/* \
    && useradd --create-home --uid 1000 --shell /usr/sbin/nologin wttr \
    && mkdir -p /app/cache /app/share/datasets \
    && chown -R wttr:wttr /app

COPY --from=host-tools /usr/local/bin/lychee /usr/local/bin/lychee
COPY --from=host-tools /usr/local/bin/duckdb /usr/local/bin/duckdb
COPY --from=builder /app/srv /app/srv
COPY share/datasets /app/share/datasets

ENV WTTR_MYDIR="/app"
ENV WTTR_GEOLITE="/app/GeoLite2-City.mmdb"
ENV WTTR_LISTEN_HOST="0.0.0.0"
ENV WTTR_LISTEN_PORT="8080"

WORKDIR /app
USER wttr
EXPOSE 8080 2222 2324
CMD ["/app/srv", "srv", "config.yaml"]

# ---------------------------------------------------------------------------
# fceumm: the NES emulator core nesdoor plays through (libretro, GPL-2.0),
# built against Bookworm's glibc. Pinned; bump the commit to update.
# ---------------------------------------------------------------------------
FROM debian:bookworm AS fceumm

ARG FCEUMM_COMMIT=7a542dab1e87679921962a9f056186eca425c0c2

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    git \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

RUN set -eux; \
    git init /src; cd /src; \
    git fetch --depth 1 https://github.com/libretro/libretro-fceumm "${FCEUMM_COMMIT}"; \
    git checkout FETCH_HEAD; \
    git archive --format=tar.gz --prefix=libretro-fceumm/ -o /src/libretro-fceumm-source.tar.gz HEAD; \
    make -j"$(nproc)"; \
    strip fceumm_libretro.so

# ---------------------------------------------------------------------------
# nesroms: the free homebrew games from games/catalog.yaml, hash-checked
# ---------------------------------------------------------------------------
FROM golang:1.26-bookworm AS nesroms

WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY games games
COPY tools/fetchroms tools/fetchroms
RUN go run ./tools/fetchroms -out /out/roms

# ---------------------------------------------------------------------------
# games: runtime plus NES games through nesdoor, a separate GPL-2.0 program
# Hammer runs as a child process (bbs.games). Pinned; bump the commit to
# update. The production compose builds this target.
# ---------------------------------------------------------------------------
FROM runtime AS games

ARG NESDOOR_COMMIT=39a0065508177a6e7bb6d2538356697fa0129c7c
ARG NUMPY_VERSION=2.2.6
# linecast (MIT) draws [k] sky & almanac; pure Python, no other packages.
ARG LINECAST_VERSION=2.10.2

USER root
RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends python3 python3-venv git; \
    git init /opt/nesdoor; cd /opt/nesdoor; \
    git fetch --depth 1 https://github.com/AlexCorris/nesdoor "${NESDOOR_COMMIT}"; \
    git checkout FETCH_HEAD; \
    rm -rf .git native-win32; \
    python3 -m venv /opt/nesdoor/venv; \
    /opt/nesdoor/venv/bin/pip install --no-cache-dir "numpy==${NUMPY_VERSION}"; \
    python3 -m venv /opt/linecast/venv; \
    /opt/linecast/venv/bin/pip install --no-cache-dir "linecast==${LINECAST_VERSION}"; \
    apt-get purge -y git; \
    apt-get autoremove -y; \
    rm -rf /var/lib/apt/lists/*

COPY --from=fceumm /src/fceumm_libretro.so /opt/nesdoor/fceumm_libretro.so
# GPL-2.0: the core's source travels with the binary.
COPY --from=fceumm /src/libretro-fceumm-source.tar.gz /usr/share/doc/libretro-fceumm/
# The catalog's games; Hammer copies them into romsDir (/app/games/roms,
# usually a volume) at startup, where operators add their own .nes files.
COPY --from=nesroms /out/roms /app/games/catalog

# nesdoor writes nesdoor.ini, saves/ and sessions/ in its own folder.
RUN mkdir -p /opt/nesdoor/saves /opt/nesdoor/sessions /app/cache/doors /app/cache/linecast /app/games/roms \
    && chown -R wttr:wttr /opt/nesdoor /app/cache /app/games

USER wttr

# ---------------------------------------------------------------------------
# full: games plus DOSBox for DOS doors (bbs.dosbox, type: dos). DOSBox
# runs headless on SDL's dummy video driver, so no X server is needed, and
# only while someone plays. The doors and the FOSSIL driver are the
# operator's: put them under /app/doors (a volume).
# ---------------------------------------------------------------------------
FROM games AS full

USER root
RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends dosbox; \
    rm -rf /var/lib/apt/lists/*; \
    mkdir -p /app/doors; \
    chown wttr:wttr /app/doors

USER wttr

# ---------------------------------------------------------------------------
# A plain `docker build` still produces the runtime image, without games.
# ---------------------------------------------------------------------------
FROM runtime AS default