mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2025-10-22 14:43:10 +00:00
ci(docker-deployment): add dockerhub push workflow file
This commit is contained in:
parent
db05eddb9c
commit
72526ba20d
66
.github/workflows/Build_Image.yml
vendored
66
.github/workflows/Build_Image.yml
vendored
@ -1,31 +1,55 @@
|
||||
name: Build Image
|
||||
name: Publish Docker image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
tags:
|
||||
- v*
|
||||
- "v*"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: github.event.base_ref == 'refs/heads/main'
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
name: Build image job
|
||||
|
||||
steps:
|
||||
- name: Checkout main
|
||||
uses: actions/checkout@v5
|
||||
- name: Get version
|
||||
id: get_version
|
||||
if: startsWith(github.ref, 'refs/tags/') && startsWith(github.repository, 'Binaryify/ncm')
|
||||
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Build and publish image
|
||||
uses: elgohr/Publish-Docker-Github-Action@v5
|
||||
if: startsWith(github.ref, 'refs/tags/') && startsWith(github.repository, 'Binaryify/ncm')
|
||||
# 1️⃣ 检出代码
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# 2️⃣ 设置 Node 环境(可选:若需打包前构建)
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
name: binaryify/netease_cloud_music_api # dockerid/imageName
|
||||
platforms: linux/arm64,linux/amd64 # 你准备构建的镜像平台
|
||||
tags: latest,${{ steps.get_version.outputs.VERSION }}
|
||||
username: ${{ secrets.DOCKER_USERNAME }} # docker hub userid 在setting创建secrets name=DOCKER_USERNAME value=dockerid
|
||||
password: ${{ secrets.DOCKER_PASSWORD }} # docker hub password,在setting创建secrets name=DOCKER_PASSWORD value=dockerpassword
|
||||
node-version: 18
|
||||
|
||||
# 3️⃣ 安装依赖与构建(如果你的 app 直接运行 app.js,可略)
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build (optional)
|
||||
run: |
|
||||
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 }}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user