-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
128 lines (109 loc) · 4.58 KB
/
Copy pathDockerfile
File metadata and controls
128 lines (109 loc) · 4.58 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
# syntax=docker/dockerfile:1.7
# ---------------------------------------------------------------------------
# MonoBucket — three-stage build producing one binary in a minimal runtime.
#
# 1. frontend : Node builds the SvelteKit dashboard to static files
# 2. backend : Alpine toolchain compiles the C++ engine, embedding (1)
# 3. runtime : the stripped binary plus only the shared libraries it needs
#
# Build:
# docker build -t monobucket:dev .
# ---------------------------------------------------------------------------
# --- Stage 1: dashboard ----------------------------------------------------
FROM node:22-alpine AS frontend
WORKDIR /src
COPY . .
# Playwright lingers as an unused devDependency and its postinstall would pull
# ~150 MB of browsers this stage has no use for.
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
# The dashboard is optional during early phases: if frontend/ has not been
# scaffolded yet, emit a placeholder so the backend stage still has something
# to embed and the image stays buildable.
RUN set -eu; \
if [ ! -f frontend/package.json ]; then \
mkdir -p frontend/build; \
printf '<!doctype html><meta charset="utf-8"><title>MonoBucket</title><p>Dashboard not built.\n' \
> frontend/build/index.html; \
else \
npm install -g pnpm@11; \
cd frontend && pnpm install --frozen-lockfile && pnpm run build; \
fi
# adapter-static must have produced an SPA entry point, otherwise the console
# would ship as an empty asset table and 404 at runtime.
RUN test -f frontend/build/index.html
# --- Stage 2: engine -------------------------------------------------------
FROM alpine:3.21 AS backend
# Off by default: the in-memory cache is the right answer for a single
# container, and a shared cache nobody asked for is dependency for its own sake.
# docker build --build-arg MONOBUCKET_ENABLE_REDIS=ON .
ARG MONOBUCKET_ENABLE_REDIS=OFF
RUN apk add --no-cache \
build-base \
cmake \
ninja \
git \
linux-headers \
openssl-dev \
zlib-dev \
brotli-dev \
# The CLI, not the library: the asset embedder shells out to `brotli` and
# `gzip` (busybox) to pre-compress the dashboard once at build time. Both
# are optional — without them the table simply carries no variants — but
# a release image should ship them.
brotli \
jsoncpp-dev \
util-linux-dev \
c-ares-dev \
rocksdb-dev \
&& if [ "$MONOBUCKET_ENABLE_REDIS" = "ON" ]; then apk add --no-cache hiredis-dev; fi
WORKDIR /src
COPY . .
COPY --from=frontend /src/frontend/build ./frontend/build
RUN cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DMONOBUCKET_BUILD_TESTS=OFF \
-DMONOBUCKET_EMBED_FRONTEND=ON \
-DMONOBUCKET_ENABLE_LTO=ON \
-DMONOBUCKET_STATIC_LINK=ON \
-DMONOBUCKET_ENABLE_REDIS="${MONOBUCKET_ENABLE_REDIS}" \
&& cmake --build build --parallel "$(nproc)" \
&& strip --strip-all build/bin/monobucket \
&& build/bin/monobucket --version
# --- Stage 3: runtime ------------------------------------------------------
FROM alpine:3.21 AS runtime
ARG MONOBUCKET_VERSION=dev
ARG VCS_REF=unknown
ARG BUILD_DATE=unknown
ARG MONOBUCKET_ENABLE_REDIS=OFF
LABEL org.opencontainers.image.title="MonoBucket" \
org.opencontainers.image.description="Single-binary S3-compatible object storage with an embedded admin dashboard" \
org.opencontainers.image.version="${MONOBUCKET_VERSION}" \
org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.licenses="GPL-3.0-or-later" \
org.opencontainers.image.source="https://github.com/sinhaparth5/MonoBucket"
RUN apk add --no-cache \
libstdc++ \
openssl \
jsoncpp \
brotli-libs \
c-ares \
libuuid \
rocksdb \
&& if [ "$MONOBUCKET_ENABLE_REDIS" = "ON" ]; then apk add --no-cache hiredis; fi \
&& addgroup -S -g 1000 monobucket \
&& adduser -S -u 1000 -G monobucket -H -h /data monobucket \
&& mkdir -p /data \
&& chown monobucket:monobucket /data
COPY --from=backend /src/build/bin/monobucket /usr/local/bin/monobucket
ENV MONOBUCKET_DATA_DIR=/data \
MONOBUCKET_HOST=0.0.0.0 \
MONOBUCKET_PORT=9000 \
MONOBUCKET_CONSOLE_PORT=9001 \
MONOBUCKET_LOG_LEVEL=info
VOLUME ["/data"]
EXPOSE 9000 9001
USER monobucket
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget -q -O- "http://127.0.0.1:${MONOBUCKET_PORT}/healthz" >/dev/null || exit 1
ENTRYPOINT ["/usr/local/bin/monobucket"]