ci(docker-deployment): add dockerhub push workflow file

This commit is contained in:
ElyPrism 2025-10-05 20:51:46 +08:00 committed by GitHub
parent db05eddb9c
commit 72526ba20d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,31 +1,55 @@
name: Build Image name: Publish Docker image
on: on:
push: push:
tags: branches:
- v* - main
- master
tags:
- "v*"
workflow_dispatch:
jobs: jobs:
build: build-and-push:
if: github.event.base_ref == 'refs/heads/main' runs-on: ubuntu-latest
runs-on: ubuntu-latest
name: Build image job
steps: steps:
- name: Checkout main # 1⃣ 检出代码
uses: actions/checkout@v5 - name: Checkout repository
- name: Get version uses: actions/checkout@v4
id: get_version
if: startsWith(github.ref, 'refs/tags/') && startsWith(github.repository, 'Binaryify/ncm') # 2⃣ 设置 Node 环境(可选:若需打包前构建)
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT - name: Set up Node.js
- name: Set up Docker Buildx uses: actions/setup-node@v4
uses: docker/setup-buildx-action@v3 with:
- name: Build and publish image node-version: 18
uses: elgohr/Publish-Docker-Github-Action@v5
if: startsWith(github.ref, 'refs/tags/') && startsWith(github.repository, 'Binaryify/ncm') # 3⃣ 安装依赖与构建(如果你的 app 直接运行 app.js可略
with: - name: Install dependencies
name: binaryify/netease_cloud_music_api # dockerid/imageName run: npm ci
platforms: linux/arm64,linux/amd64 # 你准备构建的镜像平台
tags: latest,${{ steps.get_version.outputs.VERSION }} - name: Build (optional)
username: ${{ secrets.DOCKER_USERNAME }} # docker hub userid 在setting创建secrets name=DOCKER_USERNAME value=dockerid run: |
password: ${{ secrets.DOCKER_PASSWORD }} # docker hub password,在setting创建secrets name=DOCKER_PASSWORD value=dockerpassword echo "Build step skipped — app.js already entry point."
# 4⃣ 登录 Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# 5⃣ 构建并推送镜像
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
moefurina/ncm-api:latest
moefurina/ncm-api:${{ github.sha }}
platforms: linux/amd64,linux/arm64
# 6⃣ (可选)输出镜像摘要
- name: Image digest
run: echo "Pushed image digest ${{ steps.docker_build.outputs.digest }}"