-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockerfile
More file actions
163 lines (116 loc) · 5.04 KB
/
Dockerfile
File metadata and controls
163 lines (116 loc) · 5.04 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
# node version
ARG NODE_VERSION=24
# pot provider version
ARG POT_PROVIDER_VERSION=1.2.2
# rust version
ARG RUST_VERSION=1.94
# s6-overlay version
ARG S6_OVERLAY_VERSION=3.2.1.0
FROM node:${NODE_VERSION} AS pot_provider_build_image
ARG POT_PROVIDER_VERSION
ENV POT_PROVIDER_VERSION ${POT_PROVIDER_VERSION}
RUN git clone --single-branch --branch ${POT_PROVIDER_VERSION} https://github.com/Brainicism/bgutil-ytdlp-pot-provider.git /pot-provider && \
cd /pot-provider/server && \
npm install && \
npx tsc
FROM node:${NODE_VERSION} AS client_build_image
ARG HITSTER_BRANCH
ARG HITSTER_VERSION
ENV HITSTER_BRANCH ${HITSTER_BRANCH}
ENV HITSTER_VERSION ${HITSTER_VERSION}
WORKDIR /app
# build cache first
COPY ./client/package.json ./client/package-lock.json /app/
RUN npm install && rm /app/*.json
# build everything else
COPY ./client/ /app/
RUN npm run build
FROM rust:${RUST_VERSION}-slim-trixie AS server_build_image
# create a new empty shell project
RUN apt-get update && apt-get -y install libssl-dev pkg-config && \
USER=root mkdir hitster
WORKDIR /hitster
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
RUN USER=root cargo new --bin server && \
USER=root cargo new --bin cli && \
USER=root cargo new --lib core --name hitster_core
# copy over your manifests
COPY ./cli/Cargo.toml ./cli/Cargo.toml
COPY ./core/Cargo.toml ./core/Cargo.toml
COPY ./server/Cargo.toml ./server/Cargo.toml
# this build step will cache your dependencies
RUN cargo build --release --no-default-features --features yt_dl && \
cargo build --release -p hitster-cli && \
rm server/src/*.rs && \
rm core/src/*.rs && \
rm cli/src/*.rs
# copy your source tree
COPY ./.sqlx ./.sqlx
COPY ./etc ./etc
COPY ./server/migrations ./server/migrations
COPY ./server/src ./server/src
COPY ./core/src ./core/src
COPY ./cli/src ./cli/src
# build for release
RUN rm ./target/release/deps/hitster* && \
rm ./target/release/deps/libhitster* && \
SQLX_OFFLINE=true cargo build --release --no-default-features --features yt_dl && \
cargo build --release -p hitster-cli
# our final bases, platform-dependent
# x64
FROM debian:trixie-slim AS build_amd64
ARG S6_OVERLAY_VERSION
ONBUILD ADD https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz /opt/ffmpeg.tar.xz
ONBUILD ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz /tmp/s6-overlay.tar.xz
# arm64
FROM debian:trixie-slim AS build_arm64
ARG S6_OVERLAY_VERSION
ONBUILD ADD https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linuxarm64-gpl.tar.xz /opt/ffmpeg.tar.xz
ONBUILD ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-aarch64.tar.xz /tmp/s6-overlay.tar.xz
FROM build_${TARGETARCH}
ARG NODE_VERSION
ARG S6_OVERLAY_VERSION
WORKDIR /hitster
ENV CLIENT_DIRECTORY=/hitster/client
ENV DATABASE_URL=sqlite:///hitster.sqlite
ENV DOWNLOAD_DIRECTORY=/hits
ENV NODE_VERSION=${NODE_VERSION}
ENV PATH="$PATH:/opt/ffmpeg/bin/"
EXPOSE 8000
VOLUME [ "/hits", "/hitster.sqlite" ]
# install s6-overlay
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
# prepare the OS
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -y curl && \
curl -sL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - && \
apt-get -y install --no-install-recommends libssl-dev ca-certificates python3 python3-mutagen python3-pip xz-utils && \
pip3 install --no-cache-dir --break-system-packages ffmpeg-normalize && \
mkdir /opt/ffmpeg && \
tar xf /opt/ffmpeg.tar.xz -C /opt/ffmpeg/ --strip-components 1 && \
tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz && \
tar -C / -Jxpf /tmp/s6-overlay.tar.xz && \
apt-get purge -y --auto-remove python3-pip xz-utils curl && \
apt-get clean && \
rm /opt/ffmpeg.tar.xz && \
rm /tmp/s6-overlay-noarch.tar.xz && \
rm /tmp/s6-overlay.tar.xz && \
rm -rf /var/lib/apt/lists/* && \
mkdir /.cache && \
chmod 777 /.cache && \
echo "--ffmpeg-location /opt/ffmpeg/bin/ --js-runtimes node" > /etc/yt-dlp.conf
# yt-dlp
ADD --chmod=777 https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp /usr/local/bin/yt-dlp
# copy the build artifacts from the build stage
COPY --from=server_build_image /hitster/target/release/hitster-server /hitster/server
COPY --from=server_build_image /hitster/target/release/hitster-cli /hitster/cli
COPY --from=client_build_image /app/dist /hitster/client
COPY --from=pot_provider_build_image /pot-provider/server/build /pot-provider/build
COPY --from=pot_provider_build_image /pot-provider/server/node_modules /pot-provider/node_modules
COPY --from=pot_provider_build_image /pot-provider/plugin /etc/yt-dlp/plugins/bgutil-ytdlp-pot-provider
COPY --from=pot_provider_build_image /usr/local/bin/node /usr/local/bin/node
# setup s6-overlay
COPY ./docker/s6-rc.d /etc/s6-overlay/s6-rc.d
# set the startup command to run your binary
ENTRYPOINT [ "/init" ]