Files
my-docs/.github/workflows/buidl_and_push_ghcr.yml
gitea_admin 961d90baa6
Some checks failed
Docker Image CI / build (push) Failing after 1m6s
更新 .github/workflows/buidl_and_push_ghcr.yml
2025-12-18 05:08:27 +00:00

54 lines
1.9 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
jobs:
build:
# 注意Gitea 的 runner 标签需要在 runner 配置文件中定义
# 如果你的 runner 标签不是 ubuntu-latest请修改这里 (例如: linux, host 等)
runs-on: ubuntu-latest
steps:
# 1. 检出代码
# Gitea 会自动从 https://github.com/actions/checkout 镜像或重定向
- name: Checkout code
uses: actions/checkout@v4
# 2. 设置 Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 3. 登录 Gitea 容器镜像仓库
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
# 填写你的 Gitea 域名 (不带 http/https),例如 gitea.example.com
# 如果配置了 defaults也可以留空但显式指定更安全
registry: ${{ gitea.server_url }}
username: ${{ gitea.actor }}
password: ${{ secrets.GITEA_TOKEN }}
# 4. 构建并推送 Docker 镜像
- name: Build and push Docker image
run: |
# 这里的 gitea.server_url 包含协议头(http/s)docker tag 需要去掉协议头
# 下面这行命令提取域名,例如: https://gitea.com -> gitea.com
DOMAIN=$(echo "${{ gitea.server_url }}" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
# 组合镜像名: 域名/用户名/仓库名 (自动转小写)
# 注意Docker 镜像名必须全小写
REPO_LOWER=$(echo "${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')
IMAGE_NAME="$DOMAIN/$REPO_LOWER"
echo "Pushing to: $IMAGE_NAME"
docker build . --file Dockerfile \
--tag "$IMAGE_NAME:latest" \
--tag "$IMAGE_NAME:${{ gitea.sha }}"
docker push "$IMAGE_NAME:latest"
docker push "$IMAGE_NAME:${{ gitea.sha }}"