-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
102 lines (90 loc) · 4.08 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
FROM --platform=${BUILDPLATFORM} rust:1.71-bullseye AS builder
ARG BUILDPLATFORM
ARG TARGETPLATFORM
RUN apt-get update --assume-yes && \
apt-get upgrade --assume-yes
RUN \
mkdir .cargo && \
echo '[net]' >> .cargo/config.toml && \
echo 'git-fetch-with-cli = true' >> .cargo/config.toml && \
echo >> .cargo/config.toml && \
if [ "${BUILDPLATFORM}" != "${TARGETPLATFORM}" ]; then \
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
apt-get install --assume-yes gcc-x86-64-linux-gnu; \
echo '[target.x86_64-unknown-linux-gnu]' >> .cargo/config.toml; \
echo 'linker = "x86-64-linux-gnu-gcc"' >> .cargo/config.toml; \
echo >> .cargo/config.toml; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
apt-get install --assume-yes gcc-aarch64-linux-gnu; \
echo '[target.aarch64-unknown-linux-gnu]' >> .cargo/config.toml; \
echo 'linker = "aarch64-linux-gnu-gcc"' >> .cargo/config.toml; \
echo >> .cargo/config.toml; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
apt-get install --assume-yes gcc-arm-linux-gnueabihf; \
echo '[target.armv7-unknown-linux-gnueabihf]' >> .cargo/config.toml; \
echo 'linker = "arm-linux-gnueabihf-gcc"' >> .cargo/config.toml; \
echo >> .cargo/config.toml; \
fi \
fi
RUN \
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
RUSTTARGET=x86_64-unknown-linux-gnu; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
RUSTTARGET=aarch64-unknown-linux-gnu; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
RUSTTARGET=armv7-unknown-linux-gnueabihf; \
fi && \
rustup target add ${RUSTTARGET}
WORKDIR /usr/src/angybot/
COPY ./ ./
# The hack levels are increasing
RUN \
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
RUSTTARGET=x86_64-unknown-linux-gnu; \
export TARGET_CC=/usr/bin/x86-64-linux-gnu-gcc; \
export TARGET_AR=/usr/bin/x86-64-linux-gnu-ar; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
RUSTTARGET=aarch64-unknown-linux-gnu; \
export TARGET_CC=/usr/bin/aarch64-linux-gnu-gcc; \
export TARGET_AR=/usr/bin/aarch64-linux-gnu-ar; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
RUSTTARGET=armv7-unknown-linux-gnueabihf; \
export TARGET_CC=/usr/bin/arm-linux-gnueabihf-gcc; \
export TARGET_AR=/usr/bin/arm-linux-gnueabihf-ar; \
fi && \
cargo build --all-features --bins --release --target=${RUSTTARGET} || \
if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
apt-get install --assume-yes libssl1.1:amd64 libssl-dev:amd64 libopus-dev:amd64; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
apt-get install --assume-yes libssl1.1:arm64 libssl-dev:arm64 libopus-dev:arm64; \
fi && \
if [ "${TARGETPLATFORM}" = "linux/arm/v7" ]; then \
apt-get install --assume-yes libssl1.1:armhf libssl-dev:armhf libopus-dev:armhf; \
fi && \
cargo build --all-features --bins --release --target=${RUSTTARGET}
#############################################################################
FROM --platform=${TARGETPLATFORM} rust:1.71-slim-bullseye AS final
WORKDIR /usr/src/angybot/
COPY --from=builder \
/usr/src/angybot/target/*/release/angybot \
/usr/bin/
RUN apt-get update --assume-yes && \
apt-get upgrade --assume-yes && \
apt-get install --assume-yes libopus-dev ffmpeg wget
RUN wget "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux" --output-document=/usr/bin/yt-dlp
RUN chmod a+x /usr/bin/yt-dlp
ENTRYPOINT ["angybot"]
CMD []
LABEL org.opencontainers.image.title="Angy Bot"
LABEL org.opencontainers.image.description="A Discord bot for playing back music in funny ways"
LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later"
LABEL org.opencontainers.image.url="https://github.com/RYGhub/angybot"
LABEL org.opencontainers.image.authors="Stefano Pigozzi <[email protected]>"
ENV RUST_LOG "warn,angybot=info"