From 7eb96d9068b947ec7394489d1eea099eab601fff Mon Sep 17 00:00:00 2001 From: saopig1 <4x7sw862st@gmail.com> Date: Wed, 6 May 2026 17:21:37 +0800 Subject: [PATCH] ci: publish multi-arch Docker image to GHCR on tag push Add GitHub Actions workflow that builds linux/amd64 + linux/arm64 images via buildx + QEMU and pushes to ghcr.io/zhangtianyao1/teamspeak-music-bot on v*.*.* tag pushes (or manual dispatch). Switch docker-compose.yml to pull the prebuilt image so NAS / non-build environments can deploy without a local toolchain. Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/docker-publish.yml | 64 ++++++++++++++++++++++++++++ scripts/docker/docker-compose.yml | 23 +++++++--- 2 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..38384b3 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,64 @@ +name: Build and Publish Docker Image + +on: + push: + tags: + - 'v*.*.*' + workflow_dispatch: + inputs: + tag: + description: 'Extra tag to publish (optional, e.g. "edge")' + required: false + default: '' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: zhangtianyao1/teamspeak-music-bot + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract image metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} + type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: scripts/docker/Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/scripts/docker/docker-compose.yml b/scripts/docker/docker-compose.yml index f836195..6d5ee9d 100644 --- a/scripts/docker/docker-compose.yml +++ b/scripts/docker/docker-compose.yml @@ -1,14 +1,16 @@ # TSMusicBot — Docker Compose -# 一键部署:docker-compose up -d +# 一键部署:docker-compose pull && docker-compose up -d # -# 所有依赖已内置(Node.js, FFmpeg, Opus 编码器)无需安装任何额外软件 -# FFmpeg 使用系统包管理器安装,确保容器内兼容性 +# 默认从 GitHub Container Registry 拉取预构建镜像(amd64 + arm64), +# 无需本地编译,无需 Node.js / 构建工具链。 +# 镜像内置:Node.js, FFmpeg, Opus 编码器,原生模块均已交叉编译。 +# +# 如需指定版本,把 :latest 换成具体 tag(例如 :1.4.0)。 +# 如需本地构建(开发或 fork),见底部注释。 services: tsmusicbot: - build: - context: ../.. - dockerfile: scripts/docker/Dockerfile + image: ghcr.io/zhangtianyao1/teamspeak-music-bot:latest container_name: tsmusicbot # Use host network so the bot can reach TS3 server on LAN # If your TS3 server is on the same machine, this is required @@ -27,3 +29,12 @@ services: volumes: tsmusicbot-data: driver: local + +# ------------------------------------------------------------------ +# 本地构建(仅开发 / fork 场景使用): +# 把上面的 `image:` 行删掉,换成下面的 build 块即可。 +# +# build: +# context: ../.. +# dockerfile: scripts/docker/Dockerfile +# ------------------------------------------------------------------