|
| 1 | +FROM rust:slim |
| 2 | + |
| 3 | +### STEP 1: Install dependencies ### |
| 4 | +# Install packaged dependencies |
| 5 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 6 | + build-essential git curl cmake gcc g++ pkg-config libmagic-dev \ |
| 7 | + libssl-dev zlib1g-dev sudo docker.io |
| 8 | + |
| 9 | +### STEP 2: Create user ### |
| 10 | +ENV HOME=/home/cratesfyi |
| 11 | +RUN adduser --home $HOME --disabled-login --disabled-password --gecos "" cratesfyi |
| 12 | + |
| 13 | +### STEP 3: Setup build environment as new user ### |
| 14 | +ENV CRATESFYI_PREFIX=/home/cratesfyi/prefix |
| 15 | +RUN mkdir $CRATESFYI_PREFIX && chown cratesfyi:cratesfyi "$CRATESFYI_PREFIX" |
| 16 | + |
| 17 | +USER cratesfyi |
| 18 | +RUN mkdir -vp "$CRATESFYI_PREFIX"/documentations "$CRATESFYI_PREFIX"/public_html "$CRATESFYI_PREFIX"/sources |
| 19 | +RUN git clone https://github.com/rust-lang/crates.io-index.git "$CRATESFYI_PREFIX"/crates.io-index |
| 20 | +RUN git --git-dir="$CRATESFYI_PREFIX"/crates.io-index/.git branch crates-index-diff_last-seen |
| 21 | + |
| 22 | +### STEP 4: Build the project ### |
| 23 | +# Build the dependencies in a separate step to avoid rebuilding all of them |
| 24 | +# every time the source code changes. This takes advantage of Docker's layer |
| 25 | +# caching, and it works by copying the Cargo.{toml,lock} with dummy source code |
| 26 | +# and doing a full build with it. |
| 27 | +RUN mkdir -p ~/docs.rs ~/docs.rs/src/web/badge |
| 28 | +WORKDIR $HOME/docs.rs |
| 29 | +COPY --chown=cratesfyi Cargo.lock Cargo.toml ./ |
| 30 | +COPY --chown=cratesfyi src/web/badge src/web/badge/ |
| 31 | +RUN echo "fn main() {}" > src/main.rs && \ |
| 32 | + echo "fn main() {}" > build.rs |
| 33 | + |
| 34 | +RUN cargo fetch |
| 35 | +RUN cargo build --release |
| 36 | + |
| 37 | +### STEP 5: Build the website ### |
| 38 | +# Dependencies are now cached, copy the actual source code and do another full |
| 39 | +# build. The touch on all the .rs files is needed, otherwise cargo assumes the |
| 40 | +# source code didn't change thanks to mtime weirdness. |
| 41 | +RUN rm -rf src build.rs |
| 42 | +COPY --chown=cratesfyi src src/ |
| 43 | +COPY --chown=cratesfyi build.rs build.rs |
| 44 | +COPY --chown=cratesfyi templates templates/ |
| 45 | +RUN touch build.rs && find src -name "*.rs" -exec touch {} \; && cargo build --release |
| 46 | + |
| 47 | +ADD css $CRATESFYI_PREFIX/public_html |
| 48 | + |
| 49 | +ENV DOCS_RS_DOCKER=true |
| 50 | +COPY docker-entrypoint.sh ./ |
| 51 | +USER root |
| 52 | +ENTRYPOINT ./docker-entrypoint.sh |
0 commit comments