From b521217db38d9cc2e5ef00d221f4f4ee9b6391e0 Mon Sep 17 00:00:00 2001 From: Marshall Ku Date: Tue, 9 Apr 2024 13:18:03 +0900 Subject: [PATCH] Improve performance of building image with multi stage build --- Dockerfile | 15 +++++++++-- cspell.json | 74 +++++++++++++++++++++++++---------------------------- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7d0d9be..90152e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.73-alpine AS builder +FROM rust:1.73-alpine AS base WORKDIR /usr/src/marshallku-blog-cdn @@ -6,7 +6,18 @@ RUN set -eux; \ apk add --no-cache musl-dev pkgconfig libressl-dev; \ rm -rf $CARGO_HOME/registry -COPY . . +COPY Cargo.* . + +RUN mkdir src && \ + echo 'fn main() {println!("Hello, world!");}' > src/main.rs && \ + cargo build --release && \ + rm target/release/marshallku-blog-cdn* && \ + rm target/release/deps/marshallku_blog_cdn* && \ + rm -rf src + +FROM base AS builder + +COPY src src RUN cargo build --release FROM alpine:3.14 diff --git a/cspell.json b/cspell.json index 148c718..154f823 100644 --- a/cspell.json +++ b/cspell.json @@ -1,41 +1,37 @@ { - "words": [ - "actix", - "addrs", - "autodocs", - "BUILDKIT", - "callout", - "codebases", - "codepoint", - "codepoints", - "hookform", - "iname", - "libressl", - "localforage", - "Malgun", - "marshallku", - "mindepth", - "nextjs", - "pkgconfig", - "preconfigured", - "preconfigures", - "Pretendard", - "Promiseable", - "referer", - "reqwest", - "rfind", - "treeshake", - "tsup", - "Turborepo", - "vercel", - "WEBM", - "WEBP", - "xlink" - ], - "ignorePaths": [ - "Cargo.lock", - "Cargo.toml", - "target", - "config/nginx.conf" - ] + "words": [ + "actix", + "addrs", + "autodocs", + "BUILDKIT", + "callout", + "codebases", + "codepoint", + "codepoints", + "hookform", + "iname", + "libressl", + "localforage", + "Malgun", + "marshallku", + "mindepth", + "nextjs", + "pkgconfig", + "preconfigured", + "preconfigures", + "Pretendard", + "println", + "Promiseable", + "referer", + "reqwest", + "rfind", + "treeshake", + "tsup", + "Turborepo", + "vercel", + "WEBM", + "WEBP", + "xlink" + ], + "ignorePaths": ["Cargo.lock", "Cargo.toml", "target", "config/nginx.conf"] }