Skip to content

Commit 0be8da2

Browse files
authored
Merge pull request #2 from junwha/codex/implement-podman-support-with-skopeo-fallback
Add DDIFF_FORCE_PODMAN and install.sh setup flow
2 parents 298ed7e + b84365f commit 0be8da2

3 files changed

Lines changed: 87 additions & 11 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ An efficient Docker image transfer system that extracts the diff of two images a
1111
### Install DockerDiff
1212
```
1313
git clone https://github.com/junwha/DockerDiff
14-
echo "export PATH=$(pwd)/DockerDiff:\$PATH" >> ~/.bashrc && source ~/.bashrc
14+
cd DockerDiff
15+
./install.sh
16+
source ~/.bashrc
1517
```
1618

1719
### Basic Usage: Build on the base image, and load the diff

ddiff.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
ddiff_container_name = os.getenv("DDIFF_CONTAINER_NAME", "ddiff-registry")
3636
ddiff_register_volume = os.getenv("DDIFF_REGISTRY_VOLUME")
3737
ddiff_disable_repository = os.getenv("DDIFF_DISABLE_RESPOSITORY", False)
38+
ddiff_force_skopeo = os.getenv("DDIFF_FORCE_SKOPEO", "").lower() in ["1", "true", "yes", "on"]
39+
ddiff_force_podman = os.getenv("DDIFF_FORCE_PODMAN", "").lower() in ["1", "true", "yes", "on"]
40+
41+
container_runtime = "docker"
42+
container_transport = "docker-daemon"
43+
push_pull_with_skopeo = False
3844

3945
def print_debug(*args):
4046
print("[ddiff]", *args)
@@ -172,27 +178,38 @@ def _upload_manifest(tag, manifest_path, manifest_media_type=DOCKER_MANIFEST_V2)
172178
def run_registry():
173179
volume_arg = "" if ddiff_register_volume is None else f"-v{ddiff_register_volume}:/var/lib/registry"
174180

175-
cmd = f"docker run -it -d -p{ddiff_port}:5000 --name {ddiff_container_name} registry:2.8.3"
181+
tls_verify_flag = " --tls-verify=false" if container_runtime == "podman" else ""
182+
cmd = f"{container_runtime} run -it -d -p{ddiff_port}:5000 {volume_arg} --name {ddiff_container_name}{tls_verify_flag} registry:2.8.3"
176183
run_command(cmd)
177184

178185
def push_images(tags):
179186
print_debug("Pushing to the registry...")
180187
for host_tag in tags:
181188
registry_tag = f"{ddiff_url_base}/{_prepare_tag(host_tag)}"
182-
run_command(f"docker tag {host_tag} {registry_tag}")
183-
print("a", f"docker tag {host_tag} {registry_tag}")
184-
run_command(f"docker push {registry_tag}")
185-
print("b")
186-
run_command(f"docker rmi {registry_tag}")
189+
if push_pull_with_skopeo:
190+
run_command(
191+
f"skopeo copy --dest-tls-verify=false --format=v2s2 "
192+
f"{container_transport}:{host_tag} docker://{registry_tag}"
193+
)
194+
else:
195+
run_command(f"docker tag {host_tag} {registry_tag}")
196+
run_command(f"docker push {registry_tag}")
197+
run_command(f"docker rmi {registry_tag}")
187198
# print_debug("Done.")
188199

189200
def pull_images(tags):
190201
print_debug("Pulling from the registry...")
191202
for host_tag in tags:
192203
registry_tag = f"{ddiff_url_base}/{_prepare_tag(host_tag)}"
193-
run_command(f"docker pull {registry_tag}")
194-
run_command(f"docker tag {registry_tag} {host_tag}")
195-
run_command(f"docker rmi {registry_tag}")
204+
if push_pull_with_skopeo:
205+
run_command(
206+
f"skopeo copy --src-tls-verify=false "
207+
f"docker://{registry_tag} {container_transport}:{host_tag}"
208+
)
209+
else:
210+
run_command(f"docker pull {registry_tag}")
211+
run_command(f"docker tag {registry_tag} {host_tag}")
212+
run_command(f"docker rmi {registry_tag}")
196213
# print_debug("Done.")
197214

