diff --git a/Dockerfile b/Dockerfile index 5d0b3f3..d0aaa08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM oven/bun:1-alpine AS css-builder +FROM --platform=$BUILDPLATFORM oven/bun:1-alpine AS css-builder WORKDIR /temp COPY package.json bun.lockb ./ RUN bun install --frozen-lockfile @@ -7,23 +7,33 @@ COPY tailwind.config.js . COPY src ./src RUN bunx tailwindcss -i ./src/style.css -o ./out.css --minify -FROM --platform=$TARGETPLATFORM rust:1.80-alpine AS build +FROM --platform=$BUILDPLATFORM rust:1.80-alpine AS build ARG TARGETPLATFORM +ENV TARGETPLATFORM=${TARGETPLATFORM} -RUN apk add musl-dev --no-cache +RUN apk add musl-dev --no-cache && rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl WORKDIR /usr/src RUN USER=root cargo new --bin vesta WORKDIR /usr/src/vesta COPY Cargo.toml Cargo.lock ./ COPY src ./src -RUN cargo build --release +# Determine the correct target triple based on the platform +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + export TARGET=x86_64-unknown-linux-musl; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + export TARGET=aarch64-unknown-linux-musl; \ + else \ + echo "Unsupported platform: $TARGETPLATFORM"; \ + exit 1; \ + fi && \ + cargo build --release --target $TARGET FROM scratch WORKDIR /app COPY ./static static COPY --from=css-builder /temp/out.css ./static/style.css -COPY --from=build /usr/src/vesta/target/release/vesta /app/vesta +COPY --from=build /usr/src/vesta/target/$TARGET/release/vesta /app/vesta CMD ["/app/vesta"]