Skip to content

Conversation

@Aqua-218
Copy link

@Aqua-218 Aqua-218 commented Jan 31, 2026

Overview

・リンカーが書かれてはいたけど使われてなかったため修正(.cargo/config.toml)
・不要な依存関係の削除(Cargo.toml、Cargo.lock)
・最適化設定の変更(Cargo.toml)
・Dockerのキャッシュ設定や不要なcargo fixの削除(Dockerfile)

Changes

.cargo/config.toml

linkerをclangに明示的に指定することでmoldが正しく使われるようにした。

Cargo.toml,Cargo.lock

thiserror
anyhow
validator
serde_with

これらのクレートを削除。

Dockerfile

わざとsrc/main.rsに空のfn main() {}を作り、先にCargo.tomlだけを使ってビルドするようにした。
これによりライブラリだけのビルド結果をDockerキャッシュに保存でき、自分のコードを書き替えてもライブラリの再ビルドはスキップできるようにした。

cargo build -j $(nproc)にすることで明示的にすべてのコアを使って並列ビルドできるようにした。

不要なcargo fixを削ることによりビルド時間を短縮した。

Optimization Settings

[profile.release]
lto = "thin"
lto = false
codegen-units = 16
opt-level = 2

Link Time Optimizationの設定をthinにすることで最適化をしながらビルド時間を伸ばさないようにした。
ltoをthinにするとうまくDockerのキャッシュが効かないのでfalseにした。
codegen-unitsを16にすることで並列コンパイルをするようにした。
opt-levelを2にすることで実行速度を十分に確保しつつ、ビルド時間も伸びすぎないようにした。

[profile.dev]
opt-level = 0
debug = 0

最適化を一切せず、デバッグ情報も生成しないようにした。
これによりバイナリサイズが劇的に小さくなりビルド後の書き込み時間を短縮した。

Copilot AI review requested due to automatic review settings January 31, 2026 16:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

ビルド時間短縮を目的に、Rustビルド設定とDockerビルド手順を最適化するPRです。

Changes:

  • .cargo/config.tomlでmuslターゲットのリンカーをclangに固定し、moldを確実に利用
  • 不要な依存関係の削除とsea-ormの不要feature削除、ビルドプロファイル最適化(release/dev
  • Dockerビルドを依存関係先行ビルド+BuildKitキャッシュで高速化(ただし現状キャッシュを壊す行あり)

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
Dockerfile 依存関係を先にビルドしてDockerキャッシュ活用、BuildKit cache mount導入
Cargo.toml 不要依存の削除、sea-orm feature整理、profile最適化追加
Cargo.lock 依存削除に伴うロック更新
.cargo/config.toml musl向けにclangリンカー指定を追加してmold利用を安定化

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


FROM alpine:latest
COPY . .
RUN touch src/main.rs
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RUN touch src/main.rs updates the file timestamp on every build, which makes this layer (and everything after it) effectively uncacheable and reduces build reproducibility. Removing this line (or replacing it with a deterministic cache-busting strategy only when needed) will preserve Docker layer caching and speed up builds.

Suggested change
RUN touch src/main.rs

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これわざと

RUN rm -rf src

FROM alpine:latest
COPY . .
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This COPY . . will send the entire build context into the image. Since the repo has no .dockerignore, it will also include directories like .git/ (and potentially target/ after local builds), which slows builds and can invalidate cache unexpectedly. Consider adding a .dockerignore (or narrowing what gets copied) to keep the build context small and caching effective.

Suggested change
COPY . .
COPY src ./src

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これはぐうの音も出ないから対応した

--mount=type=cache,target=/root/.cargo/git \
cargo build --release -j $(nproc)

FROM alpine:latest
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime stage uses FROM alpine:latest, which pins your base image to a mutable latest tag on Docker Hub; if that tag is ever compromised or updated with a malicious or vulnerable image, every build using this Dockerfile can silently inherit the compromise. To make builds deterministic and reduce supply-chain risk, pin the base image to an immutable reference such as a specific version tag or image digest under your control.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants