Files
way-node/.gitea/workflows/build.yml
T
admin 81e47d4b12
Build way-node / Build and Push (push) Successful in 1m10s
fix: 镜像与 release 都带上 xbctl
装 way-node 时报:
  curl: (22) The requested URL returned error: 404
  [ERROR] Failed to download xbctl from .../releases/download/<tag>/xbctl-linux-amd64

install.sh 除了 way-node 还要下 xbctl(配套 CLI),而 Dockerfile 只编了
way-node、release 也只挂了 way-node 资产。

- Dockerfile: builder 阶段同时 go build cmd/xbctl,运行时 COPY 进 /usr/local/bin
- workflow: extract 步骤从镜像里把 xbctl 也 cp 出来
- workflow: release 上传改成循环,way-node 与 xbctl 各挂一个资产
2026-11-27 12:10:33 +08:00

135 lines
5.7 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: Build way-node
# 只保留 .gitea/workflows 这一份;.github/workflows/ci.yml 依赖 ghcr.io 与
# GITHUB_TOKEN,在 Gitea 上跑不通,已重命名为 .disabled。
#
# 关键约束(第一次构建的失败教训):
# act_runner 的 job 容器里 $PWD 是容器内路径,而 docker.sock 连的是宿主 docker,
# 所以 `docker run -v "$PWD":/src` 挂进去是空目录,报
# "pattern ./internal/...: directory prefix internal does not contain main module"
# 编译因此不在 workflow 里做,交给 Dockerfile 的多阶段构建;二进制从镜像里 cp 出来。
on:
push:
branches:
- master
- dev
tags:
- 'v*'
paths-ignore:
- '**.md'
- 'docs-*.md'
workflow_dispatch:
env:
REGISTRY: git.viaeon.com
IMAGE: git.viaeon.com/admin/way-node
jobs:
build:
name: Build and Push
runs-on: ubuntu
steps:
- name: Install Docker CLI and curl
run: |
# docker 通常已存在(挂 docker.sock),所以 curl 要单独保证 —— 上一轮
# 就是因为整段 if 被跳过、curl 缺失,release 上传那步静默失败
if ! command -v docker >/dev/null 2>&1; then
if command -v apk >/dev/null 2>&1; then
apk add --no-cache docker-cli git
elif command -v apt-get >/dev/null 2>&1; then
apt-get update && apt-get install -y docker.io git
fi
fi
if ! command -v curl >/dev/null 2>&1; then
if command -v apk >/dev/null 2>&1; then
apk add --no-cache curl
elif command -v apt-get >/dev/null 2>&1; then
apt-get update && apt-get install -y curl
fi
fi
docker --version && curl --version | head -1
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Prepare version
id: ver
run: |
SHORT_SHA=$(git rev-parse --short=7 HEAD)
VERSION=$(date '+%Y%m%d')-${SHORT_SHA}
echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "版本: ${VERSION}"
- name: Login to registry
run: |
echo "${{ secrets.TOKEN }}" | docker login "${{ env.REGISTRY }}" -u "${{ github.actor }}" --password-stdin
- name: Build image
run: |
docker build \
--build-arg VERSION=${{ steps.ver.outputs.version }} \
--label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--label "org.opencontainers.image.version=${{ steps.ver.outputs.version }}" \
-t "${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }}" \
-t "${{ env.IMAGE }}:${{ steps.ver.outputs.version }}" \
-t "${{ env.IMAGE }}:latest" \
.
docker images --format '{{.Repository}}:{{.Tag}} {{.Size}}' | grep way-node | head -3
- name: Push image
run: |
docker push "${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }}"
docker push "${{ env.IMAGE }}:${{ steps.ver.outputs.version }}"
docker push "${{ env.IMAGE }}:latest"
- name: Extract binary from image
run: |
# install.sh 需要独立二进制,直接从刚构建的镜像里取,避免二次编译
CID=$(docker create "${{ env.IMAGE }}:latest")
docker cp "$CID:/usr/local/bin/way-node" way-node-linux-amd64
docker cp "$CID:/usr/local/bin/xbctl" xbctl-linux-amd64
docker rm -f "$CID" >/dev/null
ls -lh way-node-linux-amd64 xbctl-linux-amd64 | awk '{print " " $9, $5}'
- name: Upload binary to release
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master'
run: |
# 用 Gitea API 建/更新 release 并挂资产,供 install.sh 下载
TAG="${{ steps.ver.outputs.version }}"
API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}"
AUTH="Authorization: token ${{ secrets.TOKEN }}"
curl -sS -X POST -H "$AUTH" -H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"body\":\"way-node ${TAG}\",\"target_commitish\":\"${{ github.sha }}\"}" \
"${API}/releases" -o /tmp/rel.json || true
# Gitea 的 release JSON 里 "id" 会出现多次(author.id、repo.id…),
# 必须先按逗号拆行,只取顶层那个 "id",否则会拿到 1
# 顶层 "id" 在 Gitea 的 release JSON 里是最先出现的那个(后面 author.id/repo.id 才是 1)
rid_of() { grep -o '"id":[0-9]*' | head -1 | cut -d: -f2; }
RID=$(rid_of < /tmp/rel.json 2>/dev/null)
if [ -z "$RID" ]; then
RID=$(curl -sS -H "$AUTH" "${API}/releases/tags/${TAG}" | rid_of)
fi
echo " 解析到 release id: ${RID}"
if [ -n "$RID" ]; then
for asset in way-node-linux-amd64 xbctl-linux-amd64; do
[ -f "$asset" ] || { echo " ⚠ 缺少 $asset,跳过"; continue; }
curl -sS -X POST -H "$AUTH" -F "attachment=@${asset}" \
"${API}/releases/${RID}/assets?name=${asset}" >/dev/null \
&& echo " ✓ 已上传资产 ${asset}"
done
else
echo " ⚠ release 创建失败,二进制未上传(镜像已推送,docker 部署不受影响)"
fi
- name: Summary
run: |
echo "镜像:"
echo " ${{ env.IMAGE }}:${{ steps.ver.outputs.short_sha }}"
echo " ${{ env.IMAGE }}:${{ steps.ver.outputs.version }}"
echo " ${{ env.IMAGE }}:latest"