Skip to content

Commit 55ffdc9

Browse files
committed
feat: wireguard implementation
1 parent dcbcaee commit 55ffdc9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+5634
-180
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ API_KEY = xxxxxxxx-yyyy-zzzz-mmmm-aaaaaaaaaaa
2020
# GENERATED_CONFIG_PATH = /var/lib/pg-node/generated
2121
# LOG_BUFFER_SIZE = 10000
2222
# STARTUP_LOG_TAIL_SIZE = 200
23+
# STATS_UPDATE_INTERVAL_SECONDS = 10
24+
# STATS_CLEANUP_INTERVAL_SECONDS = 300

.github/workflows/docker-build-dev.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ jobs:
1919
- name: Checkout repository
2020
uses: actions/checkout@v4
2121

22-
- name: Login to Docker Hub
23-
uses: docker/login-action@v2
24-
with:
25-
username: ${{ secrets.DOCKERHUB_USERNAME }}
26-
password: ${{ secrets.DOCKERHUB_TOKEN }}
27-
2822
- name: Log in to the Container registry
2923
uses: docker/login-action@v3
3024
with:
3125
registry: ghcr.io
3226
username: ${{ github.actor }}
3327
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Login to Docker Hub
30+
uses: docker/login-action@v2
31+
with:
32+
username: ${{ secrets.DOCKERHUB_USERNAME }}
33+
password: ${{ secrets.DOCKERHUB_TOKEN }}
3434

3535
- name: Set up Docker Buildx
3636
uses: docker/setup-buildx-action@v3
@@ -43,7 +43,7 @@ jobs:
4343
platforms: linux/amd64,linux/arm64
4444
push: true
4545
tags: |
46-
${{env.IMAGE}}
4746
${{env.GHCR_IMAGE}}
47+
${{env.IMAGE}}
4848
cache-from: type=gha
4949
cache-to: type=gha,mode=max

.github/workflows/docker-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ jobs:
6363
push: true
6464
tags: ${{ env.DOCKER_TAGS }}
6565
labels: ${{ steps.meta.outputs.labels }}
66-
cache-from: type=gha
66+
cache-from: type=gha

.github/workflows/run-tests.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ name: Test Modules
33
on:
44
pull_request:
55
branches:
6-
- '*'
6+
- "**"
77
push:
88
branches:
9-
- 'dev'
9+
- "dev"
10+
- "wg"
1011

1112
jobs:
1213
test:
1314
runs-on: ubuntu-latest
15+
env:
16+
GOTOOLCHAIN: auto
1417

1518
steps:
1619
- name: Checkout codebase
@@ -19,7 +22,7 @@ jobs:
1922
- name: Set up Go
2023
uses: actions/setup-go@v6
2124
with:
22-
go-version: '1.25.7'
25+
go-version: "1.25.7"
2326
check-latest: true
2427

2528
- name: Get project dependencies
@@ -28,11 +31,17 @@ jobs:
2831
- name: Install xray-core
2932
run: make install_xray
3033

34+
- name: install wg
35+
run: make install_wg
36+
3137
- name: Create certificate
3238
run: |
33-
mkdir certs
39+
mkdir -p certs
3440
make generate_server_cert
3541
make generate_client_cert
3642
37-
- name: Run tests
38-
run: make test
43+
- name: Run regular test suite
44+
run: TEST_INTEGRATION=true go test ./... -v -p 1
45+
46+
- name: Run wireguard integration tests
47+
run: sudo -E make test-integration-wireguard

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ xray-core/
2727
*.env
2828
*.temp
2929

30+
# AI
3031
.AI

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ FROM alpine:latest
1818

1919
LABEL org.opencontainers.image.source="https://github.com/PasarGuard/node"
2020

21+
RUN apk update && apk add --no-cache wireguard-tools
22+
2123
WORKDIR /app
2224
COPY --from=builder /src /app
2325
COPY --from=builder /usr/local/bin/xray /usr/local/bin/xray

Dockerfile.wireguard

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM --platform=$BUILDPLATFORM golang:1.25.7-alpine AS builder
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
RUN apk update && apk add --no-cache make
7+
8+
WORKDIR /src
9+
10+
COPY go* .
11+
RUN go mod download
12+
13+
COPY . .
14+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} make NAME=main build
15+
16+
FROM alpine:latest
17+
18+
LABEL org.opencontainers.image.source="https://github.com/PasarGuard/node"
19+
20+
RUN apk update && apk add --no-cache wireguard-tools
21+
22+
WORKDIR /app
23+
COPY --from=builder /src /app
24+
25+
ENTRYPOINT ["./main"]

