Web Analytics

oci2git

⭐ 401 stars Japanese by Virviil

🌐 言語

OCI2Git

[ドキュメント][documentation] Crates.io ライセンス Downloads

[//]: # (mock for future test.yaml) [//]: # ([![Test Status](https://img.shields.io/github/actions/workflow/status/Virviil/oci2git/rust.yml?branch=master&event=push&label=Test)](https://github.com/Virviil/oci2git/actions))

コンテナイメージ(Dockerなど)をGitリポジトリに変換し、ファイルシステムの部品表(fsbom)をYAML形式で生成するRustアプリケーションです。各コンテナレイヤーはGitコミットとして表現され、元のイメージの履歴と構造を保持します。

Demo of OCI2Git converting the nginx image

特徴

利用例

レイヤー差分

コンテナのトラブルシューティング時、Gitの強力な差分機能を使って、任意の2つのレイヤー間で正確に何が変更されたかを特定できます。git diffでコミット間の差分を確認することで、どのファイルが追加・変更・削除されたかを明確に把握でき、各Dockerfile命令の影響や問題のある変更箇所を簡単に見つけることができます。 Example for layer diff

由来追跡

git blameを使うことで、特定のファイルやコード行がどのレイヤーで導入されたかをすぐに特定できます。これは設定ファイルや依存関係のトラブル解析時に特に有用です。全レイヤーを手動で調査することなく、任意のファイルの由来と対応するDockerfile命令を即座に特定できます。

ファイルのライフサイクル追跡

OCI2Gitを使うことで、特定ファイルがコンテナイメージの履歴を通じてどのように変化したかを追跡できます。ファイルが最初に作成された時期、各レイヤーでどのように変更されたか、そして最終的に削除されたかどうかを観察できます。この包括的な視点により、多数のレイヤーにまたがる変更を手動で追うことなく、ファイルの進化を把握できます。

コンテナイメージ内のファイルの履歴(初出・変更・削除時期など)を変換後に追跡するには、以下のGitコマンドが利用できます。

# Full history of a file (including renames)
git log --follow -- /rootfs/my/file/path

First appearance (i.e. creation) - see which layer introduced the file

git log --diff-filter=A -- /rootfs/my/file/path

All changes made to the file (with diffs)

git log -p --follow -- /rootfs/my/file/path

When the file was deleted

git log --diff-filter=D -- /rootfs/my/file/path

Show short commit info (concise layer history)

git log --follow --oneline -- /rootfs/my/file/path
これらのコマンドにより、レイヤーのtarballを手動で抽出・比較する複雑さなしに、任意のファイルのコンテナレイヤー全体の履歴を簡単に追跡できます。

マルチレイヤー分析

時には、連続していない複数のレイヤー間の変更を調べることが最も洞察に富んだ比較をもたらします。OCI2Gitを使えば、Gitの比較ツールを利用して複数のビルドステージにわたるコンポーネントの進化を分析し、隣接するレイヤーだけを見ていると見えないパターンを特定できます。

レイヤーの探索

git checkoutを使用して任意のコミットに移動することで、そのレイヤーの時点でのコンテナファイルシステムを正確に調べることができます。これにより、開発者はイメージ作成プロセスの任意の時点でのファイルやディレクトリの正確な状態を検査でき、デバッグやコンテナの動作検証時に非常に有用なコンテキストを提供します。 Checkout to previous commit

マルチイメージ分析

共通の起源を持つ複数のコンテナイメージを扱う場合、OCI2Gitは実際にイメージが分岐したときのみブランチを賢く作成します。これにより、共通の履歴を保持しつつ、単一のリポジトリ内で複数の関連イメージを分析できます。

# Convert first image to create the base repository
oci2git postgres:16.9-alpine3.21 -o alp

Convert second image to the same output folder

oci2git nginx:1.28.0-alpine-slim -o alp
OCI2Gitは、イメージ間で共有されているレイヤーを自動的に検出し、それらの共通ベースを反映した分岐構造を作成します。Gitの履歴には以下が表示されます: このアプローチは特に以下の場合に有用です: 共有ベースと分岐するブランチを示すマルチイメージリポジトリ構造

追加ユースケース

インストール

パッケージマネージャー

#### macOS / Linux(Homebrew)

brew tap virviil/oci2git
brew install oci2git

#### Debian / Ubuntu

最新リリースから.debパッケージをダウンロードしてインストールします。

# For amd64 (x86_64)
wget https://github.com/virviil/oci2git/releases/latest/download/oci2git_VERSION_amd64.deb
sudo dpkg -i oci2git_VERSION_amd64.deb

For arm64

wget https://github.com/virviil/oci2git/releases/latest/download/oci2git_VERSION_arm64.deb sudo dpkg -i oci2git_VERSION_arm64.deb

#### Arch Linux(AUR)

# Using yay
yay -S oci2git-bin

Using paru

paru -S oci2git-bin

Manual installation

git clone https://aur.archlinux.org/oci2git-bin.git cd oci2git-bin makepkg -si

事前構築済みバイナリ

ご利用のプラットフォームに適したバイナリを最新リリースからダウンロードしてください:

# Linux x86_64
wget https://github.com/virviil/oci2git/releases/latest/download/oci2git-linux-x86_64.tar.gz
tar xzf oci2git-linux-x86_64.tar.gz
sudo mv oci2git-linux-x86_64 /usr/local/bin/oci2git
chmod +x /usr/local/bin/oci2git

macOS (Apple Silicon)

wget https://github.com/virviil/oci2git/releases/latest/download/oci2git-darwin-aarch64.tar.gz tar xzf oci2git-darwin-aarch64.tar.gz sudo mv oci2git-darwin-aarch64 /usr/local/bin/oci2git chmod +x /usr/local/bin/oci2git

Crates.ioからの入手方法

cargo install oci2git

ソースから

# Clone the repository
git clone https://github.com/virviil/oci2git.git
cd oci2git

Install locally

cargo install --path .

使用方法

oci2git [OPTIONS] 
oci2git convert [OPTIONS] 
oci2git fsbom [OPTIONS] 

convert — OCIイメージ → Gitリポジトリ

oci2git convert [OPTIONS] 

or simply:

oci2git

オプション: -o, --output Gitリポジトリの出力ディレクトリ [デフォルト: ./container_repo] -e, --engine 使用するコンテナエンジン (docker, nerdctl, tar) [デフォルト: docker] -v, --verbose 冗長モード (-vは情報、-vvはデバッグ、-vvvはトレース)

fsbom — ファイルシステム部品表

oci2git fsbom [OPTIONS] 

オプション: -o, --output YAML BOM ファイルの出力パス [デフォルト: ./fsbom.yml] -e, --engine 使用するコンテナエンジン (docker, nerdctl, tar) [デフォルト: docker] -v, --verbose 詳細モード (-v は情報, -vv はデバッグ, -vvv はトレース)

環境変数: TMPDIR この環境変数を設定すると、中間データ処理に使用するデフォルトの場所を変更できます。これはプラットフォーム依存です(例:Unix/macOS では TMPDIR、Windows では TEMP または TMP)。

使用例

変換

Docker エンジンを使用(デフォルト):

oci2git ubuntu:latest

or explicitly:

oci2git convert ubuntu:latest -o ./ubuntu-repo

すでにダウンロードされたイメージtarballを使用する場合:

oci2git convert -e tar -o ./ubuntu-repo /path/to/ubuntu-latest.tar
tarエンジンは有効なOCIフォーマットのtarボールを期待しており、これは通常docker saveで作成されます:

# Create a tarball from a local Docker image
docker save -o ubuntu-latest.tar ubuntu:latest

Convert the tarball to a Git repository

oci2git convert -e tar -o ./ubuntu-repo ubuntu-latest.tar

これにより、./ubuntu-repo に Git リポジトリが作成され、以下の内容が含まれます:

Git の履歴はコンテナのレイヤー履歴を反映します:

ファイルシステム部品表(fsbom)

各レイヤーごとに導入または変更された全ファイルを YAML 形式で生成します:

oci2git fsbom ubuntu:latest -o ubuntu.yml

tarボールの使用:

oci2git fsbom -e tar image.tar -o image-bom.yml
出力されるYAMLは、各レイヤーをリストし、そのエントリをタイプ(filehardlinksymlinkdirectory)とステータス(新規は n:uid:gid、変更は m:uid:gid)でタグ付けします。 削除されたファイル(OCIホワイトアウト)は除外されます。

layers:
  
  • index: 0
command: "ADD rootfs.tar.gz / # buildkit" digest: "sha256:45f3ea58..." entries:
  • type: file
path: "bin/busybox" size: 919304 mode: 493 stat: "n:0:0"
  • type: hardlink
path: "bin/sh" target: "bin/busybox" stat: "n:0:0"
  • type: symlink
path: "lib64" target: "lib" stat: "n:0:0"
  • index: 1
command: "RUN apk add --no-cache curl" digest: "sha256:..." entries:
  • type: file
path: "usr/bin/curl" size: 204800 mode: 493 stat: "n:0:0"
  • type: file
path: "etc/apk/world" size: 32 mode: 420 stat: "m:0:0"

リポジトリ構成

repository/
├── .git/
├── Image.md     # Complete image metadata
└── rootfs/      # Filesystem content from the container

必要条件

ライセンス

MIT

[documentation]: https://docs.rs/oci2git/

--- Tranlated By Open Ai Tx | Last indexed: 2026-04-02 ---