Skip to content

Commit 746f3d7

Browse files
authored
chore: speed up docker (#15)
1 parent e50f64b commit 746f3d7

File tree

6 files changed

+88
-30
lines changed

6 files changed

+88
-30
lines changed

crates/audit/Dockerfile

Lines changed: 20 additions & 5 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
12+
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 --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 --bin tips-audit && \
23+
cp target/debug/tips-audit /tmp/tips-audit
924

1025
FROM debian:bookworm
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: 21 additions & 7 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
12+
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 --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 --bin tips-ingress-rpc && \
23+
cp target/debug/tips-ingress-rpc /tmp/tips-ingress-rpc
1024

1125
FROM debian:bookworm
1226

13-
RUN apt-get update && apt-get install -y libssl3 && rm -rf /var/lib/apt/lists/*
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: 21 additions & 7 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
12+
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 --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 --bin tips-ingress-writer && \
23+
cp target/debug/tips-ingress-writer /tmp/tips-ingress-writer
1024

1125
FROM debian:bookworm
1226

13-
RUN apt-get update && apt-get install -y libssl3 && rm -rf /var/lib/apt/lists/*
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: 21 additions & 7 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
12+
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 --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 --bin tips-maintenance && \
23+
cp target/debug/tips-maintenance /tmp/tips-maintenance
1024

1125
FROM debian:bookworm
1226

13-
RUN apt-get update && apt-get install -y libssl3 && rm -rf /var/lib/apt/lists/*
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"]

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ start-all: stop-all
5050
# Start every service in docker, except the one you're currently working on. e.g. just start-except ui ingress-rpc
5151
start-except programs: stop-all
5252
#!/bin/bash
53-
all_services=(postgres kafka kafka-setup minio minio-setup ingress-rpc audit maintenance ui)
53+
all_services=(postgres kafka kafka-setup minio minio-setup ingress-rpc ingres-writer audit maintenance ui)
5454
exclude_services=({{ programs }})
5555

5656
# Create result array with services not in exclude list

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)