mirror of
https://github.com/jiangrui1994/CloudSaver.git
synced 2026-01-09 14:48:47 +08:00
57 lines
1.8 KiB
YAML
57 lines
1.8 KiB
YAML
name: Docker Image CI/CD
|
||
on:
|
||
push:
|
||
tags: ["v*.*.*"] # 支持标签触发(如 v1.0.0)
|
||
workflow_dispatch: # 添加手动触发
|
||
jobs:
|
||
build-and-push:
|
||
runs-on: ubuntu-latest
|
||
permissions:
|
||
contents: read
|
||
packages: write # 必须授权以推送镜像
|
||
env:
|
||
REPO_NAME: ${{ github.repository }}
|
||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||
IMAGE_NAME: cloudsaver
|
||
steps:
|
||
- name: 检出代码
|
||
uses: actions/checkout@v4
|
||
|
||
- name: 设置小写镜像名称和版本
|
||
run: |
|
||
LOWER_NAME=$(echo "$REPO_NAME" | tr '[:upper:]' '[:lower:]')
|
||
echo "LOWER_NAME=$LOWER_NAME" >> $GITHUB_ENV
|
||
VERSION=${GITHUB_REF#refs/tags/v}
|
||
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
||
|
||
- name: 登录到 GitHub Container Registry
|
||
uses: docker/login-action@v2
|
||
with:
|
||
registry: ghcr.io
|
||
username: ${{ github.actor }}
|
||
password: ${{ secrets.GITHUB_TOKEN }}
|
||
|
||
- name: 登录到 Docker Hub
|
||
uses: docker/login-action@v2
|
||
with:
|
||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||
|
||
- name: 设置 QEMU 支持多架构
|
||
uses: docker/setup-qemu-action@v2
|
||
|
||
- name: 设置 Docker Buildx
|
||
uses: docker/setup-buildx-action@v2
|
||
|
||
- name: 构建并推送 Docker 镜像
|
||
uses: docker/build-push-action@v4
|
||
with:
|
||
context: .
|
||
platforms: linux/amd64,linux/arm64 # 指定架构:x86_64 和 ARM64
|
||
push: true
|
||
tags: |
|
||
ghcr.io/${{ env.LOWER_NAME }}:latest
|
||
ghcr.io/${{ env.LOWER_NAME }}:${{ env.VERSION }}
|
||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
|
||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
|