Skip to content

Commit

Permalink
Merge branch 'develop' into NET-1778
Browse files Browse the repository at this point in the history
  • Loading branch information
yabinma authored Dec 3, 2024
2 parents 0b1e328 + f610f1c commit dfd9424
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 101 deletions.
165 changes: 165 additions & 0 deletions .github/workflows/patch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
name: Patch Netclient

on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to build from'
required: true
type: string
default: 'develop'
version:
description: 'Version to patch'
required: true
type: string

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.version }}
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64, linux/arm/v7
push: true
tags: |
gravitl/netclient:${{ inputs.version }}
gravitl/netclient:latest
build-and-patch:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ inputs.branch }}

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'

- name: Get Dependencies
run: |
go mod tidy
- name: Setup Build Directory
run: mkdir -p builds

- name: Cross Compile
env:
VERSION: ${{ inputs.version }}
CGO_ENABLED: 0
run: |
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o builds/netclient-darwin-amd64
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o builds/netclient-darwin-arm64
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o builds/netclient-linux-amd64
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o builds/netclient-linux-arm64
GOOS=linux GOARCH=arm GOARM=5 go build -ldflags="-s -w" -o builds/netclient-linux-armv5
GOOS=linux GOARCH=arm GOARM=6 go build -ldflags="-s -w" -o builds/netclient-linux-armv6
GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w" -o builds/netclient-linux-armv7
GOOS=linux GOARCH=mips GOMIPS=hardfloat go build -ldflags="-s -w" -o builds/netclient-linux-mips-hardfloat
GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags="-s -w" -o builds/netclient-linux-mips-softfloat
GOOS=linux GOARCH=mipsle GOMIPS=hardfloat go build -ldflags="-s -w" -o builds/netclient-linux-mipsle-hardfloat
GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags="-s -w" -o builds/netclient-linux-mipsle-softfloat
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o builds/netclient-windows-amd64.exe
- name: Verify Builds
run: |
ls -lh builds/
- name: Update GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
assets_urls=$(curl -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ inputs.version }}" \
| jq -r '.assets[].url')
for url in $assets_urls; do
curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" $url
done
release_id=$(curl -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ inputs.version }}" \
| jq -r '.id')
cd builds
for file in *; do
echo "Uploading $file to GitHub release..."
curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$file" \
"https://uploads.github.com/repos/${{ github.repository }}/releases/$release_id/assets?name=$file"
done
- name: Install SSH Key
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H fileserver.clustercat.com >> ~/.ssh/known_hosts
- name: Upload to File Server
env:
UPLOAD_PATH: /var/www/files/releases/download/${{ inputs.version }}
run: |
ssh [email protected] "mkdir -p $UPLOAD_PATH"
echo "Uploading files to file server..."
cd builds
for file in *; do
echo "Uploading $file..."
scp "$file" "[email protected]:$UPLOAD_PATH/"
done
packages:
needs: [build-and-patch]
runs-on: ubuntu-latest
steps:
- name: setup ssh
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/id_devops
chmod 600 ~/.ssh/id_devops
cat >>~/.ssh/config <<END
Host *.clustercat.com
User root
IdentityFile ~/.ssh/id_devops
StrictHostKeyChecking no
END
env:
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- name: set version
run: |
VERSION=$(echo ${{ inputs.version }} | tr -cd '[:digit:].')
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo ${VERSION}
- name: apt/rpm
run: |
ssh fileserver.clustercat.com "cd packages; ./apt_builder.sh; ./rpm_builder.sh"
env:
LC_VERSION: ${{ env.VERSION }}
LC_REVISION: 0
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ builds:
- linux_mips_softfloat
- linux_mipsle_softfloat
- linux_mipsle_hardfloat
- windows_amd64
- darwin_amd64
- darwin_arm64

