Skip to content

Commit

Permalink
build: make cross-compilation workflow better
Browse files Browse the repository at this point in the history
  • Loading branch information
Veirt committed Aug 2, 2024
1 parent 5022194 commit c777a92
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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-gcc

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-gcc; \
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"]

0 comments on commit c777a92

Please sign in to comment.