Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion .github/workflows/deploy-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:
DEPLOY_USER: ec2-user
DEPLOY_PATH: /home/ec2-user/nhp-server
TEMPLATES_SOURCE: docker/nhp-server/templates
GO_VERSION: '1.25'
GO_VERSION: '1.25.6'
GOMODULE: github.com/OpenNHP/opennhp/nhp

jobs:
Expand Down Expand Up @@ -254,6 +254,35 @@ jobs:
ls -la examples/server_plugin/
echo ""

# Create go.work to ensure consistent dependency versions across all modules
echo "📦 Creating go.work for consistent dependency resolution..."
echo "go 1.25.6" > go.work
echo "" >> go.work
echo "use (" >> go.work
echo " ./nhp" >> go.work
echo " ./endpoints" >> go.work
# Add all plugin modules to workspace
for dir in ./examples/server_plugin/*/; do
if [ -f "$dir/go.mod" ]; then
echo " $dir" >> go.work
else
for subdir in "$dir"/*/; do
if [ -f "$subdir/go.mod" ]; then
echo " $subdir" >> go.work
fi
done
fi
done
echo ")" >> go.work
echo "📄 Generated go.work:"
cat go.work
echo ""

# Sync workspace to ensure consistent dependencies
echo "🔄 Running go work sync..."
go work sync
echo ""

# Initialize and build
make init
make serverd acd plugins
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
coverage.html
docker/*/logs/
# Go workspace
go.sum
go.work
go.work.sum

release/
25 changes: 23 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ generate-version-and-build:
init:
@echo "$(COLOUR_BLUE)[OpenNHP] Initializing... $(END_COLOUR)"
git clean -df release
cd nhp && go mod download
cd endpoints && go mod download
@for dir in ./examples/server_plugin/*/; do \
if [ -f "$$dir/go.mod" ]; then \
echo "$(COLOUR_BLUE)[Plugin-$$(basename $$dir)] Running go mod download... $(END_COLOUR)"; \
cd "$$dir" && go mod download && cd - > /dev/null; \
else \
for subdir in "$$dir"/*/; do \
if [ -f "$$subdir/go.mod" ]; then \
echo "$(COLOUR_BLUE)[Plugin-$$(basename $$subdir)] Running go mod download... $(END_COLOUR)"; \
cd "$$subdir" && go mod download && cd - > /dev/null; \
fi \
done \
fi \
done

# Use this target when you need to update dependencies (will modify go.sum)
tidy:
@echo "$(COLOUR_BLUE)[OpenNHP] Running go mod tidy... $(END_COLOUR)"
cd nhp && go mod tidy
cd endpoints && go mod tidy
@for dir in ./examples/server_plugin/*/; do \
Expand All @@ -110,6 +129,7 @@ init:
done \
fi \
done
@echo "$(COLOUR_GREEN)[OpenNHP] go mod tidy complete. Remember to commit go.sum files!$(END_COLOUR)"

agentd:
@echo "$(COLOUR_BLUE)[OpenNHP] Building nhp-agent... $(END_COLOUR)"
Expand Down Expand Up @@ -283,7 +303,8 @@ help:
@echo ""
@echo "$(COLOUR_GREEN)Build:$(END_COLOUR)"
@echo " make - Build all binaries (default)"
@echo " make init - Initialize dependencies"
@echo " make init - Download dependencies (preserves go.sum)"
@echo " make tidy - Update dependencies (modifies go.sum)"
@echo " make agentd - Build nhp-agent"
@echo " make serverd - Build nhp-server"
@echo " make acd - Build nhp-ac"
Expand Down Expand Up @@ -340,4 +361,4 @@ archive:
@cd release && mkdir -p archive && tar -czvf ./archive/$(PACKAGE_FILE) nhp-agent nhp-ac nhp-db nhp-server
@echo "$(COLOUR_GREEN)[OpenNHP] Package ${PACKAGE_FILE} archived!$(END_COLOUR)"

.PHONY: all generate-version-and-build init agentd acd serverd db linuxagentsdk androidagentsdk macosagentsdk iosagentsdk devicesdk plugins dev test test-race fmt lint clean help fuzz fuzz-quick coverage coverage-html archive ebpf clean_ebpf
.PHONY: all generate-version-and-build init tidy agentd acd serverd db linuxagentsdk androidagentsdk macosagentsdk iosagentsdk devicesdk plugins dev test test-race fmt lint clean help fuzz fuzz-quick coverage coverage-html archive ebpf clean_ebpf
12 changes: 11 additions & 1 deletion docker/Dockerfile.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ COPY . .

RUN echo "Building for architecture: ${TARGETARCH}"

RUN cd /nhp-server && make init acd test
RUN cd /nhp-server && make init acd

FROM ubuntu:22.04 AS runtime

