-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathDockerfile
164 lines (128 loc) · 5.25 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
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
ARG TWITCHDOWNLOADER_VERSION="1.55.1"
#
# API Build
#
FROM golang:1.23-bookworm AS build-api
WORKDIR /app
COPY . .
RUN make build_server build_worker
#
# API Tools
#
FROM debian:bookworm-slim AS tools
WORKDIR /tmp
RUN apt-get update && apt-get install -y --no-install-recommends \
unzip git ca-certificates curl \
&& rm -rf /var/lib/apt/lists/*
# Download TwitchDownloader for the correct platform
ARG TWITCHDOWNLOADER_VERSION
ENV TWITCHDOWNLOADER_URL=https://github.com/lay295/TwitchDownloader/releases/download/${TWITCHDOWNLOADER_VERSION}/TwitchDownloaderCLI-${TWITCHDOWNLOADER_VERSION}-Linux-x64.zip
RUN if [ "$(uname -m)" = "aarch64" ]; then \
TWITCHDOWNLOADER_URL=https://github.com/lay295/TwitchDownloader/releases/download/${TWITCHDOWNLOADER_VERSION}/TwitchDownloaderCLI-${TWITCHDOWNLOADER_VERSION}-LinuxArm64.zip; \
fi && \
echo "Download URL: $TWITCHDOWNLOADER_URL" && \
curl -L $TWITCHDOWNLOADER_URL -o twitchdownloader.zip && \
unzip twitchdownloader.zip && \
rm twitchdownloader.zip
RUN git clone --depth 1 https://github.com/xenova/chat-downloader.git
#
# Frontend base
#
FROM node:22-alpine AS base-frontend
# Install dependencies only when needed
FROM node:22-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY frontend/package.json frontend/package-lock.json* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci --force; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
#
# Frontend build
#
FROM node:22-alpine AS build-frontend
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY frontend/. .
ENV NEXT_TELEMETRY_DISABLED=1
RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi
#
# Tests stage. Inclues depedencies required for tests
#
FROM golang:1.23-bookworm AS tests
RUN apt-get update && apt-get install -y --no-install-recommends python3 python3-pip ffmpeg make git
RUN pip3 install --upgrade pip streamlink --break-system-packages
# Copy and install chat-downloader
COPY --from=tools /tmp/chat-downloader /tmp/chat-downloader
RUN cd /tmp/chat-downloader && python3 setup.py install && cd .. && rm -rf chat-downloader
# Setup fonts
RUN chmod 644 /usr/share/fonts/* && chmod -R a+rX /usr/share/fonts
# Copy TwitchDownloaderCLI
COPY --from=tools /tmp/TwitchDownloaderCLI /usr/local/bin/
RUN chmod +x /usr/local/bin/TwitchDownloaderCLI
# Production stage
FROM debian:bookworm-slim
WORKDIR /opt/app
# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 python3-pip fontconfig ffmpeg tzdata procps supervisor \
fonts-noto-core fonts-noto-cjk fonts-noto-extra fonts-inter \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& ln -sf python3 /usr/bin/python
# Install pip packages
RUN pip3 install --no-cache-dir --upgrade pip streamlink --break-system-packages
# Install gosu
RUN curl -LO https://github.com/tianon/gosu/releases/latest/download/gosu-$(dpkg --print-architecture | awk -F- '{ print $NF }') \
&& chmod 0755 gosu-$(dpkg --print-architecture | awk -F- '{ print $NF }') \
&& mv gosu-$(dpkg --print-architecture | awk -F- '{ print $NF }') /usr/local/bin/gosu
# Install node for frontend
ENV NODE_VERSION=22.x \
DEBIAN_FRONTEND=noninteractive
# Install required packages, add NodeSource repository, and install Node.js
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
gnupg \
&& curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION} | bash - \
&& apt-get install -y --no-install-recommends nodejs \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN node --version && npm --version
# Setup user
RUN useradd -u 911 -d /data abc && usermod -a -G users abc
# Copy and install chat-downloader
COPY --from=tools /tmp/chat-downloader /tmp/chat-downloader
RUN cd /tmp/chat-downloader && python3 setup.py install && cd .. && rm -rf chat-downloader
# Setup fonts
RUN chmod 644 /usr/share/fonts/* && chmod -R a+rX /usr/share/fonts
# Copy TwitchDownloaderCLI
COPY --from=tools /tmp/TwitchDownloaderCLI /usr/local/bin/
RUN chmod +x /usr/local/bin/TwitchDownloaderCLI
# Copy api and worker builds
COPY --from=build-api /app/ganymede-api .
COPY --from=build-api /app/ganymede-worker .
# Setup frontend
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=build-frontend /app/public ./public
RUN mkdir .next
RUN chown nextjs:nodejs .next
COPY --from=build-frontend --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=build-frontend --chown=nextjs:nodejs /app/.next/static ./.next/static
ENV HOSTNAME="0.0.0.0"
# Setup entrypoint
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
COPY supervisord.conf /opt/app/supervisord.conf
EXPOSE 4000
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]