Files
my-docs/.github/workflows/buidl_and_push_ghcr.yml
gitea_admin f30d0a8a1b
Some checks failed
Docker Image CI / build-and-push (push) Failing after 20s
更新 .github/workflows/buidl_and_push_ghcr.yml
2025-12-18 05:54:58 +00:00

64 lines
2.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Docker Image CI
on:
workflow_dispatch: # 保留手动触发
push:
branches:
- main # 推送代码到 main 分支时触发
jobs:
build-and-push:
runs-on: ubuntu-latest
# 模仿参考配置:指定运行容器,确保包含完整的工具链
container:
image: catthehacker/ubuntu:act-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# 模仿参考配置:提取元数据 (Registry地址, 镜像名, Version)
# Gitea 的 server_url 包含协议头(https://)docker tag 不需要,所以这里处理一下
- name: Get Meta
id: meta
run: |
# 提取域名 (去除 http:// 或 https://)
REGISTRY_HOST=$(echo "${{ gitea.server_url }}" | sed -E 's/^\s*.*:\/\///g')
# 转换为小写,确保镜像名合法
REPO_LOWER=$(echo "${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')
echo "REGISTRY_HOST=$REGISTRY_HOST" >> $GITHUB_OUTPUT
echo "IMAGE_NAME=$REPO_LOWER" >> $GITHUB_OUTPUT
echo "VERSION_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
# 设置 QEMU (支持多架构构建,如果不需要可以注释掉)
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# 设置 Docker Buildx (构建的核心)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 针对 dind-rootless 环境,有时需要显式指定驱动,通常默认即可
# 如果遇到 socket 权限问题,可能需要配置 driver-opts
# 登录 Gitea 内置的容器镜像仓库
- name: Log in to Gitea Registry
uses: docker/login-action@v3
with:
registry: ${{ steps.meta.outputs.REGISTRY_HOST }}
username: ${{ gitea.actor }}
password: ${{ secrets.GITHUB_TOKEN }} # Gitea 会自动生成此 Token拥有推送到包管理器的权限
# 构建并推送
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64 # 根据需要保留或修改架构
tags: |
${{ steps.meta.outputs.REGISTRY_HOST }}/${{ steps.meta.outputs.IMAGE_NAME }}:latest
${{ steps.meta.outputs.REGISTRY_HOST }}/${{ steps.meta.outputs.IMAGE_NAME }}:${{ steps.meta.outputs.VERSION_SHA }}