Skip to content

Commit 7375fff

Browse files
committed
chore: speed up docker
1 parent 0a3c56d commit 7375fff

File tree

5 files changed

+91
-33
lines changed

5 files changed

+91
-33
lines changed

crates/audit/Dockerfile

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
FROM rust:1-bookworm AS builder
1+
FROM rust:1-bookworm AS base
22

3+
RUN cargo install cargo-chef --locked
34
WORKDIR /app
45

5-
COPY Cargo.toml Cargo.lock ./
6-
COPY crates/ ./crates/
6+
FROM base AS planner
7+
COPY . .
8+
RUN cargo chef prepare --recipe-path recipe.json
79

8-
RUN cargo build --bin tips-audit
10+
FROM base AS builder
11+
COPY --from=planner /app/recipe.json recipe.json
912

10-
FROM debian:bookworm
13+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
14+
--mount=type=cache,target=/usr/local/cargo/git \
15+
--mount=type=cache,target=/app/target \
16+
cargo chef cook --release --recipe-path recipe.json
17+
18+
COPY . .
19+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
20+
--mount=type=cache,target=/usr/local/cargo/git \
21+
--mount=type=cache,target=/app/target \
22+
cargo build --release --bin tips-audit && \
23+
cp target/release/tips-audit /tmp/tips-audit
24+
25+
FROM debian:bookworm-slim
1126

1227
RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/*
1328

1429
WORKDIR /app
1530

16-
COPY --from=builder /app/target/debug/tips-audit /app/tips-audit
31+
COPY --from=builder /tmp/tips-audit /app/tips-audit
1732

1833
EXPOSE 3001
1934

crates/ingress-rpc/Dockerfile

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1-
FROM rust:1-bookworm AS builder
1+
FROM rust:1-bookworm AS base
22

3+
RUN cargo install cargo-chef --locked
34
WORKDIR /app
45

5-
COPY Cargo.toml Cargo.lock ./
6-
COPY crates/ ./crates/
7-
COPY .sqlx/ ./.sqlx/
6+
FROM base AS planner
7+
COPY . .
8+
RUN cargo chef prepare --recipe-path recipe.json
89

9-
RUN cargo build --bin tips-ingress-rpc
10+
FROM base AS builder
11+
COPY --from=planner /app/recipe.json recipe.json
1012

11-
FROM debian:bookworm
13+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
14+
--mount=type=cache,target=/usr/local/cargo/git \
15+
--mount=type=cache,target=/app/target \
16+
cargo chef cook --release --recipe-path recipe.json
1217

13-
RUN apt-get update && apt-get install -y libssl3 && rm -rf /var/lib/apt/lists/*
18+
COPY . .
19+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
20+
--mount=type=cache,target=/usr/local/cargo/git \
21+
--mount=type=cache,target=/app/target \
22+
cargo build --release --bin tips-ingress-rpc && \
23+
cp target/release/tips-ingress-rpc /tmp/tips-ingress-rpc
24+
25+
FROM debian:bookworm-slim
26+
27+
RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/*
1428

1529
WORKDIR /app
1630

17-
COPY --from=builder /app/target/debug/tips-ingress-rpc /app/tips-ingress-rpc
31+
COPY --from=builder /tmp/tips-ingress-rpc /app/tips-ingress-rpc
1832

1933
EXPOSE 3000
2034

crates/ingress-writer/Dockerfile

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
FROM rust:1-bookworm AS builder
1+
FROM rust:1-bookworm AS base
22

3+
RUN cargo install cargo-chef --locked
34
WORKDIR /app
45

5-
COPY Cargo.toml Cargo.lock ./
6-
COPY crates/ ./crates/
7-
COPY .sqlx/ ./.sqlx/
6+
FROM base AS planner
7+
COPY . .
8+
RUN cargo chef prepare --recipe-path recipe.json
89

9-
RUN cargo build --bin tips-ingress-writer
10+
FROM base AS builder
11+
COPY --from=planner /app/recipe.json recipe.json
1012

11-
FROM debian:bookworm
13+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
14+
--mount=type=cache,target=/usr/local/cargo/git \
15+
--mount=type=cache,target=/app/target \
16+
cargo chef cook --release --recipe-path recipe.json
1217

13-
RUN apt-get update && apt-get install -y libssl3 && rm -rf /var/lib/apt/lists/*
18+
COPY . .
19+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
20+
--mount=type=cache,target=/usr/local/cargo/git \
21+
--mount=type=cache,target=/app/target \
22+
cargo build --release --bin tips-ingress-writer && \
23+
cp target/release/tips-ingress-writer /tmp/tips-ingress-writer
24+
25+
FROM debian:bookworm-slim
26+
27+
RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/*
1428

1529
WORKDIR /app
1630

17-
COPY --from=builder /app/target/debug/tips-ingress-writer /app/tips-ingress-writer
31+
COPY --from=builder /tmp/tips-ingress-writer /app/tips-ingress-writer
1832

1933
CMD ["/app/tips-ingress-writer"]

crates/maintenance/Dockerfile

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
FROM rust:1-bookworm AS builder
1+
FROM rust:1-bookworm AS base
22

3+
RUN cargo install cargo-chef --locked
34
WORKDIR /app
45

5-
COPY Cargo.toml Cargo.lock ./
6-
COPY crates/ ./crates/
7-
COPY .sqlx/ ./.sqlx/
6+
FROM base AS planner
7+
COPY . .
8+
RUN cargo chef prepare --recipe-path recipe.json
89

9-
RUN cargo build --bin tips-maintenance
10+
FROM base AS builder
11+
COPY --from=planner /app/recipe.json recipe.json
1012

11-
FROM debian:bookworm
13+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
14+
--mount=type=cache,target=/usr/local/cargo/git \
15+
--mount=type=cache,target=/app/target \
16+
cargo chef cook --release --recipe-path recipe.json
1217

13-
RUN apt-get update && apt-get install -y libssl3 && rm -rf /var/lib/apt/lists/*
18+
COPY . .
19+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
20+
--mount=type=cache,target=/usr/local/cargo/git \
21+
--mount=type=cache,target=/app/target \
22+
cargo build --release --bin tips-maintenance && \
23+
cp target/release/tips-maintenance /tmp/tips-maintenance
24+
25+
FROM debian:bookworm-slim
26+
27+
RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/*
1428

1529
WORKDIR /app
1630

17-
COPY --from=builder /app/target/debug/tips-maintenance /app/tips-maintenance
31+
COPY --from=builder /tmp/tips-maintenance /app/tips-maintenance
1832

1933
CMD ["/app/tips-maintenance"]

ui/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
FROM node:20-alpine AS deps
22
WORKDIR /app
33
COPY ui/package.json ui/yarn.lock ./
4-
RUN yarn install --frozen-lockfile
4+
RUN --mount=type=cache,target=/root/.yarn \
5+
yarn install --frozen-lockfile
56

67
FROM node:20-alpine AS builder
78
WORKDIR /app
@@ -10,7 +11,8 @@ COPY ./ui .
1011

1112
ENV NEXT_TELEMETRY_DISABLED=1
1213

13-
RUN yarn build
14+
RUN --mount=type=cache,target=/app/.next/cache \
15+
yarn build
1416

1517
FROM node:20-alpine AS runner
1618
WORKDIR /app
@@ -21,7 +23,6 @@ ENV NEXT_TELEMETRY_DISABLED=1
2123
RUN addgroup --system --gid 1001 nodejs
2224
RUN adduser --system --uid 1001 nextjs
2325

24-
2526
RUN mkdir .next
2627
RUN chown nextjs:nodejs .next
2728

0 commit comments

Comments
 (0)