2023-02-23 11:09:45 +08:00
|
|
|
################
|
|
|
|
##### Builder
|
|
|
|
##### docker buildx create --use --name multi-builder --platform linux/arm64,linux/amd64
|
|
|
|
# https://github.com/docker/buildx/issues/318#issuecomment-1023226339
|
|
|
|
#FROM --platform=$BUILDPLATFORM rustlang/rust:nightly-buster-slim as builder
|
2023-11-23 23:53:49 +08:00
|
|
|
ARG BASE_IMAGE
|
|
|
|
FROM ${BASE_IMAGE} AS builder
|
2023-02-23 11:09:45 +08:00
|
|
|
|
|
|
|
# Installing git because of the workaround for the config
|
|
|
|
# https://github.com/rust-lang/cargo/issues/10781#issuecomment-1441071052
|
|
|
|
RUN apt-get update && apt-get install -y git
|
|
|
|
|
|
|
|
WORKDIR /usr/src/github.com/rust-lang
|
|
|
|
|
|
|
|
# Create blank project
|
|
|
|
RUN USER=root cargo new mdBook
|
|
|
|
|
|
|
|
WORKDIR /usr/src/github.com/rust-lang/mdBook
|
|
|
|
|
|
|
|
## Install target platform (Cross-Compilation) --> Needed for Alpine
|
2023-11-23 23:56:05 +08:00
|
|
|
# Use stable rather than nightly for the build target
|
|
|
|
# Got errors while building after 6 months
|
|
|
|
# https://substrate.stackexchange.com/questions/5379/how-do-i-fix-a-failed-build-error-e0635-unknown-feature-proc-macro-span-shri/9312#9312
|
|
|
|
RUN rustup default stable
|
|
|
|
|
|
|
|
# note: the `x86_64-unknown-linux-musl` target may not be installed
|
2023-02-23 11:09:45 +08:00
|
|
|
RUN rustup target add x86_64-unknown-linux-musl
|
|
|
|
|
2023-11-23 23:56:05 +08:00
|
|
|
# We want dependencies cached, so copy those first.
|
2023-12-19 09:05:26 +08:00
|
|
|
COPY Cargo.toml Cargo.lock /usr/src/github.com/rust-lang/mdBook/
|
2023-11-23 23:56:05 +08:00
|
|
|
# examples is referenced in Cargo.toml
|
|
|
|
COPY examples /usr/src/github.com/rust-lang/mdBook/examples
|
|
|
|
|
|
|
|
# This is a dummy build to pull dependencies and have them cached
|
2023-02-23 11:09:45 +08:00
|
|
|
# https://github.com/rust-lang/cargo/issues/8172#issuecomment-659056517
|
|
|
|
# Very slow builds: https://github.com/rust-lang/cargo/issues/9167#issuecomment-1219251978
|
|
|
|
# Logs verbose: https://github.com/rust-lang/cargo/issues/1106#issuecomment-141555744
|
|
|
|
RUN cargo build -vv --config "net.git-fetch-with-cli=true" --target x86_64-unknown-linux-musl --release
|
|
|
|
|
2023-11-23 23:56:05 +08:00
|
|
|
WORKDIR /usr/src/github.com/rust-lang/mdBook
|
|
|
|
|
2023-02-23 11:09:45 +08:00
|
|
|
# Now copy in the rest of the sources
|
|
|
|
COPY src /usr/src/github.com/rust-lang/mdBook/src
|
|
|
|
|
|
|
|
# This is the actual application build: # ./target/x86_64-unknown-linux-musl/release/mdbook
|
|
|
|
RUN cargo build --locked --bin mdbook --release --target x86_64-unknown-linux-musl
|
|
|
|
|
|
|
|
################
|
|
|
|
##### Runtime
|
2023-11-23 23:58:57 +08:00
|
|
|
FROM alpine:3.18.4 AS runtime
|
2023-02-23 11:09:45 +08:00
|
|
|
|
|
|
|
# Copy application binary from builder image
|
|
|
|
COPY --from=builder /usr/src/github.com/rust-lang/mdBook/target/x86_64-unknown-linux-musl/release/mdbook /usr/local/bin/mdbook
|
|
|
|
|
2023-11-23 23:58:57 +08:00
|
|
|
# Just to document which port a container from this image exposes
|
2023-02-23 11:09:45 +08:00
|
|
|
EXPOSE 3000
|
2023-11-23 23:58:57 +08:00
|
|
|
|
|
|
|
# The command to serve the books
|
2023-02-23 11:09:45 +08:00
|
|
|
ENTRYPOINT ["mdbook", "serve", "--hostname", "0.0.0.0"]
|
2023-11-23 23:58:57 +08:00
|
|
|
|