Dockerfile.xray

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM --platform=$BUILDPLATFORM golang:1.25.7-alpine AS builder
2+
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
RUN apk update && apk add --no-cache make
7+
8+
WORKDIR /src
9+
10+
COPY go* .
11+
RUN go mod download
12+
13+
COPY . .
14+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} make NAME=main build
15+
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make install_xray
16+
17+
FROM alpine:latest
18+
19+
LABEL org.opencontainers.image.source="https://github.com/PasarGuard/node"
20+
21+
WORKDIR /app
22+
COPY --from=builder /src /app
23+
COPY --from=builder /usr/local/bin/xray /usr/local/bin/xray
24+
COPY --from=builder /usr/local/share/xray /usr/local/share/xray
25+
26+
ENTRYPOINT ["./main"]

Makefile

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ifeq ($(shell echo "$(GOARCH)" | grep -Eq "(mips|mipsle)" && echo true),true)
3838
ADDITION = GOMIPS=softfloat go build -o $(NAME)_softfloat -trimpath -ldflags "$(LDFLAGS)" -v $(MAIN)
3939
endif
4040

41-
.PHONY: clean build
41+
.PHONY: clean build test test-race-wireguard test-integration test-integration-full test-integration-wireguard
4242

4343
build:
4444
CGO_ENABLED=0 go build -o $(OUTPUT) $(PARAMS) $(MAIN)
@@ -129,11 +129,47 @@ else
129129
@exit 1
130130
endif
131131

132+
install_wg: update_os
133+
ifeq ($(UNAME_S),Linux)
134+
@echo "Installing WireGuard for $(DISTRO)..."
135+
if [ "$(DISTRO)" = "debian" ] || [ "$(DISTRO)" = "ubuntu" ]; then \
136+
sudo apt-get update && sudo apt-get install -y wireguard wireguard-tools; \
137+
elif [ "$(DISTRO)" = "centos" ] || [ "$(DISTRO)" = "rhel" ]; then \
138+
sudo yum install -y epel-release && sudo yum install -y wireguard-tools; \
139+
elif [ "$(DISTRO)" = "fedora" ]; then \
140+
sudo dnf install -y wireguard-tools; \
141+
elif [ "$(DISTRO)" = "arch" ] || [ "$(DISTRO)" = "manjaro" ]; then \
142+
sudo pacman -Sy --noconfirm wireguard-tools; \
143+
elif [ "$(DISTRO)" = "alpine" ]; then \
144+
apk add --no-cache wireguard-tools; \
145+
elif [ "$(DISTRO)" = "opensuse" ] || [ "$(DISTRO)" = "opensuse-leap" ] || [ "$(DISTRO)" = "opensuse-tumbleweed" ]; then \
146+
sudo zypper install -y wireguard-tools; \
147+
else \
148+
echo "Unsupported distribution: $(DISTRO)"; \
149+
exit 1; \
150+
fi
151+
@echo "WireGuard installed successfully"
152+
@wg --version
153+
else
154+
@echo "Unsupported operating system: $(UNAME_S)"
155+
@exit 1
156+
endif
157+
132158
test-integration:
133-
TEST_INTEGRATION=true go test ./... -v -p 1
159+
$(MAKE) test-integration-full
160+
161+
test-integration-full:
162+
GOTOOLCHAIN=auto TEST_INTEGRATION=true go test ./... -v -p 1
163+
GOTOOLCHAIN=auto go test -tags=integration -v -p 1 ./backend/wireguard
164+
165+
test-integration-wireguard:
166+
GOTOOLCHAIN=auto go test -tags=integration -v -p 1 ./backend/wireguard
134167

135168
test:
136-
TEST_INTEGRATION=false go test ./... -v -p 1
169+
GOTOOLCHAIN=auto TEST_INTEGRATION=false go test ./... -v -p 1
170+
171+
test-race-wireguard:
172+
GOTOOLCHAIN=auto CGO_ENABLED=1 go test -race -v -p 1 ./backend/wireguard
137173

138174
serve:
139175
go run main.go serve

backend/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
type Backend interface {
1010
Started() bool
1111
Version() string
12-
Logs() chan string
12+
Logs() <-chan string
1313
Restart() error
1414
Shutdown()
1515
SyncUser(context.Context, *common.User) error

0 commit comments

Comments
 (0)