From 9864eeb21d2a090f8ac2eec568673533d56f5242 Mon Sep 17 00:00:00 2001 From: jiangrui1994 <31405035+jiangrui1994@users.noreply.github.com> Date: Thu, 20 Feb 2025 14:18:26 +0800 Subject: [PATCH] Create docker-image.yml --- .github/workflows/docker-image.yml | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..2a6ede9 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,31 @@ +name: Docker Image CI/CD +on: + push: + branches: [ "main" ] + tags: [ "v*.*.*" ] # 支持标签触发(如 v1.0.0) +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write # 必须授权以推送镜像 + steps: + - name: 检出代码 + uses: actions/checkout@v4 + + - name: 登录到 GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: 构建并推送 Docker 镜像 + uses: docker/build-push-action@v4 + with: + context: . + push: ${{ github.event_name == 'push' }} # 仅推送代码时上传镜像 + tags: | + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{ github.sha }} + ghcr.io/${{ github.repository }}:${{ github.ref_name }}