mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-25 01:23:22 +01:00
Self contained signal cmd build (#82)
* Moved Signal CMD to Signal directory * Removed config dir and fixed a parameter typo * removed attempt to create ssl directory * Update Signal build configuration * move Signal documentation to its directory * removed unused variables * test build management and signal * User run as subcommand to execute the signal daemon
This commit is contained in:
parent
dcc9dcacdc
commit
80de6a75d5
10
.github/workflows/golang-test.yml
vendored
10
.github/workflows/golang-test.yml
vendored
@ -46,5 +46,13 @@ jobs:
|
|||||||
- name: Install modules
|
- name: Install modules
|
||||||
run: go mod tidy
|
run: go mod tidy
|
||||||
|
|
||||||
- name: run build
|
- name: run build cli
|
||||||
run: GOOS=${{ matrix.os }} go build .
|
run: GOOS=${{ matrix.os }} go build .
|
||||||
|
|
||||||
|
- name: run build management
|
||||||
|
run: GOOS=${{ matrix.os }} go build .
|
||||||
|
working-directory: management
|
||||||
|
|
||||||
|
- name: run build signal
|
||||||
|
run: GOOS=${{ matrix.os }} go build .
|
||||||
|
working-directory: signal
|
@ -30,6 +30,16 @@ builds:
|
|||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
- arm64
|
- arm64
|
||||||
|
|
||||||
|
- id: wiretrustee-signal
|
||||||
|
dir: signal
|
||||||
|
env: [CGO_ENABLED=0]
|
||||||
|
binary: wiretrustee-signal
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm64
|
||||||
archives:
|
archives:
|
||||||
- builds:
|
- builds:
|
||||||
- wiretrustee
|
- wiretrustee
|
||||||
@ -54,9 +64,9 @@ nfpms:
|
|||||||
postinstall: "release_files/post_install.sh"
|
postinstall: "release_files/post_install.sh"
|
||||||
dockers:
|
dockers:
|
||||||
- image_templates:
|
- image_templates:
|
||||||
- wiretrustee/wiretrustee:signal-{{ .Version }}-amd64
|
- wiretrustee/signal:{{ .Version }}-amd64
|
||||||
ids:
|
ids:
|
||||||
- wiretrustee
|
- wiretrustee-signal
|
||||||
goarch: amd64
|
goarch: amd64
|
||||||
use: buildx
|
use: buildx
|
||||||
dockerfile: signal/Dockerfile
|
dockerfile: signal/Dockerfile
|
||||||
@ -69,9 +79,9 @@ dockers:
|
|||||||
- "--label=org.opencontainers.image.version={{.Version}}"
|
- "--label=org.opencontainers.image.version={{.Version}}"
|
||||||
- "--label=maintainer=wiretrustee@wiretrustee.com"
|
- "--label=maintainer=wiretrustee@wiretrustee.com"
|
||||||
- image_templates:
|
- image_templates:
|
||||||
- wiretrustee/wiretrustee:signal-{{ .Version }}-arm64v8
|
- wiretrustee/signal:{{ .Version }}-arm64v8
|
||||||
ids:
|
ids:
|
||||||
- wiretrustee
|
- wiretrustee-signal
|
||||||
goarch: arm64
|
goarch: arm64
|
||||||
use: buildx
|
use: buildx
|
||||||
dockerfile: signal/Dockerfile
|
dockerfile: signal/Dockerfile
|
||||||
@ -145,15 +155,15 @@ dockers:
|
|||||||
- "--label=maintainer=wiretrustee@wiretrustee.com"
|
- "--label=maintainer=wiretrustee@wiretrustee.com"
|
||||||
|
|
||||||
docker_manifests:
|
docker_manifests:
|
||||||
- name_template: wiretrustee/wiretrustee:signal-{{ .Version }}
|
- name_template: wiretrustee/signal:{{ .Version }}
|
||||||
image_templates:
|
image_templates:
|
||||||
- wiretrustee/wiretrustee:signal-{{ .Version }}-arm64v8
|
- wiretrustee/signal:{{ .Version }}-arm64v8
|
||||||
- wiretrustee/wiretrustee:signal-{{ .Version }}-amd64
|
- wiretrustee/signal:{{ .Version }}-amd64
|
||||||
|
|
||||||
- name_template: wiretrustee/wiretrustee:signal-latest
|
- name_template: wiretrustee/signal:latest
|
||||||
image_templates:
|
image_templates:
|
||||||
- wiretrustee/wiretrustee:signal-{{ .Version }}-arm64v8
|
- wiretrustee/signal:{{ .Version }}-arm64v8
|
||||||
- wiretrustee/wiretrustee:signal-{{ .Version }}-amd64
|
- wiretrustee/signal:{{ .Version }}-amd64
|
||||||
|
|
||||||
- name_template: wiretrustee/management:{{ .Version }}
|
- name_template: wiretrustee/management:{{ .Version }}
|
||||||
image_templates:
|
image_templates:
|
||||||
|
16
README.md
16
README.md
@ -141,22 +141,6 @@ For **Windows** systems:
|
|||||||
.\wiretrustee.exe service start
|
.\wiretrustee.exe service start
|
||||||
```
|
```
|
||||||
> You may need to run Powershell as Administrator
|
> You may need to run Powershell as Administrator
|
||||||
### Running the Signal service
|
|
||||||
After installing the application, you can run the signal using the command below:
|
|
||||||
````shell
|
|
||||||
/usr/local/bin/wiretrustee signal --log-level INFO
|
|
||||||
````
|
|
||||||
This will launch the Signal server on port 10000, in case you want to change the port, use the flag --port.
|
|
||||||
#### Docker image
|
|
||||||
We have packed the Signal server into docker image. You can pull the image from Docker Hub and execute it with the following commands:
|
|
||||||
````shell
|
|
||||||
docker pull wiretrustee/wiretrustee:signal-latest
|
|
||||||
docker run -d --name wiretrustee-signal -p 10000:10000 wiretrustee/wiretrustee:signal-latest
|
|
||||||
````
|
|
||||||
The default log-level is set to INFO, if you need you can change it using by updating the docker cmd as followed:
|
|
||||||
````shell
|
|
||||||
docker run -d --name wiretrustee-signal -p 10000:10000 wiretrustee/wiretrustee:signal-latest --log-level DEBUG
|
|
||||||
````
|
|
||||||
|
|
||||||
### Running Management, Signal and Coturn
|
### Running Management, Signal and Coturn
|
||||||
Under infrastructure_files we have a docker-compose example to run both, Wiretrustee Management and Signal services, plus an instance of [Coturn](https://github.com/coturn/coturn), it also provides a turnserver.conf file as a simple example of Coturn configuration.
|
Under infrastructure_files we have a docker-compose example to run both, Wiretrustee Management and Signal services, plus an instance of [Coturn](https://github.com/coturn/coturn), it also provides a turnserver.conf file as a simple example of Coturn configuration.
|
||||||
|
@ -47,7 +47,6 @@ func init() {
|
|||||||
rootCmd.AddCommand(initCmd)
|
rootCmd.AddCommand(initCmd)
|
||||||
rootCmd.AddCommand(addPeerCmd)
|
rootCmd.AddCommand(addPeerCmd)
|
||||||
rootCmd.AddCommand(upCmd)
|
rootCmd.AddCommand(upCmd)
|
||||||
rootCmd.AddCommand(signalCmd)
|
|
||||||
rootCmd.AddCommand(serviceCmd)
|
rootCmd.AddCommand(serviceCmd)
|
||||||
serviceCmd.AddCommand(runCmd, startCmd, stopCmd, restartCmd) // service control commands are subcommands of service
|
serviceCmd.AddCommand(runCmd, startCmd, stopCmd, restartCmd) // service control commands are subcommands of service
|
||||||
serviceCmd.AddCommand(installCmd, uninstallCmd) // service installer commands are subcommands of service
|
serviceCmd.AddCommand(installCmd, uninstallCmd) // service installer commands are subcommands of service
|
||||||
|
@ -2,10 +2,15 @@ version: "3"
|
|||||||
services:
|
services:
|
||||||
# Signal
|
# Signal
|
||||||
signal:
|
signal:
|
||||||
image: wiretrustee/wiretrustee:signal-latest
|
image: wiretrustee/signal:latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- wiretrustee-mgmt:/var/lib/wiretrustee
|
||||||
ports:
|
ports:
|
||||||
- 10000:10000
|
- 10000:10000
|
||||||
|
# # port and command for Let's Encrypt validation
|
||||||
|
# - 443:443
|
||||||
|
# command: ["--letsencrypt-domain", "<YOUR-DOMAIN>"]
|
||||||
# Management
|
# Management
|
||||||
management:
|
management:
|
||||||
image: wiretrustee/management:latest
|
image: wiretrustee/management:latest
|
||||||
@ -30,3 +35,4 @@ services:
|
|||||||
network_mode: host
|
network_mode: host
|
||||||
volumes:
|
volumes:
|
||||||
wiretrustee-mgmt:
|
wiretrustee-mgmt:
|
||||||
|
wiretrustee-signal:
|
@ -1,3 +1,3 @@
|
|||||||
FROM gcr.io/distroless/base:debug
|
FROM gcr.io/distroless/base:debug
|
||||||
ENTRYPOINT [ "/go/bin/wiretrustee","signal" ]
|
ENTRYPOINT [ "/go/bin/wiretrustee-signal","run" ]
|
||||||
COPY wiretrustee /go/bin/wiretrustee
|
COPY wiretrustee-signal /go/bin/wiretrustee-signal
|
@ -2,6 +2,55 @@
|
|||||||
|
|
||||||
This is a Wiretrustee signal-exchange server and client library to exchange connection information between Wiretrustee peers
|
This is a Wiretrustee signal-exchange server and client library to exchange connection information between Wiretrustee peers
|
||||||
|
|
||||||
|
## Command Options
|
||||||
|
The CLI accepts the command **management** with the following options:
|
||||||
|
```shell
|
||||||
|
start Wiretrustee Signal Server daemon
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
wiretrustee-signal run [flags]
|
||||||
|
|
||||||
|
Flags:
|
||||||
|
-h, --help help for run
|
||||||
|
--letsencrypt-domain string 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
|
||||||
|
--port int Server port to listen on (e.g. 10000) (default 10000)
|
||||||
|
--ssl-dir string server ssl directory location. *Required only for Let's Encrypt certificates. (default "/var/lib/wiretrustee/")
|
||||||
|
|
||||||
|
Global Flags:
|
||||||
|
--log-level string (default "info")
|
||||||
|
```
|
||||||
|
## Running the Signal service (Docker)
|
||||||
|
|
||||||
|
We have packed the Signal server into docker image. You can pull the image from Docker Hub and execute it with the following commands:
|
||||||
|
````shell
|
||||||
|
docker pull wiretrustee/signal:latest
|
||||||
|
docker run -d --name wiretrustee-signal -p 10000:10000 wiretrustee/signal:latest
|
||||||
|
````
|
||||||
|
The default log-level is set to INFO, if you need you can change it using by updating the docker cmd as followed:
|
||||||
|
````shell
|
||||||
|
docker run -d --name wiretrustee-signal -p 10000:10000 wiretrustee/signal:latest --log-level DEBUG
|
||||||
|
````
|
||||||
|
### Run with TLS (Let's Encrypt).
|
||||||
|
By specifying the **--letsencrypt-domain** the daemon will handle SSL certificate request and configuration.
|
||||||
|
|
||||||
|
In the following example ```10000``` is the signal service **default** port, and ```443``` will be used as port for Let's Encrypt challenge and HTTP API.
|
||||||
|
> The server where you are running a container has to have a public IP (for Let's Encrypt certificate challenge).
|
||||||
|
|
||||||
|
Replace <YOUR-DOMAIN> with your server's public domain (e.g. mydomain.com or subdomain sub.mydomain.com).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# create a volume
|
||||||
|
docker volume create wiretrustee-signal
|
||||||
|
# run the docker container
|
||||||
|
docker run -d --name wiretrustee-management \
|
||||||
|
-p 10000:10000 \
|
||||||
|
-p 443:443 \
|
||||||
|
-v wiretrustee-signal:/var/lib/wiretrustee \
|
||||||
|
wiretrustee/signal:latest \
|
||||||
|
--letsencrypt-domain <YOUR-DOMAIN>
|
||||||
|
```
|
||||||
|
## For development purposes:
|
||||||
|
|
||||||
The project uses gRpc library and defines service in protobuf file located in:
|
The project uses gRpc library and defines service in protobuf file located in:
|
||||||
```proto/signalexchange.proto```
|
```proto/signalexchange.proto```
|
||||||
|
|
||||||
|
62
signal/cmd/root.go
Normal file
62
signal/cmd/root.go
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ExitSetupFailed defines exit code
|
||||||
|
ExitSetupFailed = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
logLevel string
|
||||||
|
|
||||||
|
rootCmd = &cobra.Command{
|
||||||
|
Use: "wiretrustee-signal",
|
||||||
|
Short: "",
|
||||||
|
Long: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execution control channel for stopCh signal
|
||||||
|
stopCh chan int
|
||||||
|
)
|
||||||
|
|
||||||
|
// Execute executes the root command.
|
||||||
|
func Execute() error {
|
||||||
|
return rootCmd.Execute()
|
||||||
|
}
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
stopCh = make(chan int)
|
||||||
|
|
||||||
|
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "")
|
||||||
|
rootCmd.AddCommand(runCmd)
|
||||||
|
InitLog(logLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupCloseHandler handles SIGTERM signal and exits with success
|
||||||
|
func SetupCloseHandler() {
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt)
|
||||||
|
go func() {
|
||||||
|
for range c {
|
||||||
|
fmt.Println("\r- Ctrl+C pressed in Terminal")
|
||||||
|
stopCh <- 0
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitLog parses and sets log-level input
|
||||||
|
func InitLog(logLevel string) {
|
||||||
|
level, err := log.ParseLevel(logLevel)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed parsing log-level %s: %s", logLevel, err)
|
||||||
|
os.Exit(ExitSetupFailed)
|
||||||
|
}
|
||||||
|
log.SetLevel(level)
|
||||||
|
}
|
@ -6,7 +6,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/wiretrustee/wiretrustee/encryption"
|
"github.com/wiretrustee/wiretrustee/encryption"
|
||||||
sigProto "github.com/wiretrustee/wiretrustee/signal/proto"
|
"github.com/wiretrustee/wiretrustee/signal/proto"
|
||||||
"github.com/wiretrustee/wiretrustee/signal/server"
|
"github.com/wiretrustee/wiretrustee/signal/server"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
@ -19,7 +19,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
signalPort int
|
signalPort int
|
||||||
signalLetsencryptDomain string
|
signalLetsencryptDomain string
|
||||||
signalDataDir string
|
signalSSLDir string
|
||||||
|
|
||||||
signalKaep = grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
|
signalKaep = grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
|
||||||
MinTime: 5 * time.Second,
|
MinTime: 5 * time.Second,
|
||||||
@ -33,22 +33,21 @@ var (
|
|||||||
Timeout: 2 * time.Second,
|
Timeout: 2 * time.Second,
|
||||||
})
|
})
|
||||||
|
|
||||||
signalCmd = &cobra.Command{
|
runCmd = &cobra.Command{
|
||||||
Use: "signal",
|
Use: "run",
|
||||||
Short: "start Wiretrustee Signal Server",
|
Short: "start Wiretrustee Signal Server daemon",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if _, err := os.Stat(signalDataDir); os.IsNotExist(err) {
|
|
||||||
err = os.MkdirAll(signalDataDir, os.ModeDir)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("failed creating datadir: %s: %v", signalDataDir, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var opts []grpc.ServerOption
|
var opts []grpc.ServerOption
|
||||||
if signalLetsencryptDomain != "" {
|
if signalLetsencryptDomain != "" {
|
||||||
certManager := encryption.CreateCertManager(signalDataDir, signalLetsencryptDomain)
|
if _, err := os.Stat(signalSSLDir); os.IsNotExist(err) {
|
||||||
|
err = os.MkdirAll(signalSSLDir, os.ModeDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed creating datadir: %s: %v", signalSSLDir, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
certManager := encryption.CreateCertManager(signalSSLDir, signalLetsencryptDomain)
|
||||||
transportCredentials := credentials.NewTLS(certManager.TLSConfig())
|
transportCredentials := credentials.NewTLS(certManager.TLSConfig())
|
||||||
opts = append(opts, grpc.Creds(transportCredentials))
|
opts = append(opts, grpc.Creds(transportCredentials))
|
||||||
}
|
}
|
||||||
@ -65,7 +64,7 @@ var (
|
|||||||
log.Fatalf("failed to listen: %v", err)
|
log.Fatalf("failed to listen: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sigProto.RegisterSignalExchangeServer(grpcServer, server.NewServer())
|
proto.RegisterSignalExchangeServer(grpcServer, server.NewServer())
|
||||||
log.Printf("started server: localhost:%v", signalPort)
|
log.Printf("started server: localhost:%v", signalPort)
|
||||||
if err := grpcServer.Serve(lis); err != nil {
|
if err := grpcServer.Serve(lis); err != nil {
|
||||||
log.Fatalf("failed to serve: %v", err)
|
log.Fatalf("failed to serve: %v", err)
|
||||||
@ -79,7 +78,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
signalCmd.PersistentFlags().IntVar(&signalPort, "port", 10000, "Server port to listen on (e.g. 10000)")
|
runCmd.PersistentFlags().IntVar(&signalPort, "port", 10000, "Server port to listen on (e.g. 10000)")
|
||||||
signalCmd.Flags().StringVar(&signalDataDir, "datadir", "/var/lib/wiretrustee/", "server data directory location")
|
runCmd.Flags().StringVar(&signalSSLDir, "ssl-dir", "/var/lib/wiretrustee/", "server ssl directory location. *Required only for Let's Encrypt certificates.")
|
||||||
signalCmd.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")
|
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")
|
||||||
}
|
}
|
12
signal/main.go
Normal file
12
signal/main.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/wiretrustee/wiretrustee/signal/cmd"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if err := cmd.Execute(); err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user