From f5d166fdadb7f58b7d8b079136acfe66f7e77080 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sat, 11 Mar 2023 17:50:23 -0500 Subject: [PATCH] Start work on building final docker image --- build.earth | 112 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 87 insertions(+), 25 deletions(-) diff --git a/build.earth b/build.earth index 3b1b764..1495de8 100644 --- a/build.earth +++ b/build.earth @@ -1,42 +1,104 @@ VERSION 0.6 docs-build: - FROM ruby:latest + FROM ruby:latest - WORKDIR /app + WORKDIR /app - RUN gem install coderay - RUN gem install rouge - RUN gem install asciidoctor + RUN gem install coderay + RUN gem install rouge + RUN gem install asciidoctor - # These dependencies are required for asciidoctor-mathematical - RUN apt-get update - RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install bison flex libffi-dev libxml2-dev libgdk-pixbuf2.0-dev libcairo2-dev libpango1.0-dev fonts-lyx cmake - RUN gem install asciidoctor-mathematical + # These dependencies are required for asciidoctor-mathematical + RUN apt-get update + RUN DEBIAN_FRONTEND=noninteractive apt-get -qq -y install bison flex libffi-dev libxml2-dev libgdk-pixbuf2.0-dev libcairo2-dev libpango1.0-dev fonts-lyx cmake + RUN gem install asciidoctor-mathematical - COPY ./README.adoc docs/index.adoc - COPY --dir ./docs . + COPY ./README.adoc docs/index.adoc + COPY --dir ./docs . - RUN asciidoctor -r asciidoctor-mathematical -a mathematical-format=svg -a "!webfonts" -- ./docs/*.adoc - RUN \ - find docs -type f -not -iname '*.html' -not -iname '*.png' -not -iname '*.svg' -delete && \ - : + RUN asciidoctor -r asciidoctor-mathematical -a mathematical-format=svg -a "!webfonts" -- ./docs/*.adoc + RUN \ + find docs -type f -not -iname '*.html' -not -iname '*.png' -not -iname '*.svg' -delete && \ + : - SAVE ARTIFACT ./docs + SAVE ARTIFACT ./docs docs: - FROM golang:latest - WORKDIR /app + FROM golang:latest + WORKDIR /app - GIT CLONE https://github.com/tdewolff/minify/ minify/ + GIT CLONE https://github.com/tdewolff/minify/ minify/ - RUN cd minify && go install ./cmd/minify + RUN cd minify && go install ./cmd/minify - COPY +docs-build/docs/ ./docs/ - RUN minify --version - RUN minify --sync --recursive --output output/ ./docs/ + COPY +docs-build/docs/ ./docs/ + RUN minify --version + RUN minify --sync --recursive --output output/ ./docs/ - SAVE ARTIFACT output/* AS LOCAL build/docs/ + SAVE ARTIFACT output/* AS LOCAL build/docs/ + +rust-deps: + FROM rust:latest + ENV CARGO_HOME=/deps + WORKDIR /work + + COPY ./web/Cargo.toml . + # This is a binary program, expose a main.rs file + RUN mkdir src && touch src/main.rs + RUN cargo fetch + SAVE ARTIFACT /deps + +rust-builder: + FROM rust:latest + ENV CARGO_HOME=/deps + WORKDIR /work + + # Linux + RUN rustup target add x86_64-unknown-linux-musl + + RUN cargo install cargo-deb + + SAVE IMAGE docker-wg:5000/rust-builder + +build: + FROM +rust-builder + + COPY +rust-deps/deps /deps + + 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 && \ + : + + # Actually build the program + COPY ./web . + RUN cargo build --offline --release --target "$TOOLCHAIN" --jobs 1 + + ARG EXT + ARG STRIP_CMD=x86_64-linux-gnu-strip + ARG APP_NAME=web + + RUN if [ "$STRIP_CMD" ]; then "$STRIP_CMD" "target/$TOOLCHAIN/release/$APP_NAME$EXT"; fi + # --force for windows since multiple hardlinks + RUN xz --force --keep "target/$TOOLCHAIN/release/$APP_NAME$EXT" + + # Also build a deb file + IF [ -z "${TOOLCHAIN##*-linux-*}" ] + RUN echo "Building deb for ${TOOLCHAIN}" + RUN cargo deb --target "${TOOLCHAIN}" + + SAVE ARTIFACT target/$TOOLCHAIN/debian/$APP_NAME_*.deb AS LOCAL dist/ + END + + # SAVE ARTIFACT target/$TOOLCHAIN/release/$APP_NAME$EXT AS LOCAL dist/ + SAVE ARTIFACT target/$TOOLCHAIN/release/$APP_NAME$EXT.xz AS LOCAL dist/$APP_NAME-$TOOLCHAIN$EXT.xz all: - BUILD +docs + BUILD +docs + BUILD +build