Skip to content

Rustコンテナにjustをインストールしたらハマった話

Published: at 22:47

何がおきた

Rustを使用するコンテナの中でJustを使おうとDockerfileを

RUN curl -L "https://github.com/casey/just/releases/download/${JUST_VERSION}/just-${JUST_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
    -o just.tar.gz \
 && tar -xzf just.tar.gz \
 && mv just /usr/local/bin/just \
 && chmod +x /usr/local/bin/just \
 && rm -rf just*

としていた。

その後コンテナ内でCargoコマンド(厳密にはtauriコマンド)を実行したら

$ pnpm run tauri

> stratorapter@0.1.0 tauri /workspace
> tauri dev -- --manifest-path src-tauri/Cargo.toml

failed to get cargo metadata: cargo metadata command exited with a non zero exit code: error: failed to parse manifest at `/Cargo.toml`

Caused by:
  can't find library `just`, rename file to `src/lib.rs` or specify lib.path

       Error failed to get cargo metadata: cargo metadata command exited with a non zero exit code: error: failed to parse manifest at `/Cargo.toml`

Caused by:
  can't find library `just`, rename file to `src/lib.rs` or specify lib.path

と怒られた。

原因

お察しの通り。

RUN curl -L "https://github.com/casey/just/releases/download/${JUST_VERSION}/just-${JUST_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
    -o just.tar.gz \
 && tar -xzf just.tar.gz \
 && mv just /usr/local/bin/just \
 && chmod +x /usr/local/bin/just \
 && rm -rf just*

just.tar.gz/にダウンロードして展開。
最後にお掃除rm -rf just*したつもりになっていた。
が中身は

├── Cargo.lock
├── Cargo.toml
├── GRAMMAR.md
├── LICENSE
├── README.md
├── completions
   ├── just.bash
   ├── just.elvish
   ├── just.fish
   ├── just.nu
   ├── just.powershell
   └── just.zsh
├── just
└── just.1

となっている。
そのため, /直下にCargo.tomlが残っていたためにこちらのファイルを参照してしまっていたようだ。

教訓

  1. 変な場所にcurlしない
  2. ちゃんとお掃除する