由于哪吒探针官方没有提供哪吒面板FreeBSD版本,所以其实之前码的 serv00和ct8主机一键安装哪吒探针V1版本 里面的dashboard V0和V1安装包,都是来自另外一个github项目定时构建的:https://github.com/vfhky/nezha-build。
由于go build时需要开启CGO并且因为使用了go-sqlite3导致无法在Ubuntu 环境进行交叉编译,经过一系列折腾后,最终选用在workflow中使用 vmactions/freebsd-vm 虚拟机的方式来构建的FreeBSD amd64的安装包。
如果有其它项目需要下载哪吒面板FreeBSD版本的,可以通过上面的nezha-build下载,目前是设置了每天8点、16点、24点同步拉取官方最新代码进行构建。
如果有遇到无法使用goreleaser/goreleaser-action构建其它FreeBSD项目的,也可以参考上面的nezha-build源码,使用vmactions/freebsd-vm的方式构建。
如果当前也遇到了go项目交叉编译的问题,也可以看看nezha-build的折腾过程看看是否有思路:https://typecodes.com/linux/githubworkflownezhafreebsdserv00.html
最后附上构建的源码:
name: Build and Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to release'
required: true
default: 'v1.4.2'
jobs:
release:
name: build and release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup and Build on FreeBSD
uses: vmactions/freebsd-vm@v1
with:
usesh: true
release: 14.1
prepare: |
pkg install -y wget curl git go121 gcc bash jq node zip
ln -s /usr/local/bin/go121 /usr/local/bin/go
curl -sL https://github.com/mikefarah/yq/releases/latest/download/yq_freebsd_amd64 -o /usr/local/bin/yq
chmod +x /usr/local/bin/yq
yq --version
run: |
# Set version
echo "==================== 1 get nezha version ========================"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION=${{ github.event.inputs.tag }}
else
VERSION=$(curl -sL "https://api.github.com/repos/naiba/nezha/releases/latest" | jq -r .tag_name)
fi
if [ -z "${VERSION}" ]; then
echo "Error: VERSION could not be determined" >&2
exit 1
fi
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "Version set to: ${VERSION}"
# Build the project
version_num=${VERSION#v}
echo "==================== 2 download nezha git ========================"
if git ls-remote --tags https://github.com/naiba/nezha | grep -q "refs/tags/${VERSION}"; then
git clone -b ${VERSION} https://github.com/naiba/nezha
else
echo "Error: Tag ${VERSION} not found in naiba/nezha repository" && exit 1
fi
# Clean old dist directories
rm -rf nezha/cmd/dashboard/*-dist
# Download all frontend dependencies
echo "==================== 3 fetch front module ========================"
cd nezha
chmod +x ./script/fetch-frontends.sh && bash ./script/fetch-frontends.sh
cd ../
# Download GeoIP database
rm -rf nezha/pkg/geoip/geoip.db
wget -qO nezha/pkg/geoip/geoip.db https://ipinfo.io/data/free/country.mmdb?token=${{ secrets.IPINFO_TOKEN }}
echo "==================== 4 Install Swag for Swagger docs ========================"
# Install Swag for Swagger docs
go install github.com/swaggo/swag/cmd/swag@latest
# Ensure Swag is in PATH
export PATH=$PATH:$(go env GOPATH)/bin
echo "==================== 5 Swag init ========================"
# Generate Swagger docs
cd nezha
$(go env GOPATH)/bin/swag init --pd -d . -g ./cmd/dashboard/main.go -o ./cmd/dashboard/docs --parseGoList=false
# Build the project
cd cmd/dashboard
echo "==================== 6 go build ========================"
go mod tidy
go build -ldflags "-s -w -X github.com/nezhahq/nezha/service/singleton.Version=${version_num} -extldflags '-static -fpic'" -trimpath -buildvcs=false
echo "==================== 7 check output file ========================"
file dashboard
echo "==================== 8 output archive ========================"
# Create output directory
mkdir -p ../../output
mv dashboard ../../output/nezha-dashboard
# Prepare config.yaml
mkdir -p ../../output/data
#cp -rf ../../script/config.yaml ../../output/data/config.yaml
wget -qO ../../output/data/config.yaml "https://raw.githubusercontent.com/nezhahq/scripts/main/extras/config.yaml"
# Compress dist files
cd ../../output
zip -qr nezha-dashboard.zip .
mv nezha-dashboard.zip ..
tar -czf nezha-dashboard.tar.gz *
mv ../nezha-dashboard.zip .
echo "==================== 9 check output again ========================"
file nezha-dashboard
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: nezha-freebsd
path: |
nezha/output/*
- name: Release
uses: ncipollo/release-action@v1
with:
tag: ${{ env.VERSION }}
artifacts: "nezha/output/*.zip,nezha/output/*.tar.gz"
generateReleaseNotes: true
makeLatest: legacy
omitBody: false
omitBodyDuringUpdate: false
omitDraftDuringUpdate: false
omitName: false
omitNameDuringUpdate: false
omitPrereleaseDuringUpdate: false
removeArtifacts: false
replacesArtifacts: true
skipIfReleaseExists: false
updateOnlyUnreleased: false
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}