mirror of
https://github.com/anand34577/ferrum.git
synced 2026-09-19 09:05:56 +00:00
7d3a1fa134
- .gitignore/.dockerignore: cover Go build artifacts, env files, logs, editor/OS cruft, and local runtime data (sqlite db/secret, config.yaml). - README: add a Screenshots section (captured against a mock Proxmox cluster) and a Deploying a release build section. - LICENSE: MIT. Deployable binaries: - cmd/ferrum: -version flag with build-time version/commit/date via -ldflags; -log-file flag (Windows services don't capture stdout/stderr the way systemd does); native Windows Service Control Manager support (service_windows.go) so ferrum.exe manages its own start/stop lifecycle under a Windows service, same graceful-shutdown path SIGTERM already used on Linux. - packaging/systemd/ferrum.service: hardened systemd unit. - scripts/build.sh, build.ps1: cross-compile linux/windows/darwin x amd64/arm64, package as .tar.gz/.zip with an install script and checksums.txt. - scripts/linux/install.sh, uninstall.sh: create a dedicated system user, install the binary, seed /etc/ferrum/config.yaml, enable + start the systemd service. - scripts/get.sh: one-line curl-pipeable installer (get.docker.com style) that resolves the latest release, verifies its checksum, and hands off to install.sh. - scripts/windows/install-service.ps1, uninstall-service.ps1: register/ remove the self-managing Windows service. - .github/workflows/release.yml: publish all platform archives + checksums as GitHub Release assets on a vX.Y.Z tag push. - .github/workflows/ci.yml: go vet/build/test, frontend lint/test/build, and shell-script syntax checks on push/PR.
76 lines
2.5 KiB
Bash
76 lines
2.5 KiB
Bash
#!/usr/bin/env bash
|
|
# Builds the frontend and cross-compiles the ferrum binary for one or more
|
|
# platforms, then packages each as a .tar.gz (or .zip on Windows) under
|
|
# dist/ alongside a sha256sum manifest. Used locally and by
|
|
# .github/workflows/release.yml — CI just runs this script so a local build
|
|
# always matches what a tagged release publishes.
|
|
#
|
|
# Usage:
|
|
# scripts/build.sh # build for the current GOOS/GOARCH
|
|
# scripts/build.sh linux/amd64 windows/amd64 darwin/arm64
|
|
# scripts/build.sh all # every target below
|
|
set -euo pipefail
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
|
|
|
VERSION="${VERSION:-$(git describe --tags --always --dirty 2>/dev/null || echo dev)}"
|
|
COMMIT="${COMMIT:-$(git rev-parse --short HEAD 2>/dev/null || echo none)}"
|
|
DATE="${DATE:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}"
|
|
LDFLAGS="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}"
|
|
|
|
ALL_TARGETS=(linux/amd64 linux/arm64 windows/amd64 windows/arm64 darwin/amd64 darwin/arm64)
|
|
|
|
targets=("$@")
|
|
if [ ${#targets[@]} -eq 0 ]; then
|
|
targets=("$(go env GOOS)/$(go env GOARCH)")
|
|
elif [ "${targets[0]}" = "all" ]; then
|
|
targets=("${ALL_TARGETS[@]}")
|
|
fi
|
|
|
|
echo "==> Building frontend (web/dist)"
|
|
( cd web && npm ci && npm run build )
|
|
|
|
rm -rf dist
|
|
mkdir -p dist
|
|
|
|
echo "==> Version ${VERSION} (${COMMIT}, ${DATE})"
|
|
|
|
for target in "${targets[@]}"; do
|
|
goos="${target%/*}"
|
|
goarch="${target#*/}"
|
|
ext=""
|
|
[ "$goos" = "windows" ] && ext=".exe"
|
|
|
|
out_dir="dist/ferrum_${VERSION}_${goos}_${goarch}"
|
|
mkdir -p "$out_dir"
|
|
bin="$out_dir/ferrum${ext}"
|
|
|
|
echo "==> Building ${goos}/${goarch}"
|
|
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" go build \
|
|
-trimpath -ldflags "$LDFLAGS" \
|
|
-o "$bin" ./cmd/ferrum
|
|
|
|
cp README.md LICENSE config.example.yaml "$out_dir/"
|
|
if [ "$goos" = "linux" ]; then
|
|
mkdir -p "$out_dir/packaging/systemd"
|
|
cp packaging/systemd/ferrum.service "$out_dir/packaging/systemd/"
|
|
cp scripts/linux/install.sh scripts/linux/uninstall.sh "$out_dir/"
|
|
elif [ "$goos" = "windows" ]; then
|
|
cp scripts/windows/install-service.ps1 scripts/windows/uninstall-service.ps1 "$out_dir/"
|
|
fi
|
|
|
|
( cd dist
|
|
base="ferrum_${VERSION}_${goos}_${goarch}"
|
|
if [ "$goos" = "windows" ]; then
|
|
zip -qr "${base}.zip" "$base"
|
|
else
|
|
tar -czf "${base}.tar.gz" "$base"
|
|
fi
|
|
rm -rf "$base"
|
|
)
|
|
done
|
|
|
|
( cd dist && sha256sum ferrum_* > checksums.txt 2>/dev/null || shasum -a 256 ferrum_* > checksums.txt )
|
|
|
|
echo "==> Done. Artifacts in dist/:"
|
|
ls -la dist
|