Build rust image locally

This commit is contained in:
Austen Adler 2023-03-11 18:12:13 -05:00
parent f5d166fdad
commit c49c8219ac

View File

@ -38,67 +38,75 @@ docs:
SAVE ARTIFACT output/* AS LOCAL build/docs/ SAVE ARTIFACT output/* AS LOCAL build/docs/
rust-deps: # rust-deps:
FROM rust:latest # FROM rust:latest
ENV CARGO_HOME=/deps # ENV CARGO_HOME=/deps
WORKDIR /work # WORKDIR /work
COPY ./web/Cargo.toml . # COPY ./web/Cargo.toml .
# This is a binary program, expose a main.rs file # # This is a binary program, expose a main.rs file
RUN mkdir src && touch src/main.rs # RUN mkdir src && touch src/main.rs
RUN cargo fetch # RUN cargo fetch
SAVE ARTIFACT /deps # SAVE ARTIFACT /deps
rust-builder: # rust-builder:
FROM rust:latest # FROM rust:latest
ENV CARGO_HOME=/deps # ENV CARGO_HOME=/deps
WORKDIR /work # WORKDIR /work
# Linux # # Linux
RUN rustup target add x86_64-unknown-linux-musl # RUN rustup target add x86_64-unknown-linux-musl
RUN cargo install cargo-deb # SAVE IMAGE docker-wg:5000/rust-builder
SAVE IMAGE docker-wg:5000/rust-builder # rust-build:
# FROM +rust-builder
build: # COPY +rust-deps/deps /deps
FROM +rust-builder
COPY +rust-deps/deps /deps # ARG TOOLCHAIN
ARG TOOLCHAIN=x86_64-unknown-linux-musl # # Cache whatever dependency builds you can
# COPY ./web/Cargo.toml .
# RUN \
# mkdir src && touch src/lib.rs && \
# cargo build --offline --release --target "$TOOLCHAIN" --jobs 1 && \
# rm src/lib.rs && rmdir src && \
# :
# Cache whatever dependency builds you can # # Actually build the program
COPY ./web/Cargo.toml . # COPY ./web .
RUN \ # RUN cargo build --offline --release --target "$TOOLCHAIN" --jobs 1
mkdir src && touch src/lib.rs && \
cargo build --offline --release --target "$TOOLCHAIN" --jobs 1 && \
rm src/lib.rs && rmdir src && \
:
# Actually build the program # ARG EXT
COPY ./web . # ARG STRIP_CMD=x86_64-linux-gnu-strip
RUN cargo build --offline --release --target "$TOOLCHAIN" --jobs 1 # ARG APP_NAME=web
ARG EXT # RUN if [ "$STRIP_CMD" ]; then "$STRIP_CMD" "target/$TOOLCHAIN/release/$APP_NAME$EXT"; fi
ARG STRIP_CMD=x86_64-linux-gnu-strip # # --force for windows since multiple hardlinks
ARG APP_NAME=web # RUN xz --force --keep "target/$TOOLCHAIN/release/$APP_NAME$EXT"
RUN if [ "$STRIP_CMD" ]; then "$STRIP_CMD" "target/$TOOLCHAIN/release/$APP_NAME$EXT"; fi # # SAVE ARTIFACT target/$TOOLCHAIN/release/$APP_NAME$EXT AS LOCAL dist/
# --force for windows since multiple hardlinks # SAVE ARTIFACT target/$TOOLCHAIN/release/$APP_NAME$EXT.xz AS LOCAL dist/$APP_NAME-$TOOLCHAIN$EXT.xz
RUN xz --force --keep "target/$TOOLCHAIN/release/$APP_NAME$EXT"
# Also build a deb file rust-image:
IF [ -z "${TOOLCHAIN##*-linux-*}" ] FROM scratch
RUN echo "Building deb for ${TOOLCHAIN}"
RUN cargo deb --target "${TOOLCHAIN}"
SAVE ARTIFACT target/$TOOLCHAIN/debian/$APP_NAME_*.deb AS LOCAL dist/ # ARG TOOLCHAIN=x86_64-unknown-linux-musl
END # COPY --build-arg TOOLCHAIN=$TOOLCHAIN +rust-build/work/target/$TOOLCHAIN/release/$APP_NAME /
# SAVE ARTIFACT target/$TOOLCHAIN/release/$APP_NAME$EXT AS LOCAL dist/ COPY ./target/x86_64-unknown-linux-musl/release/web /xpin-web
SAVE ARTIFACT target/$TOOLCHAIN/release/$APP_NAME$EXT.xz AS LOCAL dist/$APP_NAME-$TOOLCHAIN$EXT.xz
ENV ROCKET_ADDRESS=0.0.0.0
ENV ROCKET_PORT=8000
ENV ROCKET_LOG_LEVEL=normal
EXPOSE 8000
ENTRYPOINT ["/xpin-web"]
SAVE IMAGE gitea.austen-wares.com/xpin/server
all: all:
BUILD +docs BUILD +docs
BUILD +build BUILD +rust-image