Skip to content

Commit

Permalink
docker mount cache (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris authored Jun 4, 2024
1 parent aad9483 commit 21e6470
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,4 @@ jobs:
contents: read
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- run: make login
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}

- run: make test-build-with-latest
23 changes: 17 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# syntax=docker/dockerfile:1
ARG BASE_IMAGE

FROM rust:1.78-slim-bookworm AS builder
FROM rust:1.78.0-slim-bookworm AS builder

ARG TARGETPLATFORM
ARG MDBOOK_VERSION
Expand All @@ -9,18 +10,28 @@ ARG MDBOOK_MERMAID_VERSION
ARG MDBOOK_TOC_VERSION
ARG MDBOOK_ADMONISH_VERSION

RUN apt-get update && \
ENV CARGO_TARGET_DIR="/usr/local/cargo-target"

RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,sharing=locked,target=/var/cache/apt \
--mount=type=cache,sharing=locked,target=/var/lib/apt \
apt-get update && \
apt-get install --no-install-recommends -y \
musl-tools \
file
RUN rustup target add "${CARGO_TARGET}"
RUN cargo install mdbook --version "${MDBOOK_VERSION}" --target "${CARGO_TARGET}" && \
RUN --mount=type=cache,sharing=locked,target=/usr/local/cargo-target \
cargo install mdbook --version "${MDBOOK_VERSION}" --target "${CARGO_TARGET}" && \
strip "$(which mdbook)"
RUN cargo install mdbook-mermaid --version "${MDBOOK_MERMAID_VERSION}" --target "${CARGO_TARGET}" && \
RUN --mount=type=cache,sharing=locked,target=/usr/local/cargo-target \
cargo install mdbook-mermaid --version "${MDBOOK_MERMAID_VERSION}" --target "${CARGO_TARGET}" && \
strip "$(which mdbook-mermaid)"
RUN cargo install mdbook-toc --version "${MDBOOK_TOC_VERSION}" --target "${CARGO_TARGET}" && \
RUN --mount=type=cache,sharing=locked,target=/usr/local/cargo-target \
cargo install mdbook-toc --version "${MDBOOK_TOC_VERSION}" --target "${CARGO_TARGET}" && \
strip "$(which mdbook-toc)"
RUN cargo install mdbook-admonish --version "${MDBOOK_ADMONISH_VERSION}" --target "${CARGO_TARGET}" && \
RUN --mount=type=cache,sharing=locked,target=/usr/local/cargo-target \
cargo install mdbook-admonish --version "${MDBOOK_ADMONISH_VERSION}" --target "${CARGO_TARGET}" && \
strip "$(which mdbook-admonish)"

FROM ${BASE_IMAGE}
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ build-alpine:
--cache-from "type=gha,scope=${DOCKER_SCOPE}" \
--cache-to "type=gha,mode=max,scope=${DOCKER_SCOPE}" \
--build-arg MDBOOK_VERSION="${DOCKER_VERSION}" \
--build-arg BASE_IMAGE="alpine:3.20" \
--build-arg BASE_IMAGE="alpine:3.20.0" \
--build-arg MDBOOK_MERMAID_VERSION="${MDBOOK_MERMAID_VERSION}" \
--build-arg MDBOOK_TOC_VERSION="${MDBOOK_TOC_VERSION}" \
--build-arg MDBOOK_ADMONISH_VERSION="${MDBOOK_ADMONISH_VERSION}" \
Expand All @@ -75,7 +75,7 @@ build-rust:
--cache-from "type=gha,scope=${DOCKER_SCOPE}" \
--cache-to "type=gha,mode=max,scope=${DOCKER_SCOPE}" \
--build-arg MDBOOK_VERSION="${DOCKER_VERSION}" \
--build-arg BASE_IMAGE="rust:1.78-alpine3.20" \
--build-arg BASE_IMAGE="rust:1.78.0-alpine3.20" \
--build-arg MDBOOK_MERMAID_VERSION="${MDBOOK_MERMAID_VERSION}" \
--build-arg MDBOOK_TOC_VERSION="${MDBOOK_TOC_VERSION}" \
--build-arg MDBOOK_ADMONISH_VERSION="${MDBOOK_ADMONISH_VERSION}" \
Expand Down

0 comments on commit 21e6470

Please sign in to comment.