Skip to content

Release Docker Image #188

Release Docker Image

Release Docker Image #188

Workflow file for this run

name: Release Docker Image
on:
workflow_call: # TODO
workflow_dispatch:
inputs:
image_tag:
description: '镜像标签,留空则使用 package.json 中的版本号。务必注意:请确认选择了正确的分支。完整输入示例:0.35.24072117-E1 '
required: false
default: ''
channel:
description: "发行渠道"
required: true
type: choice
options:
- T
- R & Rococo & latest
- P & Pioneer
- C & Canary
- E & Emo
- S_Gibbet
- D_Gibbet
# ref https://docs.github.com/zh/actions/learn-github-actions/variables
env:
repo_name_android: "Sillot-android"
repo_name: "Sillot"
repo_owner: "Hi-Windom"
package_json: "package.json"
docker_hub_readme: "./.github/docs/docker/README.md"
docker_hub_owner: "soltus"
docker_hub_repo: "sillot"
jobs:
setup:
runs-on: ubuntu-latest
outputs:
docker_file: ${{ steps.set-vars.outputs.docker_file }}
steps:
- name: Set variables based on input name
id: set-vars
run: |
# 定义映射关系
declare -A dockerFileMap=(
["T"]="docker/T.Dockerfile"
["R & Rococo & latest"]="docker/R.Dockerfile"
["P & Pioneer"]="docker/P.Dockerfile"
["C & Canary"]="docker/C.Dockerfile"
["E & Emo"]="docker/E.Dockerfile"
["S_Gibbet"]="docker/S_Gibbet.Dockerfile"
["D_Gibbet"]="docker/D_Gibbet.Dockerfile"
)
channel="${{ github.event.inputs.channel }}"
docker_file="${dockerFileMap[$channel]}"
echo "docker_file=$docker_file" >>$GITHUB_OUTPUT
build:
name: Release Docker Image
needs: [setup]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: ☄️ Checkout repository and submodules
uses: actions/checkout@v4
with:
ref: ${{ github.event.ref }}
submodules: recursive
- name: 💫 Extract Sillot version from package.json
uses: sergeysova/jq-action@v2
id: version
with:
cmd: "jq .version ${{ env.package_json }} -r"
- name: 🗑️ Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true
# 设置 up QEMU 用于多架构构建
- name: 🔨 Set up QEMU
uses: docker/setup-qemu-action@v3
- name: 🔨 Setup Docker buildx
uses: docker/setup-buildx-action@v3
- name: 🔗 Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PWD }}
- name: 🔥 Build the Docker image use Workflow Dispatch inputs' version
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.image_tag != '' && github.event.inputs.image_tag != null }}
run: |
# Check if the channel input contains '&', if not, it's a single tag
if [[ "${{ github.event.inputs.channel }}" == *" & "* ]]; then
# Split the channel input by ' & ' to get an array of tags
IFS=' & ' read -ra TAGS <<< "${{ github.event.inputs.channel }}"
else
# Use the channel input as a single tag
TAGS=("${{ github.event.inputs.channel }}")
fi
# Construct the -t options for the docker buildx command
TAG_ARGS=()
for TAG in "${TAGS[@]}"; do
TAG_ARGS+=("-t" "${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:$TAG")
if [ "$TAG" != "latest" ]; then
TAG_ARGS+=("-t" "${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:$TAG-${{ github.event.inputs.image_tag }}")
fi
done
# Run the docker buildx command once with all the -t options
docker buildx build --push --platform linux/amd64 \
--file ${{ needs.setup.outputs.docker_file }} \
"${TAG_ARGS[@]}" \
.
- name: 🔥 Build the Docker image use package_json version
if: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.image_tag == '' || github.event.inputs.image_tag == null) }}
run: |
# Check if the channel input contains '&', if not, it's a single tag
if [[ "${{ github.event.inputs.channel }}" == *" & "* ]]; then
# Split the channel input by ' & ' to get an array of tags
IFS=' & ' read -ra TAGS <<< "${{ github.event.inputs.channel }}"
else
# Use the channel input as a single tag
TAGS=("${{ github.event.inputs.channel }}")
fi
# Construct the -t options for the docker buildx command
TAG_ARGS=()
for TAG in "${TAGS[@]}"; do
TAG_ARGS+=("-t" "${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:$TAG")
if [ "$TAG" != "latest" ]; then
TAG_ARGS+=("-t" "${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }}:$TAG-${{ steps.version.outputs.value }}")
fi
done
# Run the docker buildx command once with all the -t options
docker buildx build --push --platform linux/amd64 \
--file ${{ needs.setup.outputs.docker_file }} \
"${TAG_ARGS[@]}" \
.
- name: 📤 Update Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PWD }}
repository: ${{ env.docker_hub_owner }}/${{ env.docker_hub_repo }} # 这是 docker hub 的不是 github 的
readme-filepath: ${{ env.docker_hub_readme }}
short-description: ${{ github.event.repository.description }}
enable-url-completion: false