-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
70 lines (54 loc) · 1.9 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
# one of:
# amd64
# arm64
ARG TARGETARCH=amd64
#########
# amd64 #
#########
FROM rust AS builder_amd64
RUN apt-get update && apt-get install -y musl-tools musl-dev
RUN rustup target add x86_64-unknown-linux-musl && rustup component add clippy
WORKDIR /usr/src/chore_planner
# cache dependencies
COPY ./Cargo.toml ./Cargo.toml
RUN echo 'fn main() {}' > dummy.rs && \
sed -i 's#src/main.rs#dummy.rs#' Cargo.toml
RUN cargo clippy -- -D warnings && \
cargo test && \
cargo build --release --target x86_64-unknown-linux-musl
# actually build
COPY ./Cargo.toml ./Cargo.toml
COPY ./src ./src
RUN cargo clippy -- -D warnings && \
cargo test && \
cargo build --release --target x86_64-unknown-linux-musl && \
cp /usr/src/chore_planner/target/x86_64-unknown-linux-musl/release/chore_planner /var/run/chore_planner
#########
# arm64 #
#########
FROM messense/rust-musl-cross:aarch64-musl AS builder_arm64
RUN rustup target add aarch64-unknown-linux-musl && rustup component add clippy
WORKDIR /usr/src/chore_planner
# cache dependencies
COPY ./Cargo.toml ./Cargo.toml
RUN echo 'fn main() {}' > dummy.rs && \
sed -i 's#src/main.rs#dummy.rs#' Cargo.toml
RUN cargo clippy -- -D warnings && \
cargo test && \
cargo build --release --target aarch64-unknown-linux-musl
# actually build
COPY ./Cargo.toml ./Cargo.toml
COPY ./src ./src
RUN cargo clippy -- -D warnings && \
cargo test && \
cargo build --release --target aarch64-unknown-linux-musl && \
cp /usr/src/chore_planner/target/aarch64-unknown-linux-musl/release/chore_planner /var/run/chore_planner
###############
# final image #
###############
FROM builder_${TARGETARCH} AS builder
FROM --platform=linux/${TARGETARCH} alpine
COPY --from=builder /var/run/chore_planner /var/run/chore_planner
WORKDIR /var/run
ENTRYPOINT ["/var/run/chore_planner"]
LABEL org.opencontainers.image.source=https://github.com/christopher-besch/chore_planner