Rename wiretrustee-signal to netbird-signal (#313)

* rename wiretrustee-signal to netbird-signal

* Rename Signal repositories and source bin

* Adjust docker-compose with signal volume [skip ci]

Co-authored-by: mlsmaycon <mlsmaycon@gmail.com>
This commit is contained in:
shatoboar 2022-05-13 21:51:41 +02:00 committed by GitHub
parent 7d893c0238
commit 77e58295e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 165 additions and 49 deletions

View File

@ -41,10 +41,10 @@ builds:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser
mod_timestamp: '{{ .CommitTimestamp }}'
- id: wiretrustee-signal
- id: netbird-signal
dir: signal
env: [CGO_ENABLED=0]
binary: wiretrustee-signal
binary: netbird-signal
goos:
- linux
goarch:
@ -183,9 +183,9 @@ dockers:
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=maintainer=wiretrustee@wiretrustee.com"
- image_templates:
- wiretrustee/signal:{{ .Version }}-amd64
- netbirdio/signal:{{ .Version }}-amd64
ids:
- wiretrustee-signal
- netbird-signal
goarch: amd64
use: buildx
dockerfile: signal/Dockerfile
@ -196,11 +196,11 @@ dockers:
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=maintainer=wiretrustee@wiretrustee.com"
- "--label=maintainer=dev@netbird.io"
- image_templates:
- wiretrustee/signal:{{ .Version }}-arm64v8
- netbird/signal:{{ .Version }}-arm64v8
ids:
- wiretrustee-signal
- netbird-signal
goarch: arm64
use: buildx
dockerfile: signal/Dockerfile
@ -211,11 +211,11 @@ dockers:
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=maintainer=wiretrustee@wiretrustee.com"
- "--label=maintainer=dev@netbird.io"
- image_templates:
- wiretrustee/signal:{{ .Version }}-arm
- netbird/signal:{{ .Version }}-arm
ids:
- wiretrustee-signal
- netbird-signal
goarch: arm
goarm: 6
use: buildx
@ -334,17 +334,17 @@ docker_manifests:
- wiretrustee/wiretrustee:{{ .Version }}-arm
- wiretrustee/wiretrustee:{{ .Version }}-amd64
- name_template: wiretrustee/signal:{{ .Version }}
- name_template: netbird/signal:{{ .Version }}
image_templates:
- wiretrustee/signal:{{ .Version }}-arm64v8
- wiretrustee/signal:{{ .Version }}-arm
- wiretrustee/signal:{{ .Version }}-amd64
- netbird/signal:{{ .Version }}-arm64v8
- netbird/signal:{{ .Version }}-arm
- netbird/signal:{{ .Version }}-amd64
- name_template: wiretrustee/signal:latest
- name_template: netbird/signal:latest
image_templates:
- wiretrustee/signal:{{ .Version }}-arm64v8
- wiretrustee/signal:{{ .Version }}-arm
- wiretrustee/signal:{{ .Version }}-amd64
- netbird/signal:{{ .Version }}-arm64v8
- netbird/signal:{{ .Version }}-arm
- netbird/signal:{{ .Version }}-amd64
- name_template: netbird/management:{{ .Version }}
image_templates:

View File

@ -22,14 +22,24 @@ then
export TURN_PASSWORD=$(openssl rand -base64 32|sed 's/=//g')
fi
# if wiretrustee-mgmt already exists, leave it, else create new mgmt with netbird
MGMT_VOLUMENAME="${$VOLUME_PREFIX}${MGMT_VOLUMESUFFIX}"
SIGNAL_VOLUMENAME="${$VOLUME_PREFIX}${SIGNAL_VOLUMESUFFIX}"
LETSENCRYPT_VOLUMENAME="${$VOLUME_PREFIX}${LETSENCRYPT_VOLUMESUFFIX}"
# if volume with wiretrustee- prefix already exists, use it, else create new with netbird-
OLD_PREFIX='wiretrustee-'
if docker volume ls | grep -q "${OLD_PREFIX}mgmt"; then
VOLUME_PREFIX=$OLD_PREFIX
if docker volume ls | grep -q "${OLD_PREFIX}${MGMT_VOLUMESUFFIX}"; then
MGMT_VOLUMENAME="${$OLD_PREFIX}${MGMT_VOLUMESUFFIX}"
fi
if docker volume ls | grep -q "${OLD_PREFIX}${SIGNAL_VOLUMESUFFIX}"; then
SIGNAL_VOLUMENAME="${$OLD_PREFIX}${SIGNAL_VOLUMESUFFIX}"
fi
if docker volume ls | grep -q "${OLD_PREFIX}${LETSENCRYPT_VOLUMESUFFIX}"; then
LETSENCRYPT_VOLUMENAME="${$OLD_PREFIX}${LETSENCRYPT_VOLUMESUFFIX}"
fi
export MGMT_VOLUMENAME="${$VOLUME_PREFIX}mgmt"
export LETSENCRYPT_VOLUMENAME="${$VOLUME_PREFIX}letsencrypt"
export MGMT_VOLUMENAME
export SIGNAL_VOLUMENAME
export LETSENCRYPT_VOLUMENAME
envsubst < docker-compose.yml.tmpl > docker-compose.yml
envsubst < management.json.tmpl > management.json

View File

@ -19,10 +19,10 @@ services:
- $LETSENCRYPT_VOLUMENAME:/etc/letsencrypt/
# Signal
signal:
image: wiretrustee/signal:latest
image: netbird/signal:latest
restart: unless-stopped
volumes:
- wiretrustee-signal:/var/lib/wiretrustee
- $SIGNAL_VOLUMENAME:/var/lib/netbird
ports:
- 10000:10000
# # port and command for Let's Encrypt validation
@ -56,5 +56,5 @@ services:
network_mode: host
volumes:
$MGMT_VOLUMENAME:
wiretrustee-signal:
$LETSENCRYPT_VOLUMENAME:
$SIGNAL_VOLUMENAME:
$LETSENCRYPT_VOLUMENAME:

View File

@ -38,11 +38,11 @@ TURN_MIN_PORT=49152
TURN_MAX_PORT=65535
VOLUME_PREFIX="netbird-"
MGMT_VOLUMENAME=""
LETSENCRYPT_VOLUMENAME=""
MGMT_VOLUMESUFFIX="mgmt"
SIGNAL_VOLUMESUFFIX="signal"
LETSENCRYPT_VOLUMESUFFIX="letsencrypt"
# exports
export VOLUME_PREFIX
export WIRETRUSTEE_DOMAIN
export WIRETRUSTEE_AUTH0_DOMAIN
export WIRETRUSTEE_AUTH0_CLIENT_ID
@ -56,4 +56,7 @@ export TURN_USER
export TURN_PASSWORD
export TURN_MIN_PORT
export TURN_MAX_PORT
export VOLUME_PREFIX
export MGMT_VOLUMESUFFIX
export SIGNAL_VOLUMESUFFIX
export LETSENCRYPT_VOLUMESUFFIX

View File

@ -60,9 +60,8 @@ var (
if mgmtDataDir == "" {
oldPath := "/var/lib/wiretrustee"
newPath := "/var/lib/netbird"
if migrateToNetbird(oldPath, newPath) {
if err := cpDir(oldPath, newPath); err != nil {
if migrateToNetbird(oldPath, defaultMgmtDataDir) {
if err := cpDir(oldPath, defaultMgmtDataDir); err != nil {
log.Fatal(err)
}
}
@ -72,7 +71,7 @@ var (
if mgmtConfig == "" {
oldPath := "/etc/wiretrustee/management.json"
if migrateToNetbird(oldPath, defaultMgmtConfig) {
if err := cpDir("/etc/wiretrustee/", "/etc/netbird/"); err != nil {
if err := cpDir("/etc/wiretrustee/", defaultConfigPath); err != nil {
log.Fatal(err)
}

View File

@ -1,4 +1,4 @@
FROM gcr.io/distroless/base:debug
ENTRYPOINT [ "/go/bin/wiretrustee-signal","run" ]
ENTRYPOINT [ "/go/bin/netbird-signal","run" ]
CMD ["--log-file", "console"]
COPY wiretrustee-signal /go/bin/wiretrustee-signal
COPY netbird-signal /go/bin/netbird-signal

View File

@ -2,10 +2,11 @@ package cmd
import (
"fmt"
"github.com/spf13/cobra"
"os"
"os/signal"
"runtime"
"github.com/spf13/cobra"
)
const (
@ -19,7 +20,7 @@ var (
logFile string
rootCmd = &cobra.Command{
Use: "wiretrustee-signal",
Use: "netbird-signal",
Short: "",
Long: "",
}
@ -32,16 +33,18 @@ var (
func Execute() error {
return rootCmd.Execute()
}
func init() {
func init() {
stopCh = make(chan int)
defaultLogFile = "/var/log/wiretrustee/signal.log"
defaultLogFile = "/var/log/netbird/signal.log"
defaultSignalSSLDir = "/var/lib/netbird/"
if runtime.GOOS == "windows" {
defaultLogFile = os.Getenv("PROGRAMDATA") + "\\Wiretrustee\\" + "signal.log"
defaultLogFile = os.Getenv("PROGRAMDATA") + "\\Netbird\\" + "signal.log"
}
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "")
rootCmd.PersistentFlags().StringVar(&logFile, "log-file", defaultLogFile, "sets Wiretrustee log path. If console is specified the the log will be output to stdout")
rootCmd.PersistentFlags().StringVar(&logFile, "log-file", defaultLogFile, "sets Netbird log path. If console is specified the the log will be output to stdout")
rootCmd.AddCommand(runCmd)
}

View File

@ -3,6 +3,14 @@ package cmd
import (
"flag"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
"path"
"time"
"github.com/netbirdio/netbird/encryption"
"github.com/netbirdio/netbird/signal/proto"
"github.com/netbirdio/netbird/signal/server"
@ -12,16 +20,13 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive"
"net"
"net/http"
"os"
"time"
)
var (
signalPort int
signalLetsencryptDomain string
signalSSLDir string
defaultSignalSSLDir string
signalKaep = grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: 5 * time.Second,
@ -37,7 +42,7 @@ var (
runCmd = &cobra.Command{
Use: "run",
Short: "start Wiretrustee Signal Server daemon",
Short: "start Netbird Signal Server daemon",
Run: func(cmd *cobra.Command, args []string) {
flag.Parse()
err := util.InitLog(logLevel, logFile)
@ -45,6 +50,15 @@ var (
log.Fatalf("failed initializing log %v", err)
}
if signalSSLDir == "" {
oldPath := "/var/lib/wiretrustee"
if migrateToNetbird(oldPath, defaultSignalSSLDir) {
if err := cpDir(oldPath, defaultSignalSSLDir); err != nil {
log.Fatal(err)
}
}
}
var opts []grpc.ServerOption
if signalLetsencryptDomain != "" {
if _, err := os.Stat(signalSSLDir); os.IsNotExist(err) {
@ -87,8 +101,95 @@ var (
}
)
func cpFile(src, dst string) error {
var err error
var srcfd *os.File
var dstfd *os.File
var srcinfo os.FileInfo
if srcfd, err = os.Open(src); err != nil {
return err
}
defer srcfd.Close()
if dstfd, err = os.Create(dst); err != nil {
return err
}
defer dstfd.Close()
if _, err = io.Copy(dstfd, srcfd); err != nil {
return err
}
if srcinfo, err = os.Stat(src); err != nil {
return err
}
return os.Chmod(dst, srcinfo.Mode())
}
func copySymLink(source, dest string) error {
link, err := os.Readlink(source)
if err != nil {
return err
}
return os.Symlink(link, dest)
}
func cpDir(src string, dst string) error {
var err error
var fds []os.FileInfo
var srcinfo os.FileInfo
if srcinfo, err = os.Stat(src); err != nil {
return err
}
if err = os.MkdirAll(dst, srcinfo.Mode()); err != nil {
return err
}
if fds, err = ioutil.ReadDir(src); err != nil {
return err
}
for _, fd := range fds {
srcfp := path.Join(src, fd.Name())
dstfp := path.Join(dst, fd.Name())
fileInfo, err := os.Stat(srcfp)
if err != nil {
log.Fatalf("Couldn't get fileInfo; %v", err)
}
switch fileInfo.Mode() & os.ModeType {
case os.ModeSymlink:
if err = copySymLink(srcfp, dstfp); err != nil {
log.Fatalf("Failed to copy from %s to %s; %v", srcfp, dstfp, err)
}
case os.ModeDir:
if err = cpDir(srcfp, dstfp); err != nil {
log.Fatalf("Failed to copy from %s to %s; %v", srcfp, dstfp, err)
}
default:
if err = cpFile(srcfp, dstfp); err != nil {
log.Fatalf("Failed to copy from %s to %s; %v", srcfp, dstfp, err)
}
}
}
return nil
}
func migrateToNetbird(oldPath, newPath string) bool {
_, old := os.Stat(oldPath)
_, new := os.Stat(newPath)
if os.IsNotExist(old) || os.IsExist(new) {
return false
}
return true
}
func init() {
runCmd.PersistentFlags().IntVar(&signalPort, "port", 10000, "Server port to listen on (e.g. 10000)")
runCmd.Flags().StringVar(&signalSSLDir, "ssl-dir", "/var/lib/wiretrustee/", "server ssl directory location. *Required only for Let's Encrypt certificates.")
runCmd.Flags().StringVar(&signalSSLDir, "ssl-dir", defaultSignalSSLDir, "server ssl directory location. *Required only for Let's Encrypt certificates.")
runCmd.Flags().StringVar(&signalLetsencryptDomain, "letsencrypt-domain", "", "a domain to issue Let's Encrypt certificate for. Enables TLS using Let's Encrypt. Will fetch and renew certificate, and run the server with TLS")
}