198215
def diff_image(base_tag, target_tag):
@@ -311,7 +328,7 @@ def build_image(build_args):
311328
assert not target_tag is None
312329

313330
print_debug(f"Building image with tag: {target_tag}\nwe will diff image blobs of {target_tag} from {base_tag}")
314-
run_command("docker build " + " ".join(build_args))
331+
run_command(f"{container_runtime} build " + " ".join(build_args))
315332
print_debug(f"Diff image blobs of {target_tag} from {base_tag}")
316333
diff_image(base_tag, target_tag)
317334

@@ -331,6 +348,23 @@ def list_blobs(tag):
331348
print(blob.replace("sha256:", ""))
332349

333350
if __name__ == '__main__':
351+
if ddiff_force_podman or shutil.which("docker") is None:
352+
if shutil.which("podman") is None:
353+
print_debug("Docker and podman commands are not available.")
354+
print("Please install podman first (e.g. https://podman.io/docs/installation) and run again.")
355+
sys.exit(0)
356+
357+
container_runtime = "podman"
358+
container_transport = "containers-storage"
359+
push_pull_with_skopeo = True
360+
if ddiff_force_podman:
361+
print_debug("DDIFF_FORCE_PODMAN is enabled. Switching to podman mode.")
362+
else:
363+
print_debug("Docker command not found. Switching to podman mode.")
364+
elif ddiff_force_skopeo:
365+
push_pull_with_skopeo = True
366+
print_debug("DDIFF_FORCE_SKOPEO is enabled. Using skopeo for push/pull.")
367+
334368
if len(sys.argv) < 2 or not sys.argv[1] in ["server", "push", "pull", "diff", "load", "build", "list"]:
335369
print("Usage: ddiff [command] [args...]")
336370
print("Commands:")

install.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
BASHRC_PATH="${HOME}/.bashrc"
6+
PATH_EXPORT="export PATH=${SCRIPT_DIR}:\$PATH"
7+
8+
if ! grep -Fqx "$PATH_EXPORT" "$BASHRC_PATH" 2>/dev/null; then
9+
echo "$PATH_EXPORT" >> "$BASHRC_PATH"
10+
echo "[ddiff] Added ${SCRIPT_DIR} to PATH in ${BASHRC_PATH}."
11+
else
12+
echo "[ddiff] PATH entry already exists in ${BASHRC_PATH}."
13+
fi
14+
15+
if command -v podman >/dev/null 2>&1 && ! command -v skopeo >/dev/null 2>&1; then
16+
echo "[ddiff] podman detected but skopeo is missing. Installing skopeo..."
17+
18+
if command -v apt-get >/dev/null 2>&1; then
19+
sudo apt-get update
20+
sudo apt-get install -y skopeo
21+
elif command -v dnf >/dev/null 2>&1; then
22+
sudo dnf install -y skopeo
23+
elif command -v yum >/dev/null 2>&1; then
24+
sudo yum install -y skopeo
25+
elif command -v pacman >/dev/null 2>&1; then
26+
sudo pacman -Sy --noconfirm skopeo
27+
elif command -v zypper >/dev/null 2>&1; then
28+
sudo zypper --non-interactive install skopeo
29+
elif command -v brew >/dev/null 2>&1; then
30+
brew install skopeo
31+
else
32+
echo "[ddiff] Could not detect a supported package manager."
33+
echo "[ddiff] Please install skopeo manually."
34+
exit 1
35+
fi
36+
37+
echo "[ddiff] skopeo installation complete."
38+
fi
39+
40+
echo "[ddiff] Installation complete. Run: source ~/.bashrc"

0 commit comments

Comments
 (0)