-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
73 lines (49 loc) · 1.88 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
FROM --platform=$BUILDPLATFORM rustlang/rust:nightly-bullseye-slim AS build
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="aarch64-linux-gnu-gcc"
RUN apt update \
&& apt upgrade -y \
&& apt install -y git default-libmysqlclient-dev 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 -y \
&& apt install default-libmysqlclient-dev:arm64 -y; \
fi
RUN rustup target add $(cat /target.txt)
RUN cargo install --target $(cat /target.txt) diesel_cli --no-default-features --features "mysql" \
&& mkdir /out \
&& cp /usr/local/cargo/bin/diesel /out
RUN cargo new --bin testauskoira-rs
WORKDIR /testauskoira-rs
COPY Cargo.toml Cargo.lock ./
RUN cargo build --target $(cat /target.txt) --release && rm -rf .git src/ target/$(cat /target.txt)/release/deps/testauskoira*
COPY src/ src/
COPY .git/ .git/
COPY build.rs build.rs
RUN cargo build --target $(cat /target.txt) --release && mv target/$(cat /target.txt)/release/testauskoira-rs /out
FROM --platform=$TARGETPLATFORM debian:bullseye-slim AS runner
RUN apt update \
&& apt upgrade -y \
&& apt install --no-install-recommends default-mysql-client ca-certificates -y \
&& rm -rf /var/lib/apt/lists/*
RUN adduser \
--disabled-password \
--gecos "" \
--home "/none" \
--shell "/sbin/nologin" \
--no-create-home \
doggo
WORKDIR /app
COPY --from=build /out/diesel ./
COPY --from=build /out/testauskoira-rs ./
COPY migrations /app/migrations
COPY entrypoint.sh ./
RUN chown -R doggo:doggo /app
USER doggo
CMD ["sh", "entrypoint.sh"]