-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathDockerfile
134 lines (122 loc) · 4.98 KB
/
Dockerfile
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
ARG base_image=jasongdove/ersatztv-ffmpeg
ARG base_image_tag=7.0
# Setup a node + ffmpeg + nvidia base
FROM ${base_image}:${base_image_tag} AS ffmpeg-base
ENV NODE_MAJOR=22
ENV TUNARR_BIND_ADDR=0.0.0.0
# Expose Tunarr server default port
EXPOSE 8000
# Expose SSDP default port
EXPOSE 1900/udp
# Update deps, Install Bun
# Install musl for native node bindings (sqlite)
RUN <<EOF
apt-get update --fix-missing && apt-get install -y ca-certificates curl gnupg unzip wget musl-dev
EOF
RUN ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
RUN <<EOF
curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.0"
EOF
RUN ln -s ~/.bun/bin/bun /usr/bin/bun
# Install node - we still need this for some dev tools (for now)
RUN <<EOF
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
apt-get update && apt-get install nodejs -y
EOF
# Install pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# RUN wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.bashrc" SHELL="$(which bash)" bash -
RUN npm install -g corepack@latest
RUN corepack enable && corepack enable pnpm
RUN pnpm --version
RUN ln -s /usr/local/bin/ffmpeg /usr/bin/ffmpeg
RUN ln -s /usr/local/bin/ffprobe /usr/bin/ffprobe
ENTRYPOINT [ "/tunarr/tunarr-linux-x64" ]
CMD [ "server" ]
# Add Tunarr sources
FROM ffmpeg-base AS sources
WORKDIR /tunarr
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml turbo.json ./
COPY scripts ./scripts
COPY server/ ./server
COPY shared/ ./shared
COPY types ./types
COPY web ./web
COPY patches ./patches
COPY CHANGELOG.md CHANGELOG.md
# Dev container
FROM ffmpeg-base AS dev
EXPOSE 5173
WORKDIR /tunarr
COPY . .
RUN pnpm install --frozen-lockfile
ENTRYPOINT [ "pnpm" ]
CMD [ "turbo", "dev" ]
# Step for caching production deps
FROM sources AS prod-deps
ARG NODE_ENVIRONMENT
ENV NODE_ENV=${NODE_ENVIRONMENT:-production}
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
### Begin server build ###
FROM sources AS build-server
# Install deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
ARG is_edge_build
ARG tunarr_build
ARG exec_target=linux-x64
# Build common modules
RUN <<EOF
touch server/.env
echo TUNARR_BUILD=${tunarr_build} >> server/.env
echo TUNARR_EDGE_BUILD=${is_edge_build} >> server/.env
cat server/.env
EOF
# Build and bundle
RUN echo "Building target: ${exec_target}"
RUN pnpm turbo --filter=@tunarr/server make-exec -- --target ${exec_target} --no-include-version
### End server build ###
### Begin server web ###
FROM sources AS build-web
# Install deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
# Build common modules
RUN pnpm turbo --filter=@tunarr/web bundle
FROM sources AS build-full-stack
ARG exec_target=linux-x64
# Install deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
# Bundle web in a separate task
RUN NODE_OPTIONS=--max-old-space-size=32768 pnpm turbo bundle --filter=@tunarr/web
RUN echo "Building target: ${exec_target}"
RUN pnpm turbo --filter=@tunarr/server make-exec -- --target ${exec_target} --no-include-version --strip-baseline-name
### Begin server run ###
FROM ffmpeg-base AS server
COPY --from=prod-deps /tunarr/node_modules /tunarr/node_modules
COPY --from=prod-deps /tunarr/server/node_modules /tunarr/server/node_modules
COPY --from=build-server /tunarr/types /tunarr/types
COPY --from=build-server /tunarr/shared /tunarr/shared
COPY --from=build-server /tunarr/server/package.json /tunarr/server/package.json
COPY --from=build-server /tunarr/server/dist /tunarr/server/dist
# Create a symlink to the executable in /tunarr. This simplifies things for the
# user, such as volume mapping their legacy DBs, while not interrupting the
# other assumptions that Tunarr makes about its working directory
RUN ln -s /tunarr/server/dist/bin/tunarr-linux-x64 /tunarr/tunarr-linux-x64
### Begin server run
### Full stack ###
FROM ffmpeg-base AS full-stack
# Duplicate the COPY statements from server build to ensure we don't bundle
# twice, needlessly
COPY --from=prod-deps /tunarr/node_modules /tunarr/node_modules
COPY --from=prod-deps /tunarr/server/node_modules /tunarr/server/node_modules
COPY --from=build-full-stack /tunarr/types /tunarr/types
COPY --from=build-full-stack /tunarr/shared /tunarr/shared
COPY --from=build-full-stack /tunarr/server/package.json /tunarr/server/package.json
COPY --from=build-full-stack /tunarr/server/dist /tunarr/server/dist
COPY --from=build-full-stack /tunarr/web/dist /tunarr/server/dist/web
# Create a symlink to the executable in /tunarr. This simplifies things for the
# user, such as volume mapping their legacy DBs, while not interrupting the
# other assumptions that Tunarr makes about its working directory
RUN ln -s /tunarr/server/dist/bin/tunarr-linux-x64 /tunarr/tunarr-linux-x64