diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 7cca7c4..909dd6d 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -34,6 +34,8 @@ jobs: platforms: linux/amd64 push: true tags: ${{ secrets.DOCKER_USERNAME }}/nvd-rs:latest + cache-from: type=gha + cache-to: type=gha,mode=max - name: Build and push helper uses: docker/build-push-action@v5 with: @@ -42,6 +44,8 @@ jobs: platforms: linux/amd64 push: true tags: ${{ secrets.DOCKER_USERNAME }}/nvd-helper-rs:latest + cache-from: type=gha + cache-to: type=gha,mode=max deploy: if: inputs.deploy_to_fly uses: ./.github/workflows/fly.yml diff --git a/Dockerfile b/Dockerfile index 2bf36e2..e637916 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,11 +5,17 @@ WORKDIR /prod COPY .cargo .cargo COPY nvd-server/Cargo.toml Cargo.toml COPY nvd-model/ /nvd-model -RUN cargo fetch -RUN apt-get update -RUN apt-get install -y --no-install-recommends gcc-multilib xz-utils liblz4-tool libc6-dev libssl-dev default-libmysqlclient-dev pkg-config musl-tools patchelf build-essential zlib1g-dev ca-certificates +RUN --mount=type=cache,target=/var/cache/buildkit \ + CARGO_HOME=/var/cache/buildkit/cargo \ + CARGO_TARGET_DIR=/var/cache/buildkit/target \ + cargo fetch +RUN --mount=type=cache,target=/var/lib/cache/ apt-get update \ + apt-get install -y --no-install-recommends gcc-multilib xz-utils liblz4-tool libc6-dev libssl-dev default-libmysqlclient-dev pkg-config musl-tools patchelf build-essential zlib1g-dev ca-certificates COPY nvd-server/src src -RUN cargo build --release --all-features +RUN --mount=type=cache,target=/var/cache/buildkit \ + CARGO_HOME=/var/cache/buildkit/cargo \ + CARGO_TARGET_DIR=/var/cache/buildkit/target \ + cargo build --release --all-features FROM rust:slim-buster AS yew @@ -22,12 +28,18 @@ RUN cargo install --locked wasm-bindgen-cli # 其他模块需要工作区配置 COPY nvd-yew/Cargo.toml Cargo.toml COPY nvd-model/ /nvd-model -RUN cargo fetch +RUN --mount=type=cache,target=/var/cache/buildkit \ + CARGO_HOME=/var/cache/buildkit/cargo \ + CARGO_TARGET_DIR=/var/cache/buildkit/target \ + cargo fetch COPY nvd-yew/index.html index.html COPY nvd-yew/Trunk.toml Trunk.toml COPY nvd-yew/static static COPY nvd-yew/src src -RUN trunk build --release --no-sri +RUN --mount=type=cache,target=/var/cache/buildkit \ + CARGO_HOME=/var/cache/buildkit/cargo \ + CARGO_TARGET_DIR=/var/cache/buildkit/target \ + trunk build --release --no-sri # Use any runner as you want # But beware that some images have old glibc which makes rust unhappy diff --git a/DockerfileHelper b/DockerfileHelper index 5ab6e71..a89fe5a 100644 --- a/DockerfileHelper +++ b/DockerfileHelper @@ -3,21 +3,27 @@ FROM rust:latest AS helper WORKDIR /prod #为了命中docker构建缓存,先拷贝这几个文件进去 COPY .cargo .cargo -RUN apt-get update -RUN apt-get install -y --no-install-recommends gcc-multilib xz-utils liblz4-tool libc6-dev libssl-dev default-libmysqlclient-dev pkg-config musl-tools patchelf build-essential zlib1g-dev ca-certificates +RUN --mount=type=cache,target=/var/lib/cache/ apt-get update \ + apt-get install -y --no-install-recommends gcc-multilib xz-utils liblz4-tool libc6-dev libssl-dev default-libmysqlclient-dev pkg-config musl-tools patchelf build-essential zlib1g-dev ca-certificates COPY .cargo .cargo COPY helper/Cargo.toml Cargo.toml COPY nvd-model/ /nvd-model -RUN cargo fetch +RUN --mount=type=cache,target=/var/cache/buildkit \ + CARGO_HOME=/var/cache/buildkit/cargo \ + CARGO_TARGET_DIR=/var/cache/buildkit/target \ + cargo fetch COPY helper/src src -RUN cargo build --release +RUN --mount=type=cache,target=/var/cache/buildkit \ + CARGO_HOME=/var/cache/buildkit/cargo \ + CARGO_TARGET_DIR=/var/cache/buildkit/target \ + cargo build --release # Use any runner as you want # But beware that some images have old glibc which makes rust unhappy FROM debian:latest AS runner WORKDIR /prod ENV TZ=Asia/Shanghai -RUN apt-get update -RUN apt-get install -y --no-install-recommends libssl-dev default-libmysqlclient-dev ca-certificates +RUN --mount=type=cache,target=/var/lib/cache/ apt-get update \ + apt-get install -y --no-install-recommends libssl-dev default-libmysqlclient-dev ca-certificates COPY --from=helper /prod/target/release/helper /prod ENTRYPOINT [ "/prod/helper" ] \ No newline at end of file