2022-10-31 21:46:34 +00:00
|
|
|
# Builder
|
2024-08-12 14:14:24 +00:00
|
|
|
FROM --platform=linux/amd64 rust:1.79.0-buster AS builder
|
2022-10-31 21:46:34 +00:00
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Add extra build dependencies here
|
2023-09-24 11:43:30 +00:00
|
|
|
RUN apt-get update && apt-get install -yqq \
|
2024-08-12 14:14:24 +00:00
|
|
|
cmake gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
|
2022-10-31 21:46:34 +00:00
|
|
|
|
|
|
|
COPY . .
|
2023-09-19 11:49:32 +00:00
|
|
|
|
2024-08-12 14:14:24 +00:00
|
|
|
RUN rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu
|
2023-09-24 11:43:30 +00:00
|
|
|
|
2024-08-12 14:14:24 +00:00
|
|
|
# Add `--no-default-features` if you don't want stats collection
|
|
|
|
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
|
|
|
--mount=type=cache,target=/app/target \
|
|
|
|
cargo build --release --target=x86_64-unknown-linux-gnu --target=aarch64-unknown-linux-gnu && \
|
|
|
|
# Copy the executables outside of /target as it'll get unmounted after this RUN command
|
|
|
|
cp /app/target/x86_64-unknown-linux-gnu/release/spoticord /app/x86_64 && \
|
|
|
|
cp /app/target/aarch64-unknown-linux-gnu/release/spoticord /app/aarch64
|
2022-10-31 21:46:34 +00:00
|
|
|
|
|
|
|
# Runtime
|
|
|
|
FROM debian:buster-slim
|
|
|
|
|
2023-09-24 11:43:30 +00:00
|
|
|
ARG TARGETPLATFORM
|
2024-08-12 14:14:24 +00:00
|
|
|
ENV TARGETPLATFORM=${TARGETPLATFORM}
|
2022-10-31 21:46:34 +00:00
|
|
|
|
|
|
|
# Add extra runtime dependencies here
|
2024-08-12 14:14:24 +00:00
|
|
|
RUN apt update && apt install -y ca-certificates
|
2023-09-24 11:43:30 +00:00
|
|
|
|
2024-08-12 14:14:24 +00:00
|
|
|
# Copy spoticord binaries from builder to /tmp so we can dynamically use them
|
2023-09-24 20:12:15 +00:00
|
|
|
COPY --from=builder \
|
2024-08-12 14:14:24 +00:00
|
|
|
/app/x86_64 /tmp/x86_64
|
2023-09-24 20:12:15 +00:00
|
|
|
COPY --from=builder \
|
2024-08-12 14:14:24 +00:00
|
|
|
/app/aarch64 /tmp/aarch64
|
2023-09-24 11:43:30 +00:00
|
|
|
|
2024-08-12 14:14:24 +00:00
|
|
|
# Copy appropriate binary for target arch from /tmp
|
|
|
|
RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then \
|
|
|
|
cp /tmp/x86_64 /usr/local/bin/spoticord; \
|
|
|
|
elif [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
|
|
|
cp /tmp/aarch64 /usr/local/bin/spoticord; \
|
2023-09-24 20:12:15 +00:00
|
|
|
fi
|
2023-09-24 11:43:30 +00:00
|
|
|
|
|
|
|
# Delete unused binaries
|
2023-09-24 20:12:15 +00:00
|
|
|
RUN rm -rvf /tmp/x86_64 /tmp/aarch64
|
2023-09-24 11:43:30 +00:00
|
|
|
|
2024-08-12 14:14:24 +00:00
|
|
|
ENTRYPOINT [ "/usr/local/bin/spoticord" ]
|