archives:
- format: binary
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func checkConfig() {
}
if netclient.ListenPort == 0 {
logger.Log(0, "setting listenport")
port, err := ncutils.GetFreePort(config.DefaultListenPort)
port, err := ncutils.GetFreePort(config.DefaultListenPort, netclient.ListenPort, true)
if err != nil {
logger.Log(0, "error getting free port", err.Error())
} else {
Expand Down
7 changes: 0 additions & 7 deletions config/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,6 @@ func ParseAccessToken(token string) (*models.AccessToken, error) {
return &accesstoken, nil
}

// ModPort - Change Node Port if ListenPort is not free
func ModPort(host *Config) error {
var err error
host.ListenPort, err = ncutils.GetFreePort(host.ListenPort)
return err
}

// FormatBool converts a boolean to a [yes|no] string
func FormatBool(b bool) string {
s := "no"
Expand Down
8 changes: 3 additions & 5 deletions functions/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc {
}

if !config.Netclient().IsStaticPort {
if freeport, err := ncutils.GetFreePort(config.Netclient().ListenPort); err != nil {
if freeport, err := ncutils.GetFreePort(ncutils.NetclientDefaultPort, config.Netclient().ListenPort, false); err != nil {
slog.Warn("no free ports available for use by netclient", "error", err.Error())
} else if freeport != config.Netclient().ListenPort {
slog.Info("port has changed", "old port", config.Netclient().ListenPort, "new port", freeport)
Expand Down Expand Up @@ -276,13 +276,11 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc {
go messageQueue(ctx, wg, server)
wg.Add(1)
go Checkin(ctx, wg)
wg.Add(1)
go networking.StartIfaceDetection(ctx, wg, config.Netclient().ListenPort, 4)
wg.Add(1)
go networking.StartIfaceDetection(ctx, wg, config.Netclient().ListenPort, 6)
networking.InitialiseIfaceDetection(ctx, wg)
if server.IsPro {
wg.Add(1)
go watchPeerConnections(ctx, wg)
networking.InitialiseMetricsThread(ctx, wg)
}
wg.Add(1)
go mqFallback(ctx, wg)
Expand Down
45 changes: 0 additions & 45 deletions functions/localport.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package functions

import (
"net"
"strings"

"github.com/gravitl/netclient/ncutils"
"github.com/gravitl/netclient/stun"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/models"
"golang.zx2c4.com/wireguard/wgctrl"
)

Expand All @@ -26,42 +20,3 @@ func GetLocalListenPort(ifacename string) (int, error) {
}
return device.ListenPort, nil
}

func getInterfaces() (*[]models.Iface, error) {
ifaces, err := net.Interfaces()
if err != nil {
return nil, err
}
var data = []models.Iface{}
var link models.Iface
for _, iface := range ifaces {
iface := iface
if iface.Flags&net.FlagUp == 0 || // interface down
iface.Flags&net.FlagLoopback != 0 || // loopback interface
iface.Flags&net.FlagPointToPoint != 0 || // avoid direct connections
iface.Name == ncutils.GetInterfaceName() || strings.Contains(iface.Name, "netmaker") || // avoid netmaker
ncutils.IsBridgeNetwork(iface.Name) || // avoid bridges
strings.Contains(iface.Name, "docker") {
continue
}
addrs, err := iface.Addrs()
if err != nil {
return nil, err
}
for _, addr := range addrs {
ip, cidr, err := net.ParseCIDR(addr.String())
if err != nil {
continue
}
if ip.IsLoopback() || // no need to send loopbacks
stun.IsPublicIP(ip) { // no need to send public IPs
continue
}
link.Name = iface.Name
link.Address = *cidr
link.Address.IP = ip
data = append(data, link)
}
}
return &data, nil
}
7 changes: 4 additions & 3 deletions functions/mqpublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/gravitl/netclient/daemon"
"github.com/gravitl/netclient/metrics"
"github.com/gravitl/netclient/ncutils"
"github.com/gravitl/netclient/networking"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/models"
"golang.org/x/exp/slog"
Expand Down Expand Up @@ -377,13 +378,13 @@ func UpdateHostSettings(fallback bool) error {
publishMsg = true
}

ip, err := getInterfaces()
ip, err := networking.GetInterfaces()
if err != nil {
logger.Log(0, "failed to retrieve local interfaces during check-in", err.Error())
} else {
if ip != nil {
if len(*ip) != len(config.Netclient().Interfaces) {
config.Netclient().Interfaces = *ip
if len(ip) != len(config.Netclient().Interfaces) {
config.Netclient().Interfaces = ip
publishMsg = true
}
}
Expand Down
5 changes: 3 additions & 2 deletions functions/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/gravitl/netclient/config"
"github.com/gravitl/netclient/daemon"
"github.com/gravitl/netclient/ncutils"
"github.com/gravitl/netclient/networking"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/models"
)
Expand All @@ -29,13 +30,13 @@ func Register(token string) error {
logger.FatalLog("could not read enrollment token")
}
host := config.Netclient()
ip, err := getInterfaces()
ip, err := networking.GetInterfaces()
if err != nil {
logger.Log(0, "failed to retrieve local interfaces", err.Error())
} else {
// just in case getInterfaces() returned nil, nil
if ip != nil {
host.Interfaces = *ip
host.Interfaces = ip
}
}
defaultInterface, err := getDefaultInterface()
Expand Down
5 changes: 3 additions & 2 deletions functions/register_sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/gorilla/websocket"
"github.com/gravitl/netclient/config"
"github.com/gravitl/netclient/networking"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/models"
)
Expand All @@ -35,13 +36,13 @@ func RegisterWithSSO(registerData *RegisterSSO) (err error) {
} // end validation

host := config.Netclient()
ip, err := getInterfaces()
ip, err := networking.GetInterfaces()
if err != nil {
logger.Log(0, "failed to retrieve local interfaces", err.Error())
} else {
// just in case getInterfaces() returned nil, nil
if ip != nil {
host.Interfaces = *ip
host.Interfaces = ip
}
}
defaultInterface, err := getDefaultInterface()
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/eclipse/paho.mqtt.golang v1.4.3
github.com/glendc/go-external-ip v0.1.0
github.com/go-ping/ping v1.1.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/google/nftables v0.2.0
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.3
Expand All @@ -27,11 +27,11 @@ require (
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/vishvananda/netlink v1.3.0
golang.org/x/crypto v0.28.0
golang.org/x/crypto v0.29.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/net v0.30.0
golang.org/x/sys v0.26.0
golang.org/x/term v0.25.0
golang.org/x/net v0.31.0
golang.org/x/sys v0.27.0
golang.org/x/term v0.26.0
golang.zx2c4.com/wireguard v0.0.0-20220920152132-bb719d3a6e2c
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20221104135756-97bc4ad4a1cb
golang.zx2c4.com/wireguard/windows v0.5.3
Expand Down Expand Up @@ -94,8 +94,8 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading

0 comments on commit dfd9424

Please sign in to comment.