Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combine workflows, using choice input for selecting the target platform #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .github/workflows/amd64.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/arm32.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/arm64.yml

This file was deleted.

55 changes: 55 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Export docker images
on:
workflow_dispatch:
inputs:
docker_images:
description: 请填写docker镜像名称 多个用英文逗号分开
required: true
default: 'alpine:latest,ubuntu:latest' # 设置默认的 Docker 镜像列表
arch:
description: 系统架构
required: true
default: amd64
type: choice
options:
- amd64
- arm64
- arm32

jobs:
pull_and_package:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Clean up Docker to free space
run: |
docker system prune -a -f
docker volume prune -f

- name: Pull Docker Images and Package
run: |
platform=${{ github.event.inputs.arch }}
if [[ $platform == 'arm32' ]]; then platform="arm/v7"; fi
images="${{ github.event.inputs.docker_images }}"
IFS=',' read -r -a image_array <<< "$images"
for image in "${image_array[@]}"; do
# trim the prefix or suffix whitespaces, can also use `image=$(echo $image | xargs)`
# see also https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable
image=$(echo $image)
docker pull "${image}" --platform "linux/${{ github.event.inputs.arch }}"
docker save "${image}" -o "${image//\//_}-${{ github.event.inputs.arch }}.tar"
done

- name: Compress the TAR files
run: |
tar -cJf ${{ github.event.inputs.arch }}-images.tar.xz *-${{ github.event.inputs.arch }}.tar

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.inputs.arch }}-docker-images
path: ${{ github.event.inputs.arch }}-images.tar.xz
retention-days: 1 # 将保留天数设置为 1 天 最多可设置90天