Skip to content

Commit

Permalink
Update hangar docker image docs
Browse files Browse the repository at this point in the history
  • Loading branch information
STARRY-S committed Feb 23, 2024
1 parent 5639183 commit 8482b0e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,6 @@ Docker 镜像支持 `amd64` 和 `arm64` 架构。
# 获取镜像
docker pull cnrancher/hangar:${VERSION}

# 获取帮助信息
## 默认情况下 entrypoint 为 hangar 可执行文件
docker run cnrancher/hangar:${VERSION} hangar --help
```

设定 `entrypoint``bash`, 将本地目录挂载到容器中,可在容器内执行 Mirror / Load / Save。

```console
$ docker run --entrypoint bash -v $(pwd):/hangar -it cnrancher/hangar:${VERSION}
a455e1202691:/hangar # hangar -h
Usage: hangar COMMAND [OPTIONS]
......
```

## 在 CI 中运行 Mirror

在 CI Pipeline 中可自动运行 Mirror 命令,可通过设定以下环境变量指定源镜像 Registry 和目标 Registry 以及用户名密码。

- `SOURCE_USERNAME`: 源 Registry 用户名
- `SOURCE_PASSWORD`: 源 Registry 密码
- `SOURCE_REGISTRY`: 源 Registry 地址
- `DEST_USERNAME`: 目标 Registry 用户名
- `DEST_PASSWORD`: 目标 Registry 密码
- `DEST_REGISTRY`: 目标 Registry 地址

----

Example:

```bash
#!/bin/bash

docker run -v $(pwd):/hangar \
-e SOURCE_REGISTRY="" \
-e SOURCE_USERNAME="" \
-e SOURCE_PASSWORD="" \
-e DEST_REGISTRY="" \
-e DEST_USERNAME="" \
-e DEST_PASSWORD="" \
cnrancher/hangar:${VERSION} \
hangar mirror \
-f /hangar/list.txt \
-o /hangar/mirror-failed.txt

# check mirror-failed.txt
cat mirror-failed.txt
# Set `entrypoint` to `bash`, mount the local directory into the container, and execute mirror/load/save in the container:
docker run -v $(pwd):/hangar -it --entrypoint=bash cnrancher/hangar:latest
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,32 @@ Hangar 的 Docker 镜像支持 `amd64` 和 `arm64` 架构。
docker pull cnrancher/hangar:${VERSION}
```

运行 Hangar 命令
在容器中运行 Hangar:

```bash
docker run cnrancher/hangar:${VERSION} hangar --help
docker run -v $(pwd):/hangar -it cnrancher/hangar:latest
```

将本地文件夹映射到容器镜像中,之后在容器镜像中执行 `mirror/save/load/sync` 等命令
因 Entrypoint 为 bash,可通过 bash 的 `-c` 参数指定执行的 Hangar 命令

```bash
docker run -v $(pwd):/hangar -it cnrancher/hangar:${VERSION}
docker run cnrancher/hangar -c "hangar help"
```

## 将 Hangar 集成至 CI

您可以将 `cnrancher/hangar` Docker 镜像作为基础镜像使用在 CI 中,以下是一份样例脚本:

```bash
```bash title="mirror.sh"
#!/bin/bash

docker run -v $(pwd):/hangar cnrancher/hangar:${VERSION} mirror \
# Login to the destination registry server
# (and source registry server if needed) before copy images.
hangar login [DESTINATION_REGISTRY_URL] \
--username="${USERNAME}" \
--password="${PASSWORD}"

hangar mirror \
--file="/hangar/list.txt" \
--source="docker.io" \
--destination="[DESTINATION_REGISTRY_URL]" \
Expand All @@ -48,7 +54,7 @@ if [[ -e "mirror-failed.txt" ]]; then
fi

# Validate the mirrored images (optional)
docker run -v $(pwd):/hangar cnrancher/hangar:${VERSION} mirror validate \
hangar mirror validate \
--file="/hangar/list.txt" \
--source="docker.io" \
--destination="[DESTINATION_REGISTRY_URL]" \
Expand Down
47 changes: 2 additions & 45 deletions versioned_docs/version-v1.6/97-docker-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,6 @@ Docker images support `amd64` and `arm64` architectures.
```sh
docker pull cnrancher/hangar:${VERSION}

# Get help information
# The default entrypoint is hangar binary file
docker run cnrancher/hangar:${VERSION} hangar --help
```

Set `entrypoint` to `bash`, mount the local directory into the container, and execute mirror/load/save in the container:
```console
$ docker run --entrypoint bash -v $(pwd):/hangar -it cnrancher/hangar:${VERSION}
a455e1202691:/hangar # hangar -h
Usage: hangar COMMAND [OPTIONS]
...
```

## Run Mirror in CI

The Mirror command can be run automatically in a CI Pipeline, and the source registry, target registry, and username and password can be specified by setting the following environment variables:

- `SOURCE_USERNAME`: Source registry username
- `SOURCE_PASSWORD`: Source registry password
- `SOURCE_REGISTRY`: Source registry URL
- `DEST_USERNAME`: Destination registry username
- `DEST_PASSWORD`: Destination registry password
- `DEST_REGISTRY`: Destination registry URL

----

Example:

```bash
#!/bin/bash

docker run -v $(pwd):/hangar \
-e SOURCE_REGISTRY="" \
-e SOURCE_USERNAME=""\
-e SOURCE_PASSWORD="" \
-e DEST_REGISTRY=""\
-e DEST_USERNAME=""\
-e DEST_PASSWORD="" \
cnrancher/hangar:${VERSION} \
hangar mirror \
-f /hangar/list.txt \
-o /hangar/mirror-failed.txt

# check mirror-failed.txt
cat mirror-failed.txt
# Set `entrypoint` to `bash`, mount the local directory into the container, and execute mirror/load/save in the container:
docker run -v $(pwd):/hangar -it --entrypoint=bash cnrancher/hangar:latest
```
11 changes: 6 additions & 5 deletions versioned_docs/version-v1.7/97-docker-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ Starting form `v1.7.0`, the entrypoint of hangar image was changed to `bash` ins
docker pull cnrancher/hangar:${VERSION}
```

Execute hangar commands:
Execute hangar commands in the container:

```bash
docker run cnrancher/hangar:${VERSION} hangar --help
docker run -v $(pwd):/hangar -it cnrancher/hangar:latest
```

Mount the local directory into the container, and execute `mirror/load/save/sync` commands inside the container image:
Use the `-c` option of the bash to execute the hangar commands.

```bash
docker run -v $(pwd):/hangar -it cnrancher/hangar:${VERSION}
docker run cnrancher/hangar -c "hangar help"
```

## Integrate Hangar with CI

You can use `cnrancher/hangar` docker image as base image to integrate hangar with CI, here is an example script:

```bash
```bash title="mirror.sh"
#!/bin/bash

# Login to the destination registry server
Expand All @@ -50,6 +50,7 @@ hangar mirror \
# Check mirror-failed.txt
if [[ -e "mirror-failed.txt" ]]; then
echo "There are some images failed to copy:"

cat mirror-failed.txt
exit 1
fi
Expand Down

0 comments on commit 8482b0e

Please sign in to comment.