-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,26 @@ | ||
FROM --platform=$BUILDPLATFORM rust:latest AS builder-base | ||
RUN apt-get update && \ | ||
apt-get install -y ffmpeg pkg-config libssl-dev && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
WORKDIR /app | ||
COPY . . | ||
|
||
FROM builder-base AS builder-amd64 | ||
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=gcc | ||
RUN rustup target add x86_64-unknown-linux-gnu && \ | ||
cargo build --release --target x86_64-unknown-linux-gnu && \ | ||
mv target/x86_64-unknown-linux-gnu/release/backend /app/backend && \ | ||
rm -rf target src Cargo.toml Cargo.lock .git* && \ | ||
find . -type f ! -name 'backend' -delete | ||
|
||
FROM builder-base AS builder-arm64 | ||
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc | ||
RUN dpkg --add-architecture arm64 && \ | ||
apt-get update && \ | ||
apt-get install -y \ | ||
gcc-aarch64-linux-gnu \ | ||
libssl-dev:arm64 \ | ||
pkg-config \ | ||
crossbuild-essential-arm64 && \ | ||
rustup target add aarch64-unknown-linux-gnu && \ | ||
PKG_CONFIG_ALLOW_CROSS=1 \ | ||
PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig \ | ||
PKG_CONFIG_SYSROOT_DIR=/ \ | ||
OPENSSL_DIR=/usr/lib/aarch64-linux-gnu \ | ||
OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu \ | ||
OPENSSL_INCLUDE_DIR=/usr/include/aarch64-linux-gnu \ | ||
AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu \ | ||
AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR=/usr/include/aarch64-linux-gnu \ | ||
cargo build --release --target aarch64-unknown-linux-gnu && \ | ||
mv target/aarch64-unknown-linux-gnu/release/backend /app/backend && \ | ||
rm -rf target src Cargo.toml Cargo.lock .git* && \ | ||
find . -type f ! -name 'backend' -delete | ||
|
||
FROM ubuntu:22.04 AS runtime | ||
FROM rust:1.82.0 AS builder | ||
|
||
RUN USER=root cargo new --bin backend | ||
WORKDIR /backend | ||
|
||
COPY ./Cargo.lock ./Cargo.lock | ||
COPY ./Cargo.toml ./Cargo.toml | ||
|
||
RUN cargo build --release | ||
RUN rm src/*.rs | ||
|
||
COPY ./src ./src | ||
|
||
RUN rm ./target/release/deps/backend* | ||
RUN cargo build --release | ||
|
||
FROM debian:bookworm-slim | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y ffmpeg libssl3 && \ | ||
apt-get clean && \ | ||
apt-get install -y ffmpeg pkg-config libssl3 && \ | ||
rm -rf /var/lib/apt/lists/* | ||
WORKDIR /app | ||
|
||
FROM runtime AS runtime-amd64 | ||
COPY --from=builder-amd64 /app/backend . | ||
|
||
FROM runtime AS runtime-arm64 | ||
COPY --from=builder-arm64 /app/backend . | ||
COPY --from=builder /backend/target/release/backend /usr/local/bin/ | ||
|
||
FROM runtime-$TARGETARCH | ||
EXPOSE 3001 | ||
CMD ["./backend"] | ||
CMD ["backend"] |