更新 .github/workflows/buidl_and_push_ghcr.yml
Some checks failed
Docker Image CI / build (push) Failing after 12s
Some checks failed
Docker Image CI / build (push) Failing after 12s
This commit is contained in:
30
.github/workflows/buidl_and_push_ghcr.yml
vendored
30
.github/workflows/buidl_and_push_ghcr.yml
vendored
@@ -8,11 +8,9 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest # 确保你的 Gitea Runner 注册了这个标签
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
# 【关键配置】在 K8s 中使用 DinD 的标准方式
|
# 声明 DinD 服务
|
||||||
# 如果你的 runner 已经配置了挂载宿主机 docker sock,可以去掉 services 部分
|
|
||||||
# 但对于纯 DinD 模式,建议保留以下配置
|
|
||||||
services:
|
services:
|
||||||
docker:
|
docker:
|
||||||
image: docker:dind
|
image: docker:dind
|
||||||
@@ -20,50 +18,36 @@ jobs:
|
|||||||
ports:
|
ports:
|
||||||
- 2375:2375
|
- 2375:2375
|
||||||
|
|
||||||
# Gitea Actions 默认容器可能没有 git 或 docker 客户端
|
|
||||||
# 指定一个包含常用工具的容器镜像作为执行环境
|
|
||||||
container:
|
container:
|
||||||
image: catthehacker/ubuntu:act-latest
|
image: catthehacker/ubuntu:act-latest
|
||||||
# 告诉容器 Docker 守护进程在哪里 (对应上面的 service)
|
|
||||||
env:
|
env:
|
||||||
DOCKER_HOST: tcp://docker:2375
|
# 【修改点 1】在 K8s Pod 中,sidecar 容器即 localhost
|
||||||
|
DOCKER_HOST: tcp://localhost:2375
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# 设置 Docker Buildx (兼容性最好)
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
with:
|
with:
|
||||||
# 显式指定 endpoint,防止找不到 docker 进程
|
# 【修改点 2】显式指定 endpoint 为 localhost
|
||||||
driver-opts: image=moby/buildkit:master
|
driver-opts: image=moby/buildkit:master
|
||||||
endpoint: tcp://docker:2375
|
endpoint: tcp://localhost:2375
|
||||||
|
|
||||||
# 登录 Gitea 内置的容器镜像仓库
|
|
||||||
- name: Log in to Gitea Container Registry
|
- name: Log in to Gitea Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ gitea.server_url }} # 自动获取你的 Gitea 地址 (带协议)
|
registry: ${{ gitea.server_url }}
|
||||||
# 注意:login action通常只需要域名,如果 server_url 带 http/https 可能需要处理
|
|
||||||
# 建议直接写域名,或者使用下面的这种方式:
|
|
||||||
# registry: git.yourdomain.com
|
|
||||||
username: ${{ gitea.actor }}
|
username: ${{ gitea.actor }}
|
||||||
password: ${{ secrets.GITEA_TOKEN }}
|
password: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
|
||||||
# 构建并推送
|
|
||||||
# 建议使用官方 Action 替代 shell 脚本,因为它能自动处理 Buildx 上下文
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: Dockerfile
|
file: Dockerfile
|
||||||
push: true
|
push: true
|
||||||
# 自动生成 tag
|
|
||||||
tags: |
|
tags: |
|
||||||
${{ gitea.server_url }}/${{ gitea.actor }}/my-docs:latest
|
${{ gitea.server_url }}/${{ gitea.actor }}/my-docs:latest
|
||||||
${{ gitea.server_url }}/${{ gitea.actor }}/my-docs:${{ gitea.sha }}
|
${{ gitea.server_url }}/${{ gitea.actor }}/my-docs:${{ gitea.sha }}
|
||||||
|
|
||||||
# 如果上面 server_url 带了 http:// 前缀导致报错,请手动写死域名,例如:
|
|
||||||
# tags: |
|
|
||||||
# git.example.com/zeroornull/my-docs:latest
|
|
||||||
Reference in New Issue
Block a user