From 33a72cbad26d9710c0f8f3baf0880a1e87c9308a Mon Sep 17 00:00:00 2001 From: Baolin Zhu Date: Wed, 8 Apr 2026 14:11:57 +0800 Subject: [PATCH] feat: replace build scripts with Makefile Consolidate build.sh and build-deb.sh into a single Makefile with multi-arch support. Targets include linux-amd64, linux-arm64 (binary builds), deb-amd64, deb-arm64 (.deb packages), ui (frontend), and clean. fpm metadata and file mappings are centralized in .fpm. Co-Authored-By: Claude Opus 4.6 --- .fpm | 11 +++++++++++ .gitignore | 5 ++++- Dockerfile | 2 +- Makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ build.sh | 15 --------------- netgate.service | 20 +++++++++++--------- 6 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 .fpm create mode 100644 Makefile delete mode 100755 build.sh diff --git a/.fpm b/.fpm new file mode 100644 index 0000000..3edfe36 --- /dev/null +++ b/.fpm @@ -0,0 +1,11 @@ +-s dir +--name netgate +--category net +--license MIT +--description "An inbound network gateway with authentication, proxy, and management UI." +--url "https://github.com/mrhaoxx/OpenNG" +--maintainer "mrhaoxx " +--config-files /etc/netgate/config.yaml +doc/config-sample.yaml=/etc/netgate/config.yaml +netgate.service=/usr/lib/systemd/system/netgate.service +netgate=/usr/bin/netgate diff --git a/.gitignore b/.gitignore index 938c38c..7d13319 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,7 @@ new.config.yaml **dist** node_modules -.claude \ No newline at end of file +.claude +/netgate +*.deb +DEBIAN/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a5fbfb2..9e7e2c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN apt-get update && apt-get install -y build-essential git COPY . /go/src/github.com/mrhaoxx/OpenNG COPY --from=web /workdir/dist /go/src/github.com/mrhaoxx/OpenNG/ui/html/dist -RUN cd /go/src/github.com/mrhaoxx/OpenNG && ./build.sh -o /NetGATE +RUN cd /go/src/github.com/mrhaoxx/OpenNG && make NAME=/NetGATE FROM debian:bookworm AS runtime diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..58756c4 --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +NAME=netgate +BUILDTIME=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') +VERSION ?= $(shell v="$$(git describe --tags --abbrev=7 --dirty 2>/dev/null)"; \ + echo "$${v:-0.0.0}" | sed 's/^v//; s/-/./g') + +GOBUILD=go build -a \ + -ldflags "-w -s \ + -X 'main.buildstamp=$(BUILDTIME)' \ + -X 'main.gitver=$(VERSION)'" + +HOST_ARCH=$(shell uname -m) +ifeq ($(HOST_ARCH),x86_64) + HOST_GOARCH=amd64 +else ifeq ($(HOST_ARCH),aarch64) + HOST_GOARCH=arm64 +else + HOST_GOARCH=$(HOST_ARCH) +endif + +ui: + (cd ui/html && npm install && npm run build) + +linux-amd64: + GOOS=linux GOARCH=amd64 GOAMD64=v2 $(GOBUILD) -o $(NAME) + +linux-arm64: + GOOS=linux GOARCH=arm64 $(GOBUILD) -o $(NAME) + +all: linux-$(HOST_GOARCH) + +deb: deb-$(HOST_GOARCH) + +deb-amd64: linux-amd64 ui + fpm -t deb -v "$(VERSION)" -p "$(NAME)_$(VERSION)_amd64.deb" --architecture amd64 -f + +deb-arm64: linux-arm64 ui + fpm -t deb -v "$(VERSION)" -p "$(NAME)_$(VERSION)_arm64.deb" --architecture arm64 -f + +clean: + rm -f $(NAME) *.deb + +.PHONY: all ui linux-amd64 linux-arm64 deb deb-amd64 deb-arm64 clean diff --git a/build.sh b/build.sh deleted file mode 100755 index cdf6c73..0000000 --- a/build.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -BUILD_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ') - -GIT_VERSION=$(git describe --tags --abbrev=7 --dirty 2>/dev/null || echo "unknown") - -# if arch is amd64 set GOAMD64=v2 -if [ "$(uname -m)" == "x86_64" ]; then - export GOAMD64=v2 -fi - -go build -a -ldflags="-w -s \ - -X 'main.buildstamp=$BUILD_TIME' \ - -X 'main.gitver=$GIT_VERSION'" \ - "$@" diff --git a/netgate.service b/netgate.service index e3c1b45..a49175e 100644 --- a/netgate.service +++ b/netgate.service @@ -1,14 +1,16 @@ [Unit] - -[Install] -WantedBy=multi-user.target +Description=Netgate - Inbound Network Gateway +After=network-online.target +Wants=network-online.target [Service] -ExecStart=/home/ubuntu/OpenNG -WorkingDirectory=/home/ubuntu/OpenNG -User=ubuntu +# Runs as root: needs access to TLS certificates owned by root +Type=simple +ExecStart=/usr/bin/netgate -config /etc/netgate/config.yaml +WorkingDirectory=/etc/netgate Restart=always RestartSec=5 -StandardOutput=syslog -StandardError=syslog -SyslogIdentifier=%n +LimitNOFILE=65535 + +[Install] +WantedBy=multi-user.target