Skip to content

Commit

Permalink
add platform option
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe committed Jun 19, 2024
1 parent ac106ff commit 2f5d8fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/download.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@ jobs:
- name: Check out repository code
uses: actions/checkout@v4

- name: Get the image name
id: get-image-name
- name: Get the image info
run: |
TAG_NAME="${GITHUB_REF#refs/tags/}"
IMAGE_NAME="${TAG_NAME//--/:}"
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
tag_name="${GITHUB_REF#refs/tags/}"
image_name="${tag_name//--/:}"
platform="amd64"
regex="(.+)(-amd64|-arm64)$"
if [[ $image_name =~ $regex ]]; then
image_name="${BASH_REMATCH[1]}"
platform="${BASH_REMATCH[2]#-}"
fi
echo "image_name=$image_name" >> $GITHUB_ENV
echo "platform=$platform" >> $GITHUB_ENV
- name: Pull Docker image
run: docker pull "$IMAGE_NAME"
run: docker pull --platform linux/"$platform" "$image_name"

- name: Export Docker image
run: docker save -o image.tar "$IMAGE_NAME"
run: docker save -o image.tar "$image_name"

- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Fork and clone this repository and create a tag by Docker image name, and then t

Note:
- There must not be `:` in git tag, so you should use `--` to represent `:` in the tag name.
- The workflow will use `linux/amd64` platform by default, if you want `linux/arm64` image, you can add suffix `-arm64` in tag name.
- Workflows are not being run on forked repository by default, so you should enable it manually. See [docs](https://docs.github.com/en/actions/using-workflows/disabling-and-enabling-a-workflow?tool=webui#enabling-a-workflow).

For example, you want to download the Docker image `testcontainers/ryuk:0.5.1`, then you should execute the following commands:
Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fork 并 clone 本仓库,并根据需要下载的镜像名称创建 git tag,

注意:
- 因为 git tag 中不能有 `:`,因此你需要使用 `--` 来代替镜像名称中的 `:`
- 工作流默认使用 `linux/amd64` 平台,如果你想要 `linux/arm64` 的镜像,可以在标签名中添加后缀 `-arm64`
- 默认情况下,GitHub Action 在 fork 仓库里是未启用的,因此你可能需要手动启用它。请参阅[文档](https://docs.github.com/en/actions/using-workflows/disabling-and-enabling-a-workflow?tool=webui#enabling-a-workflow)

现在假设你要下载 Docker 镜像 `testcontainers/ryuk:0.5.1`,那么你应该在项目目录执行以下命令:
Expand Down

0 comments on commit 2f5d8fd

Please sign in to comment.