Skip to content

Commit f5d5bb1

Browse files
authored
optimize dockerfile (#2066)
1 parent cdbfdee commit f5d5bb1

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

.github/workflows/mono-engine-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ concurrency:
3434
jobs:
3535
build-push-single-arch:
3636
runs-on: ubuntu-latest
37-
timeout-minutes: 30
37+
timeout-minutes: 60
3838

3939
steps:
4040
- uses: actions/checkout@v4

mono/Dockerfile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@
33
# The recipe will change ONLY when Cargo.toml changes.
44
FROM rust:1.94.0-bookworm AS chef
55

6+
ARG TARGETARCH=amd64
7+
ARG CARGO_CHEF_VERSION=0.1.73
8+
69
WORKDIR /opt/mega
710

8-
# Install cargo-chef, a tool to cache Rust dependencies efficiently
9-
RUN cargo install cargo-chef --version 0.1.73
11+
# Prebuilt cargo-chef (avoids compiling it on every cold planner layer).
12+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl \
13+
&& rm -rf /var/lib/apt/lists/* \
14+
&& set -eux \
15+
&& case "$TARGETARCH" in \
16+
amd64) chef_arch=x86_64-unknown-linux-musl ;; \
17+
arm64) chef_arch=aarch64-unknown-linux-gnu ;; \
18+
*) echo "unsupported TARGETARCH=$TARGETARCH" >&2; exit 1 ;; \
19+
esac \
20+
&& curl -fsSL "https://github.com/LukeMathWalker/cargo-chef/releases/download/v${CARGO_CHEF_VERSION}/cargo-chef-${chef_arch}.tar.gz" \
21+
| tar xz -C /usr/local/cargo/bin
1022

1123
COPY Cargo.toml ./
1224
COPY api-model/Cargo.toml api-model/
@@ -43,10 +55,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
4355
libssl-dev \
4456
ca-certificates \
4557
clang \
58+
mold \
4659
protobuf-compiler \
4760
libprotobuf-dev \
4861
&& rm -rf /var/lib/apt/lists/*
4962

63+
# Faster linking (release deps + final mono link).
64+
ENV RUSTFLAGS="-C link-arg=-fuse-ld=mold"
5065

5166
# Copy the dependency recipe from the planner stage
5267
COPY --from=chef /opt/mega/recipe.json recipe.json

0 commit comments

Comments
 (0)