更新 .github/workflows/buidl_and_push_ghcr.yml
Some checks failed
Gitea Docker Image CI / build (push) Failing after 7s

This commit is contained in:
2025-12-18 06:46:45 +00:00
parent aafc9b9e6f
commit 4105ad5e8a

View File

@@ -2,53 +2,60 @@ name: Gitea Docker Image CI
run-name: Build and Push to Gitea Registry run-name: Build and Push to Gitea Registry
on: on:
workflow_dispatch: # 保留手动触发 workflow_dispatch:
push: # push 事件触发 push:
branches: branches:
- main # 当推送代码到 main 分支时触发 - main
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
# 1. 生成认证配置 # 1. 关键修复:清洗变量
# 这里的逻辑替代了 docker/login-action # 这一步同时处理:
# 我们将 Gitea 自动提供的 Token 写入 Kaniko 需要的 config.json 中 # (1) 去掉 server_url 的 http:// 前缀
# (2) 把仓库名转为全小写 (docker 不支持大写)
- name: Prepare Variables
id: prep
run: |
# 移除 http:// 和 https://
CLEAN_HOST=$(echo "${{ gitea.server_url }}" | sed 's~http[s]*://~~g')
# 转换为全小写
LOWER_REPO=$(echo "${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')
echo "Full Docker Host: $CLEAN_HOST"
echo "Lower Repo Name: $LOWER_REPO"
# 输出给后续步骤使用
echo "registry_host=$CLEAN_HOST" >> $GITHUB_OUTPUT
echo "image_repo=$LOWER_REPO" >> $GITHUB_OUTPUT
# 2. 生成认证配置
- name: Create Kaniko Credentials - name: Create Kaniko Credentials
run: | run: |
mkdir -p $HOME/.docker mkdir -p $HOME/.docker
# 提取 Gitea 的域名 (去掉 http/https 前缀) HOST="${{ steps.prep.outputs.registry_host }}"
DOMAIN=$(echo "${{ gitea.server_url }}" | awk -F/ '{print $3}')
# 生成认证文件
echo "{\"auths\":{\"$DOMAIN\":{\"username\":\"${{ gitea.actor }}\",\"password\":\"${{ secrets.GITHUB_TOKEN }}\"}}}" > $HOME/.docker/config.json
# 2. 准备镜像名称变量 (处理大小写) # 生成 config.json
# 这一步是为了防止用户名或仓库名有大写字母导致构建失败 echo "{\"auths\":{\"$HOST\":{\"username\":\"${{ gitea.actor }}\",\"password\":\"${{ secrets.GITHUB_TOKEN }}\"}}}" > $HOME/.docker/config.json
- name: Prepare Image Name
id: prep
run: |
# 将 gitea.repository (格式: owner/repo) 转换为全小写
IMAGE_NAME=$(echo "${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')
echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
# 3. 使用 Kaniko 构建并推送 # 3. Kaniko 构建
# 替代了 setup-buildx, build 和 push # 注意 destination 这里使用了处理过的 registry_host (不带 http)
- name: Build and Push with Kaniko - name: Build and Push with Kaniko
uses: docker://gcr.io/kaniko-project/executor:debug uses: docker://gcr.io/kaniko-project/executor:debug
env: env:
# 指定 Kaniko 使用我们在第一步生成的认证文件
DOCKER_CONFIG: /github/home/.docker DOCKER_CONFIG: /github/home/.docker
with: with:
# 相当于 docker build . --file Dockerfile
# destination 对应 docker push
args: >- args: >-
--context . --context .
--dockerfile ./Dockerfile --dockerfile ./Dockerfile
--destination ${{ gitea.server_url }}/${{ steps.prep.outputs.image_name }}:latest --destination ${{ steps.prep.outputs.registry_host }}/${{ steps.prep.outputs.image_repo }}:latest
--destination ${{ gitea.server_url }}/${{ steps.prep.outputs.image_name }}:${{ gitea.sha }} --destination ${{ steps.prep.outputs.registry_host }}/${{ steps.prep.outputs.image_repo }}:${{ gitea.sha }}
--force --force
--cache=true --cache=true
--insecure
--skip-tls-verify