-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Dockerfile
87 lines (67 loc) · 3.05 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
# by using --platform=$BUILDPLATFORM we force the build step
# to always run on the native architecture of the build machine
# making the build time shorter
FROM --platform=$BUILDPLATFORM rust:1.78 as builder
ARG BUILDPLATFORM
ARG TARGETPLATFORM
#find the right build target for rust
RUN if [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \
export RUST_TARGET_PLATFORM=armv7-unknown-linux-gnueabihf; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
export RUST_TARGET_PLATFORM=aarch64-unknown-linux-gnu; \
elif [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
export RUST_TARGET_PLATFORM=x86_64-unknown-linux-gnu; \
else \
export RUST_TARGET_PLATFORM=$(rustup target list --installed | head -n 1); \
fi; \
echo "choosen rust target: $RUST_TARGET_PLATFORM" ;\
echo $RUST_TARGET_PLATFORM > /rust_platform.txt
RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM, rust target is $(cat /rust_platform.txt)"
RUN if echo $TARGETPLATFORM | grep -q 'arm'; then \
echo 'Installing packages for ARM platforms...'; \
apt-get update && apt-get install build-essential gcc gcc-arm* gcc-aarch* -y && apt-get clean; \
echo 'gcc-arm* packages installed and cache cleaned.'; \
fi
RUN rustup target add $(cat /rust_platform.txt)
RUN cd /tmp && USER=root cargo new --bin vod2pod
WORKDIR /tmp/vod2pod
COPY Cargo.toml ./
#trick to use github action cache, check the action folder for more info
RUN sed '/\[dev-dependencies\]/,/^$/d' Cargo.toml > Cargo.toml.tmp && mv Cargo.toml.tmp Cargo.toml
RUN cargo fetch
COPY .cargo/ ./.cargo/
COPY src ./src
COPY set_version.sh version.txt* ./
COPY templates/ ./templates/
RUN sh set_version.sh
RUN cargo build --release --target "$(cat /rust_platform.txt)"
RUN echo "final size of vod2pod:\n $(ls -lah /tmp/vod2pod/target/*/release/app)"
#----------
#this step will always run on the target architecture,
#so the build driver will need to be able to support runtime commands on it (es: using QEMU)
FROM --platform=$TARGETPLATFORM debian:bookworm-slim as app
ARG BUILDPLATFORM
ARG TARGETPLATFORM
RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM"
COPY requirements.txt ./
#install ffmpeg and yt-dlp
RUN apt-get update && \
apt-get install -y --no-install-recommends python3 curl ca-certificates ffmpeg && \
export YT_DLP_VERSION=$(cat requirements.txt | grep yt-dlp | cut -d "=" -f3 | awk -F. '{printf "%d.d.d\n", $1, $2, $3}') && \
curl -L https://github.com/yt-dlp/yt-dlp/releases/download/$YT_DLP_VERSION/yt-dlp -o /usr/local/bin/yt-dlp && \
chmod a rx /usr/local/bin/yt-dlp && \
apt-get -y purge curl && \
apt-get -y autoremove && \
apt-get -y clean && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /tmp/vod2pod/target/*/release/app /usr/local/bin/vod2pod
COPY --from=builder /tmp/vod2pod/templates/ ./templates
RUN if vod2pod --version; then \
echo "vod2pod starts correctly"; \
exit 0; \
else \
echo "vod2pod did not start" 1>&2; \
exit 1; \
fi
EXPOSE 8080
CMD ["vod2pod"]