ARG APT_MIRROR=
ENV DEBIAN_FRONTEND=noninteractive

# Switch APT mirror if specified
RUN if [ -n "$APT_MIRROR" ]; then \
sed -i "s|ports.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list && \
sed -i "s|archive.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list && \
sed -i "s|security.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list; \
fi

RUN apt-get update && \
apt-get install -y wget \
ca-certificates \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.agent
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY . .

RUN echo "Building for architecture: ${TARGETARCH}"

RUN cd /workdir && cat Makefile && make init agentd test
RUN cd /workdir && cat Makefile && make init agentd

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
Expand Down
18 changes: 18 additions & 0 deletions docker/Dockerfile.app
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ FROM --platform=$BUILDPLATFORM ubuntu:22.04 AS builder
# Get target platform architecture
ARG TARGETARCH
ARG TARGETOS
ARG APT_MIRROR=

# Switch APT mirror if specified
RUN if [ -n "$APT_MIRROR" ]; then \
sed -i "s|ports.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list && \
sed -i "s|archive.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list && \
sed -i "s|security.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list; \
fi

# Install basic tools
RUN apt-get update && \
Expand Down Expand Up @@ -62,6 +70,16 @@ RUN CGO_ENABLED=0 GOOS=linux go mod tidy && go build -o app

# Stage 2: Create a minimal runtime image
FROM ubuntu:22.04

ARG APT_MIRROR=

# Switch APT mirror if specified
RUN if [ -n "$APT_MIRROR" ]; then \
sed -i "s|ports.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list && \
sed -i "s|archive.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list && \
sed -i "s|security.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list; \
fi

RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
Expand Down
12 changes: 11 additions & 1 deletion docker/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ FROM --platform=$BUILDPLATFORM ubuntu:22.04 AS builder
ARG TARGETARCH
ARG TARGETOS
ARG GOPROXY=https://proxy.golang.org,direct
ARG GO_VERSION=1.21.2
ARG GO_VERSION=1.25.6
ARG APT_MIRROR=

# Set Proxy
ENV GOPROXY=${GOPROXY}

# Switch APT mirror if specified (for users in China, use mirrors.aliyun.com)
RUN if [ -n "$APT_MIRROR" ]; then \
sed -i "s|ports.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list && \
sed -i "s|archive.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list && \
sed -i "s|security.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list; \
fi

# Install basic tools
RUN apt-get update && \
apt-get install -y --no-install-recommends \
Expand Down Expand Up @@ -52,6 +60,8 @@ ENV PATH="${GOPATH}/bin:${PATH}"
ENV GOOS=${TARGETOS}
ENV GOARCH=${TARGETARCH}
ENV CGO_ENABLED=1
# Force all builds to use go1.25.6 to ensure plugin compatibility
ENV GOTOOLCHAIN=go1.25.6

# Verify installations
RUN go version && \
Expand Down
11 changes: 10 additions & 1 deletion docker/Dockerfile.server
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ COPY . .

RUN echo "Building for architecture: ${TARGETARCH}"

RUN cd /nhp-server && make init serverd plugins test
RUN cd /nhp-server && make init serverd plugins

FROM ubuntu:22.04 AS runtime

ARG APT_MIRROR=
ENV DEBIAN_FRONTEND=noninteractive

# Switch APT mirror if specified
RUN if [ -n "$APT_MIRROR" ]; then \
sed -i "s|ports.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list && \
sed -i "s|archive.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list && \
sed -i "s|security.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list; \
fi

RUN apt-get update && \
apt-get install -y wget \
ca-certificates \
Expand Down
4 changes: 4 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
dockerfile: ./docker/Dockerfile.server
args:
- GOPROXY=${GOPROXY:-}
- APT_MIRROR=${APT_MIRROR:-}
container_name: nhp-server
restart: always
networks:
Expand All @@ -35,6 +36,7 @@ services:
dockerfile: ./docker/Dockerfile.ac
args:
- GOPROXY=${GOPROXY:-}
- APT_MIRROR=${APT_MIRROR:-}
volumes:
- ./nhp-ac/etc/:/nhp-ac/etc/
- ./nhp-ac/traefik/etc/traefik.toml:/opt/traefik/traefik.toml
Expand All @@ -57,6 +59,7 @@ services:
dockerfile: ./Dockerfile.app
args:
- GOPROXY=${GOPROXY:-}
- APT_MIRROR=${APT_MIRROR:-}
restart: always
cap_add:
- NET_ADMIN
Expand All @@ -71,6 +74,7 @@ services:
dockerfile: ./docker/Dockerfile.agent
args:
- GOPROXY=${GOPROXY:-}
- APT_MIRROR=${APT_MIRROR:-}
container_name: nhp-agent
restart: always
#command: []
Expand Down
Loading
Loading