Compare commits

..
Author SHA1 Message Date
admin 963c80aaa0 ci: 修正 docker tag(分支名 ci/xxx 里的斜杠换成短横线)
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 1m40s
2026-11-24 19:10:04 +08:00
admin be344b97f7 ci: 触发重跑(已配好仓库级 TOKEN secret)
Docker Build (Gitea) / Build and Push Docker Image (push) Failing after 11s
2026-11-24 19:06:21 +08:00
admin 59d23a2dc7 ci: 加 Gitea Actions 构建并推送 Docker 镜像(git.viaeon.com/admin/bepusdt)
Docker Build (Gitea) / Build and Push Docker Image (push) Failing after 3s
2026-11-24 19:00:13 +08:00
+82
View File
@@ -0,0 +1,82 @@
name: Docker Build (Gitea)
on:
push:
branches:
- main
- 'ci/**'
tags:
- 'v*'
workflow_dispatch:
env:
REGISTRY: git.viaeon.com
IMAGE: git.viaeon.com/admin/bepusdt
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu
env:
RUNNER_TOOL_CACHE: /toolcache
steps:
- name: Install Docker CLI
run: |
if ! command -v docker &> /dev/null; then
if command -v apk &> /dev/null; then
apk add --no-cache docker-cli git
elif command -v apt-get &> /dev/null; then
apt-get update && apt-get install -y docker.io git
else
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz | tar xz -C /tmp
mv /tmp/docker/docker /usr/local/bin/
chmod +x /usr/local/bin/docker
fi
fi
docker --version
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Prepare version
id: ver
run: |
SHORT_SHA=$(git rev-parse --short=7 HEAD)
BASE=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
# 分支名可能带斜杠(ci/xxx),docker tag 不允许,统一换成短横线
REF_SLUG=$(echo "${GITHUB_REF_NAME}" | tr '/' '-')
echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "ref_slug=${REF_SLUG}" >> "$GITHUB_OUTPUT"
echo "version=${BASE}-${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "VERSION=${BASE}-${SHORT_SHA}"
- name: Login to Gitea Container Registry
run: |
echo "${{ secrets.TOKEN }}" | docker login "${{ env.REGISTRY }}" -u "${{ github.actor }}" --password-stdin 2>&1
- name: Build Docker image
run: |
docker build \
--label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--build-arg "VERSION=${{ steps.ver.outputs.version }}" \
-t "${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }}" \
-t "${{ env.IMAGE }}:${{ steps.ver.outputs.ref_slug }}" \
-t "${{ env.IMAGE }}:latest" .
- name: Push Docker image
run: |
docker push "${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }}" 2>&1
docker push "${{ env.IMAGE }}:${{ steps.ver.outputs.ref_slug }}" 2>&1
docker push "${{ env.IMAGE }}:latest" 2>&1
- name: Summary
run: |
echo "镜像已推送:"
echo " ${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }}"
echo " ${{ env.IMAGE }}:${{ steps.ver.outputs.ref_slug }}"
echo " ${{ env.IMAGE }}:latest"