Skip to content

Commit eabc166

Browse files
authored
Merge pull request #116 from fifthsegment/copilot/optimize-gatesentry-performance
Optimize Gatesentry for low-spec hardware through buffer pooling and memory reduction
2 parents 0433c89 + 3209c1b commit eabc166

27 files changed

+2267
-459
lines changed

.github/workflows/pr-build.yml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
name: Build PR Binaries
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
branches:
7+
- master
8+
- main
9+
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Check out code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v4
24+
with:
25+
go-version: '1.24'
26+
27+
- name: Set up Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '18'
31+
32+
- name: Build frontend
33+
run: |
34+
cd ui
35+
npm install
36+
npm run build
37+
cd ..
38+
rm -rf application/webserver/frontend/files/*
39+
mv ui/dist/* application/webserver/frontend/files/
40+
mv application/webserver/frontend/files/fs/* application/webserver/frontend/files/
41+
42+
- name: Get dependencies
43+
run: go get -v
44+
45+
- name: Build binaries for multiple platforms
46+
run: |
47+
mkdir -p pr-binaries
48+
echo "Building Linux amd64..."
49+
env GOOS=linux GOARCH=amd64 go build -o pr-binaries/gatesentry-linux-amd64
50+
echo "Building Linux arm64..."
51+
env GOOS=linux GOARCH=arm64 go build -o pr-binaries/gatesentry-linux-arm64
52+
echo "Building macOS amd64..."
53+
env GOOS=darwin GOARCH=amd64 go build -o pr-binaries/gatesentry-macos-amd64
54+
echo "Building macOS arm64 (Apple Silicon)..."
55+
env GOOS=darwin GOARCH=arm64 go build -o pr-binaries/gatesentry-macos-arm64
56+
echo "Building Windows amd64..."
57+
env GOOS=windows GOARCH=amd64 go build -o pr-binaries/gatesentry-windows-amd64.exe
58+
59+
# Make binaries executable
60+
chmod +x pr-binaries/gatesentry-*
61+
62+
# Get file sizes
63+
ls -lh pr-binaries/
64+
65+
- name: Upload binaries as artifacts
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: gatesentry-pr-${{ github.event.pull_request.number }}
69+
path: pr-binaries/*
70+
retention-days: 30
71+
72+
- name: Generate download links and comment
73+
uses: actions/github-script@v7
74+
with:
75+
script: |
76+
const fs = require('fs');
77+
const path = require('path');
78+
79+
// Get file sizes
80+
const binariesDir = 'pr-binaries';
81+
const files = fs.readdirSync(binariesDir);
82+
83+
let fileList = '';
84+
files.forEach(file => {
85+
const stats = fs.statSync(path.join(binariesDir, file));
86+
const sizeMB = (stats.size / (1024 * 1024)).toFixed(2);
87+
fileList += `- \`${file}\` (${sizeMB} MB)\n`;
88+
});
89+
90+
const runId = context.runId;
91+
const repo = context.repo;
92+
const prNumber = context.payload.pull_request.number;
93+
const sha = context.payload.pull_request.head.sha.substring(0, 7);
94+
95+
// Create comment body
96+
const commentBody = `## 🚀 PR Build Artifacts
97+
98+
Test binaries have been built for this PR (commit ${sha}).
99+
100+
### Available Binaries:
101+
${fileList}
102+
103+
### Download Instructions:
104+
105+
1. **Via GitHub Actions UI:**
106+
- Go to the [Actions tab](https://github.com/${repo.owner}/${repo.repo}/actions/runs/${runId})
107+
- Scroll down to "Artifacts" section
108+
- Download \`gatesentry-pr-${prNumber}\`
109+
110+
2. **Via GitHub CLI:**
111+
\`\`\`bash
112+
gh run download ${runId} -n gatesentry-pr-${prNumber} -R ${repo.owner}/${repo.repo}
113+
\`\`\`
114+
115+
### Quick Test (Linux/macOS):
116+
\`\`\`bash
117+
# Extract and make executable
118+
chmod +x gatesentry-*
119+
120+
# Test with low memory settings (good for routers)
121+
export GS_MAX_SCAN_SIZE_MB=3
122+
export GS_DEBUG_LOGGING=false
123+
./gatesentry-linux-amd64
124+
125+
# Or test with custom settings
126+
export GS_MAX_SCAN_SIZE_MB=10
127+
./gatesentry-linux-amd64
128+
\`\`\`
129+
130+
### Quick Test (Windows):
131+
\`\`\`powershell
132+
# Set environment variables
133+
$env:GS_MAX_SCAN_SIZE_MB=10
134+
$env:GS_DEBUG_LOGGING="false"
135+
.\\gatesentry-windows-amd64.exe
136+
\`\`\`
137+
138+
### Configuration Options:
139+
- \`GS_MAX_SCAN_SIZE_MB\`: Set max content scan size (1-1000 MB, default: 10)
140+
- \`GS_DEBUG_LOGGING\`: Enable verbose logging (true/false, default: false)
141+
142+
See [ROUTER_OPTIMIZATION.md](https://github.com/${repo.owner}/${repo.repo}/blob/${context.payload.pull_request.head.ref}/ROUTER_OPTIMIZATION.md) for detailed configuration guide.
143+
144+
---
145+
146+
📝 *Binaries are kept for 30 days and automatically deleted afterwards.*`;
147+
148+
// Find existing comment
149+
const { data: comments } = await github.rest.issues.listComments({
150+
owner: repo.owner,
151+
repo: repo.repo,
152+
issue_number: prNumber
153+
});
154+
155+
const botComment = comments.find(comment =>
156+
comment.user.login === 'github-actions[bot]' &&
157+
comment.body.includes('PR Build Artifacts')
158+
);
159+
160+
// Update or create comment
161+
if (botComment) {
162+
await github.rest.issues.updateComment({
163+
owner: repo.owner,
164+
repo: repo.repo,
165+
comment_id: botComment.id,
166+
body: commentBody
167+
});
168+
console.log('Updated existing comment');
169+
} else {
170+
await github.rest.issues.createComment({
171+
owner: repo.owner,
172+
repo: repo.repo,
173+
issue_number: prNumber,
174+
body: commentBody
175+
});
176+
console.log('Created new comment');
177+
}
178+
179+
- name: Build summary
180+
run: |
181+
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
182+
echo "" >> $GITHUB_STEP_SUMMARY
183+
echo "✅ Successfully built binaries for PR #${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY
184+
echo "" >> $GITHUB_STEP_SUMMARY
185+
echo "### Binaries:" >> $GITHUB_STEP_SUMMARY
186+
echo "" >> $GITHUB_STEP_SUMMARY
187+
ls -lh pr-binaries/ | tail -n +2 | awk '{print "- " $9 " (" $5 ")"}' >> $GITHUB_STEP_SUMMARY
188+
echo "" >> $GITHUB_STEP_SUMMARY
189+
echo "Artifacts are available for download from the Actions tab." >> $GITHUB_STEP_SUMMARY

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ jobs:
2020
- name: Set up Go 1.x
2121
uses: actions/setup-go@v2
2222
with:
23-
go-version: ^1.17 # Replace with your Go version if different
23+
go-version: ^1.17
24+
25+
#- name: Run Tests with Coverage
26+
# run: go test ./... -coverprofile=coverage.txt -covermode=atomic
2427

2528
- name: Run Tests with Coverage
26-
run: go test ./... -coverprofile=coverage.txt -covermode=atomic
29+
run: make test
2730

2831
- name: Upload coverage to Codecov
2932
uses: codecov/codecov-action@v2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
bin
22
log.txt
33
docker_root
4+
test-binaries
5+
pr-binaries

Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.PHONY: test build run clean-test
2+
3+
clean-test:
4+
@echo "Cleaning up test artifacts..."
5+
@-kill `cat /tmp/gatesentry.pid 2>/dev/null` 2>/dev/null || true
6+
@-rm -f /tmp/gatesentry.pid /tmp/gatesentry.log
7+
@-rm -rf /tmp/gatesentry
8+
9+
build: clean-test
10+
go build -o /tmp/gatesentry-bin .
11+
12+
run: build
13+
cd /tmp && ./gatesentry-bin
14+
15+
# Run integration tests with server
16+
test: clean-test build
17+
@echo "Starting Gatesentry server in background..."
18+
@cd /tmp && ./gatesentry-bin > /dev/null 2>&1 & echo $$! > /tmp/gatesentry.pid
19+
@echo "Waiting for server to be ready..."
20+
@for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do \
21+
if curl -s http://localhost:10786/api/health > /dev/null 2>&1 || curl -s http://localhost:10786 > /dev/null 2>&1; then \
22+
echo "Server is ready!"; \
23+
break; \
24+
fi; \
25+
if [ $$i -eq 15 ]; then \
26+
echo "Server failed to start. Logs:"; \
27+
cat /tmp/gatesentry.log; \
28+
kill `cat /tmp/gatesentry.pid` 2>/dev/null || true; \
29+
rm -f /tmp/gatesentry.pid; \
30+
exit 1; \
31+
fi; \
32+
echo "Waiting... ($$i/15)"; \
33+
sleep 2; \
34+
done
35+
@echo "Running tests..."
36+
@GODEBUG=gotestcache=off go test -v -timeout 5m ./tests/... -coverprofile=coverage.txt -covermode=atomic || (kill `cat /tmp/gatesentry.pid` 2>/dev/null; rm -f /tmp/gatesentry.pid; exit 1)
37+
@echo "Stopping server..."
38+
@kill `cat /tmp/gatesentry.pid` 2>/dev/null || true
39+
@rm -f /tmp/gatesentry.pid

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ An open source proxy server (supports SSL filtering / MITM) + DNS Server with a
55
![Codecov](https://codecov.io/gh/fifthsegment/Gatesentry/branch/master/graph/badge.svg)
66

77

8-
[Download the latest releast](https://github.com/fifthsegment/Gatesentry/releases)
8+
[Download the latest release](https://github.com/fifthsegment/Gatesentry/releases)
99

1010
Usages:
1111

0 commit comments

Comments
 (0)