Skip to content

Beta Release (Docker) #140

Beta Release (Docker)

Beta Release (Docker) #140

Workflow file for this run

name: Beta Release (Docker)
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- copy
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
GHCR_ORG_NAME: ${{ vars.GHCR_ORG_NAME || 'ironboxplus' }} # 👈 最好改成你的用户名,防止推错地方
IMAGE_NAME: openlist
REGISTRY: ghcr.io
ARTIFACT_NAME: 'binaries_docker_release'
# 👇 关键修改:只保留 linux/amd64,删掉后面一长串
RELEASE_PLATFORMS: 'linux/amd64'
# 👇 关键修改:强制允许推送,不用管是不是 push 事件
IMAGE_PUSH: 'true'
# 👇 使用默认的前端仓库 (OpenListTeam/OpenList-Frontend)
# FRONTEND_REPO: 'Ironboxplus/OpenList-Frontend'
IMAGE_TAGS_BETA: |
type=ref,event=pr
type=raw,value=beta-retry
jobs:
build_binary:
name: Build Binaries (x64 Only)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.25.0'
cache: true
cache-dependency-path: go.sum
# 获取前端仓库的最新commit SHA
- name: Get Frontend Commit SHA
id: frontend-sha
run: |
FRONTEND_REPO="${{ env.FRONTEND_REPO }}"
# 如果未设置FRONTEND_REPO,使用默认值
if [ -z "$FRONTEND_REPO" ]; then
FRONTEND_REPO="OpenListTeam/OpenList-Frontend"
fi
FRONTEND_SHA=$(curl -s https://api.github.com/repos/$FRONTEND_REPO/commits/main | jq -r '.sha')
echo "sha=$FRONTEND_SHA" >> $GITHUB_OUTPUT
echo "repo=$FRONTEND_REPO" >> $GITHUB_OUTPUT
echo "Frontend repo: $FRONTEND_REPO"
echo "Frontend repo latest commit: $FRONTEND_SHA"
# 缓存前端下载 - key包含前端仓库的commit SHA
- name: Cache Frontend
id: cache-frontend
uses: actions/cache@v4
with:
path: public/dist
key: frontend-${{ steps.frontend-sha.outputs.repo }}-${{ steps.frontend-sha.outputs.sha }}
restore-keys: |
frontend-${{ steps.frontend-sha.outputs.repo }}-
# 即使只构建 x64,我们也需要 musl 工具链(因为 BuildDockerMultiplatform 默认会检查它)
- name: Cache Musl
id: cache-musl
uses: actions/cache@v4
with:
path: build/musl-libs
key: docker-musl-libs-v2
- name: Download Musl Library
if: steps.cache-musl.outputs.cache-hit != 'true'
run: bash build.sh prepare docker-multiplatform
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build go binary
# 这里还是跑 docker-multiplatform,虽然会多编译一些架构,但这是兼容 Dockerfile 路径最稳妥的方法
run: bash build.sh beta docker-multiplatform
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# FRONTEND_REPO 使用 build.sh 默认值 (OpenListTeam/OpenList-Frontend)
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
overwrite: true
path: |
build/
!build/*.tgz
!build/musl-libs/**
release_docker:
needs: build_binary
name: Release Docker (x64)
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
matrix:
# 构建所有变体
image: ["latest", "ffmpeg", "aria2", "aio"]
include:
- image: "latest"
base_image_tag: "base"
build_arg: ""
tag_favor: ""
- image: "ffmpeg"
base_image_tag: "ffmpeg"
build_arg: INSTALL_FFMPEG=true
tag_favor: "suffix=-ffmpeg,onlatest=true"
- image: "aria2"
base_image_tag: "aria2"
build_arg: INSTALL_ARIA2=true
tag_favor: "suffix=-aria2,onlatest=true"
- image: "aio"
base_image_tag: "aio"
build_arg: |
INSTALL_FFMPEG=true
INSTALL_ARIA2=true
tag_favor: "suffix=-aio,onlatest=true"
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: 'build/'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 👇 只保留 GitHub 登录,删除了 DockerHub 登录
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.GHCR_ORG_NAME }}/${{ env.IMAGE_NAME }}
tags: ${{ env.IMAGE_TAGS_BETA }}
flavor: ${{ matrix.tag_favor }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.ci
push: true
build-args: |
BASE_IMAGE_TAG=${{ matrix.base_image_tag }}
${{ matrix.build_arg }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ env.RELEASE_PLATFORMS }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.GHCR_ORG_NAME }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.image }}
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.GHCR_ORG_NAME }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.image }},mode=max