-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerfile
More file actions
185 lines (157 loc) · 7.84 KB
/
Copy pathContainerfile
File metadata and controls
185 lines (157 loc) · 7.84 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
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
# --------------------------------------------------------------------------
# THIS FILE IS AUTOGENERATED - DO NOT EDIT MANUALLY
#
# Source: Containerfile.j2
# --------------------------------------------------------------------------
# Seerr - Unified media request management
# Multi-stage build matching upstream pattern: prod-deps + build + runtime
ARG BASE_VERSION=15.1
FROM ghcr.io/daemonless/base:${BASE_VERSION} AS base
# Build dependencies (shared across stages)
RUN pkg update && pkg install -y \
node22 npm-node22 python3 py312-setuptools \
gmake pkgconf sqlite3 vips \
FreeBSD-clang FreeBSD-lld FreeBSD-toolchain FreeBSD-clibs-dev FreeBSD-runtime-dev \
FreeBSD-zlib-dev FreeBSD-openssl-dev FreeBSD-xz-dev FreeBSD-bzip2-dev \
ca_root_nss \
&& pkg clean -ay && rm -rf /var/cache/pkg/* /var/db/pkg/repos/*
RUN ln -sf /usr/bin/clang /usr/bin/cc && \
ln -sf /usr/bin/clang++ /usr/bin/c++
RUN corepack enable
ENV PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
# Build native addons against local node22 headers (no nodejs.org fetch -> no
# ECONNRESET); CPPFLAGS adds system libuv's uv.h, which node22's headers omit.
ENV npm_config_nodedir=/usr/local \
CPPFLAGS=-I/usr/local/include
ENV NODE_OPTIONS="--max-old-space-size=2048"
# Download source
RUN SEERR_VERSION=$(fetch -qo - "https://api.github.com/repos/seerr-team/seerr/releases/latest" | jq -r '.tag_name') && \
echo "Building Seerr ${SEERR_VERSION}" && \
mkdir -p /app/seerr && \
fetch -qo - "https://github.com/seerr-team/seerr/archive/refs/tags/${SEERR_VERSION}.tar.gz" | \
tar xzf - -C /app/seerr --strip-components=1 && \
echo "${SEERR_VERSION#v}" > /app/version
WORKDIR /app/seerr
# Next.js SWC patch for FreeBSD (no native binary): stub the downloads, force
# the WASM fallback first, drop the hard exit. Used by both prod-deps and build.
COPY <<'PATCH' /tmp/patch-swc.js
const fs = require('fs');
const p = process.argv[2];
fs.writeFileSync(p + '/dist/lib/download-swc.js',
'module.exports.downloadNativeNextSwc=async function(){};module.exports.downloadWasmSwc=async function(){};');
let idx = fs.readFileSync(p + '/dist/build/swc/index.js', 'utf8');
idx = idx.replace(
/shouldLoadWasmFallbackFirst\s*=\s*[^;]+;/,
'shouldLoadWasmFallbackFirst = true;');
idx = idx.replace('process.exit(1)', '/* patched */');
fs.writeFileSync(p + '/dist/build/swc/index.js', idx);
console.log('SWC patched for FreeBSD WASM fallback');
PATCH
# Install the WASM SWC matching Next.js's minor and wire it into the next pkg.
# $1 = optional extra pnpm flags (e.g. --prod env uses --ignore-scripts already).
COPY <<'WASM' /usr/local/bin/setup-next-wasm.sh
#!/bin/sh
set -e
NEXT_DIR=$(ls -d node_modules/.pnpm/next@*/node_modules/next)
NEXT_VER=$(jq -r .version "${NEXT_DIR}/package.json")
NEXT_MINOR=$(echo "${NEXT_VER}" | sed 's/\.[0-9]*$//')
echo "Next.js ${NEXT_VER}: installing WASM SWC ~${NEXT_MINOR}.0"
pnpm add --ignore-scripts "@next/swc-wasm-nodejs@~${NEXT_MINOR}.0"
WASM_SRC=$(ls -d node_modules/.pnpm/@next+swc-wasm-nodejs@*/node_modules/@next/swc-wasm-nodejs)
mkdir -p "${NEXT_DIR}/wasm/@next/swc-wasm-nodejs"
cp -r "${WASM_SRC}"/* "${NEXT_DIR}/wasm/@next/swc-wasm-nodejs/"
node /tmp/patch-swc.js "${NEXT_DIR}"
WASM
RUN chmod +x /usr/local/bin/setup-next-wasm.sh
# seerr's next.config wires SVGR only for Turbopack. We build with --webpack
# (no FreeBSD native bindings), which ignores that, so SVG imports fall back to
# static images and crash SSR ("Element type is invalid"). Inject the equivalent
# webpack SVGR rule so SVGs become React components like Turbopack produces.
COPY <<'SVGR' /tmp/patch-svgr.js
const fs = require('fs');
const p = process.argv[2];
let s = fs.readFileSync(p, 'utf8');
const anchor = 'const nextConfig: NextConfig = {';
if (!s.includes(anchor)) { console.error('SVGR patch: anchor not found in ' + p); process.exit(1); }
const inject = `
webpack(config) {
const r = config.module.rules.find((x) => x.test && x.test.test && x.test.test('.svg'));
if (r) {
config.module.rules.push(
{ ...r, test: /\\.svg$/i, resourceQuery: /url/ },
{ test: /\\.svg$/i, issuer: r.issuer, resourceQuery: { not: [...((r.resourceQuery && r.resourceQuery.not) || []), /url/] }, use: ['@svgr/webpack'] }
);
r.exclude = /\\.svg$/i;
} else {
config.module.rules.push({ test: /\\.svg$/i, issuer: /\\.[jt]sx?$/, use: ['@svgr/webpack'] });
}
return config;
},`;
fs.writeFileSync(p, s.replace(anchor, anchor + inject));
console.log('SVGR webpack rule injected into ' + p);
SVGR
# --- Stage: production dependencies ---
FROM base AS prod-deps
RUN CYPRESS_INSTALL_BINARY=0 pnpm install --prod --frozen-lockfile --ignore-scripts && \
pnpm rebuild sqlite3 bcrypt && \
setup-next-wasm.sh && \
rm -rf $(pnpm store path)
# --- Stage: build ---
FROM base AS build
RUN CYPRESS_INSTALL_BINARY=0 pnpm install --frozen-lockfile
# WASM SWC (no native binary on FreeBSD) — same setup used by prod-deps.
RUN setup-next-wasm.sh
# next build defaults to Turbopack (no FreeBSD native bindings) -> force webpack,
# and add the SVGR webpack rule that the Turbopack-only config would otherwise skip.
RUN node /tmp/patch-svgr.js next.config.ts && \
node_modules/.bin/next build --webpack && \
pnpm build:server && \
rm -rf .next/cache $(pnpm store path)
# --- Stage: production image ---
FROM ghcr.io/daemonless/base:${BASE_VERSION}
ARG FREEBSD_ARCH=amd64
ARG PACKAGES="node22 vips sqlite3"
ARG UPSTREAM_URL="https://api.github.com/repos/seerr-team/seerr/releases/latest"
ARG UPSTREAM_JQ=".tag_name"
ARG HEALTHCHECK_ENDPOINT="http://localhost:5055/api/v1/status"
ENV HEALTHCHECK_URL="${HEALTHCHECK_ENDPOINT}"
# --- Metadata (Injected by Generator) ---
LABEL org.opencontainers.image.title="Seerr" \
org.opencontainers.image.description="Unified media request management (Plex, Jellyfin, Emby) on FreeBSD." \
org.opencontainers.image.source="https://github.com/daemonless/seerr" \
org.opencontainers.image.url="https://seerr.io/" \
org.opencontainers.image.documentation="https://docs.seerr.io/" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.vendor="daemonless" \
org.opencontainers.image.authors="daemonless" \
io.daemonless.category="Media Management" \
io.daemonless.port="5055" \
io.daemonless.volumes="/config" \
io.daemonless.arch="${FREEBSD_ARCH}" \
io.daemonless.upstream-url="${UPSTREAM_URL}" \
io.daemonless.upstream-jq="${UPSTREAM_JQ}" \
io.daemonless.healthcheck-url="${HEALTHCHECK_ENDPOINT}" \
io.daemonless.packages="${PACKAGES}"
# Runtime dependencies only
RUN pkg update && \
pkg install -y ${PACKAGES} && \
pkg clean -ay && \
rm -rf /var/cache/pkg/* /var/db/pkg/repos/*
# Copy full source tree, then overlay prod deps and build output (matching upstream)
COPY --from=base --chown=bsd:bsd /app/seerr /app/seerr
COPY --from=base --chown=bsd:bsd /app/version /app/version
COPY --from=prod-deps --chown=bsd:bsd /app/seerr/node_modules /app/seerr/node_modules
COPY --from=build --chown=bsd:bsd /app/seerr/.next /app/seerr/.next
COPY --from=build --chown=bsd:bsd /app/seerr/dist /app/seerr/dist
# Fix fresh-install crash: enable synchronize (creates schema) and skip broken migrations
RUN node -e "let f='/app/seerr/dist/datasource.js',s=require('fs').readFileSync(f,'utf8');require('fs').writeFileSync(f,s.replace('synchronize: false','synchronize: true'))" && \
node -e "let f='/app/seerr/dist/index.js',s=require('fs').readFileSync(f,'utf8');require('fs').writeFileSync(f,s.replace(/await dbConnection\.runMigrations\(\)/g,'/* migrations handled by synchronize */'))"
# Create config directory
RUN mkdir -p /config && chown bsd:bsd /config
# Copy service files
COPY root/ /
RUN chmod +x /etc/services.d/*/run /etc/cont-init.d/* 2>/dev/null || true
# --- Expose (Injected by Generator) ---
EXPOSE 5055
# --- Volumes (Injected by Generator) ---
VOLUME /config