-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
66 lines (43 loc) · 1.52 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
FROM --platform=$BUILDPLATFORM rust:1-slim-bullseye AS build
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="aarch64-linux-gnu-gcc"
RUN apt update \
&& apt upgrade -y \
&& apt install -y git pkg-config libssl-dev perl make
ARG TARGETPLATFORM
RUN case "$TARGETPLATFORM" in \
"linux/amd64") echo "x86_64-unknown-linux-gnu" > /target.txt ;; \
"linux/arm64") echo "aarch64-unknown-linux-gnu" > /target.txt ;; \
*) exit 1 ;; \
esac
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
dpkg --add-architecture arm64 \
&& apt update \
&& apt install gcc-aarch64-linux-gnu libc6-dev-arm64-cross libssl-dev:arm64 pkg-config -y; \
fi
RUN rustup target add $(cat /target.txt)
RUN cargo new --bin bot
WORKDIR /bot
COPY Cargo.toml Cargo.lock ./
RUN cargo build --target $(cat /target.txt) --release && rm -rf .git src/ target/$(cat /target.txt)/release/deps/hacksquad*
COPY src/ src/
COPY .git/ .git/
RUN mkdir /out
RUN cargo build --target $(cat /target.txt) --release && mv target/$(cat /target.txt)/release/hacksquad-bot /out
FROM --platform=$TARGETPLATFORM debian:bullseye-slim AS runner
RUN apt update \
&& apt upgrade -y \
&& apt install --no-install-recommends ca-certificates -y \
&& rm -rf /var/lib/apt/lists/*
RUN adduser \
--disabled-password \
--gecos "" \
--home "/none" \
--shell "/sbin/nologin" \
--no-create-home \
bot
WORKDIR /bot
COPY --from=build /out/hacksquad-bot ./
COPY ./.git ./.git
RUN chown -R bot:bot /bot
USER bot
CMD ["./hacksquad-bot"]