61 lines
2.0 KiB
YAML
61 lines
2.0 KiB
YAML
name: Gitea Docker Image CI
|
|
run-name: Build and Push to Gitea Registry
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
# 1. 关键修复:清洗变量
|
|
# 这一步同时处理:
|
|
# (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
|
|
run: |
|
|
mkdir -p $HOME/.docker
|
|
HOST="${{ steps.prep.outputs.registry_host }}"
|
|
|
|
# 生成 config.json
|
|
echo "{\"auths\":{\"$HOST\":{\"username\":\"${{ gitea.actor }}\",\"password\":\"${{ secrets.PACKAGES_TOKEN }}\"}}}" > $HOME/.docker/config.json
|
|
|
|
# 3. Kaniko 构建
|
|
# 注意 destination 这里使用了处理过的 registry_host (不带 http)
|
|
- name: Build and Push with Kaniko
|
|
uses: docker://gcr.io/kaniko-project/executor:debug
|
|
env:
|
|
DOCKER_CONFIG: /github/home/.docker
|
|
with:
|
|
args: >-
|
|
--context .
|
|
--dockerfile ./Dockerfile
|
|
--destination ${{ steps.prep.outputs.registry_host }}/${{ steps.prep.outputs.image_repo }}:latest
|
|
--destination ${{ steps.prep.outputs.registry_host }}/${{ steps.prep.outputs.image_repo }}:${{ gitea.sha }}
|
|
--force
|
|
--cache=true
|
|
--insecure
|
|
--skip-tls-verify |