Skip to content

Commit f20b9eb

Browse files
Merge pull request #9 from fosrl/dev
CICD, --version & Bug Fixes
2 parents 5b42454 + 39bfe5b commit f20b9eb

File tree

5 files changed

+98
-7
lines changed

5 files changed

+98
-7
lines changed

.github/workflows/cicd.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
release:
10+
name: Build and Release
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
20+
- name: Log in to Docker Hub
21+
uses: docker/login-action@v2
22+
with:
23+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
24+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
25+
26+
- name: Extract tag name
27+
id: get-tag
28+
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
29+
30+
- name: Install Go
31+
uses: actions/setup-go@v4
32+
with:
33+
go-version: 1.23.1
34+
35+
- name: Update version in main.go
36+
run: |
37+
TAG=${{ env.TAG }}
38+
if [ -f main.go ]; then
39+
sed -i 's/Newt version replaceme/Newt version '"$TAG"'/' main.go
40+
echo "Updated main.go with version $TAG"
41+
else
42+
echo "main.go not found"
43+
fi
44+
45+
- name: Build and push Docker images
46+
run: |
47+
TAG=${{ env.TAG }}
48+
make docker-build-release tag=$TAG
49+
50+
- name: Build binaries
51+
run: |
52+
make go-build-release
53+
54+
- name: Upload artifacts from /bin
55+
uses: actions/upload-artifact@v3
56+
with:
57+
name: binaries
58+
path: bin/

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11

22
all: build push
33

4+
docker-build-release:
5+
@if [ -z "$(tag)" ]; then \
6+
echo "Error: tag is required. Usage: make build-all tag=<tag>"; \
7+
exit 1; \
8+
fi
9+
docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/newt:latest -f Dockerfile --push .
10+
docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/newt:$(tag) -f Dockerfile --push .
11+
412
build:
513
docker build -t fosrl/newt:latest .
614

@@ -13,12 +21,12 @@ test:
1321
local:
1422
CGO_ENABLED=0 go build -o newt
1523

16-
release:
24+
go-build-release:
1725
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/newt_linux_arm64
1826
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/newt_linux_amd64
1927
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/newt_darwin_arm64
2028
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o bin/newt_darwin_amd64
21-
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o newt_windows_amd64.bin/exe
29+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/newt_windows_amd64.exe
2230
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -o bin/newt_freebsd_amd64
2331
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -o bin/newt_freebsd_arm64
2432

main.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,21 @@ func main() {
283283
if logLevel == "" {
284284
flag.StringVar(&logLevel, "log-level", "INFO", "Log level (DEBUG, INFO, WARN, ERROR, FATAL)")
285285
}
286+
287+
// do a --version check
288+
version := flag.Bool("version", false, "Print the version")
289+
286290
flag.Parse()
287291

292+
if *version {
293+
fmt.Println("Newt version replaceme")
294+
os.Exit(0)
295+
}
296+
288297
logger.Init()
289298
loggerLevel := parseLogLevel(logLevel)
290299
logger.GetLogger().SetLevel(parseLogLevel(logLevel))
291300

292-
// Validate required fields
293-
if endpoint == "" || id == "" || secret == "" {
294-
logger.Fatal("endpoint, id, and secret are required either via CLI flags or environment variables")
295-
}
296-
297301
// parse the mtu string into an int
298302
mtuInt, err = strconv.Atoi(mtu)
299303
if err != nil {

proxy/manager.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"net"
7+
"strings"
78
"sync"
89
"time"
910

@@ -279,6 +280,22 @@ func (pm *ProxyManager) handleUDPProxy(conn *gonet.UDPConn, targetAddr string) {
279280
if !pm.running {
280281
return
281282
}
283+
284+
// Check for connection closed conditions
285+
if err == io.EOF || strings.Contains(err.Error(), "use of closed network connection") {
286+
logger.Info("UDP connection closed, stopping proxy handler")
287+
288+
// Clean up existing client connections
289+
clientsMutex.Lock()
290+
for _, targetConn := range clientConns {
291+
targetConn.Close()
292+
}
293+
clientConns = nil
294+
clientsMutex.Unlock()
295+
296+
return
297+
}
298+
282299
logger.Error("Error reading UDP packet: %v", err)
283300
continue
284301
}

websocket/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ func (c *Client) establishConnection() error {
305305
go c.readPump()
306306

307307
if c.onConnect != nil {
308+
err := c.saveConfig()
309+
if err != nil {
310+
logger.Error("Failed to save config: %v", err)
311+
}
308312
if err := c.onConnect(); err != nil {
309313
logger.Error("OnConnect callback failed: %v", err)
310314
}

0 commit comments

Comments
 (0)