adding userspace docker server implementation

This commit is contained in:
afeiszli 2021-10-08 22:46:39 -04:00
parent f9a4eb6bb2
commit 875b1d72b9
9 changed files with 129 additions and 5 deletions

View file

@ -0,0 +1,56 @@
version: "3.4"
services:
netmaker:
container_name: netmaker
image: gravitl/netmaker:v0.8.3
volumes:
- /etc/netclient/config:/etc/netclient/config
- /usr/bin/wg:/usr/bin/wg
- sqldata:/root/data
cap_add:
- NET_ADMIN
restart: always
network_mode: host
environment:
SERVER_HOST: "SERVER_PUBLIC_IP"
SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443"
SERVER_GRPC_CONN_STRING: "grpc.NETMAKER_BASE_DOMAIN:443"
COREDNS_ADDR: "SERVER_PUBLIC_IP"
GRPC_SSL: "on"
DNS_MODE: "off"
SERVER_HTTP_HOST: "api.NETMAKER_BASE_DOMAIN"
SERVER_GRPC_HOST: "grpc.NETMAKER_BASE_DOMAIN"
API_PORT: "8081"
GRPC_PORT: "50051"
CLIENT_MODE: "on"
MASTER_KEY: "REPLACE_MASTER_KEY"
SERVER_GRPC_WIREGUARD: "off"
CORS_ALLOWED_ORIGIN: "*"
DATABASE: "sqlite"
netmaker-ui:
container_name: netmaker-ui
depends_on:
- netmaker
image: gravitl/netmaker-ui:v0.8
links:
- "netmaker:api"
ports:
- "8082:80"
environment:
BACKEND_URL: "https://api.NETMAKER_BASE_DOMAIN"
restart: always
caddy:
image: caddy:latest
container_name: caddy
restart: unless-stopped
network_mode: host # Wants ports 80 and 443!
volumes:
- /root/Caddyfile:/etc/caddy/Caddyfile
# - $PWD/site:/srv # you could also serve a static site in site folder
- caddy_data:/data
- caddy_conf:/config
volumes:
caddy_data: {}
caddy_conf: {}
sqldata: {}

View file

@ -45,6 +45,7 @@ type ServerConfig struct {
GRPCSecure string `yaml:"grpcsecure"`
MasterKey string `yaml:"masterkey"`
AllowedOrigin string `yaml:"allowedorigin"`
NodeID string `yaml:"nodeid"`
RestBackend string `yaml:"restbackend"`
AgentBackend string `yaml:"agentbackend"`
ClientMode string `yaml:"clientmode"`

View file

@ -84,12 +84,12 @@ func pgInsertPeer(key string, value string) error {
}
func pgDeleteRecord(tableName string, key string) error {
deleteSQL := "DELETE FROM " + tableName + " WHERE key = \"" + key + "\""
deleteSQL := "DELETE FROM " + tableName + " WHERE key = $1;"
statement, err := PGDB.Prepare(deleteSQL)
if err != nil {
return err
}
if _, err = statement.Exec(); err != nil {
if _, err = statement.Exec(key); err != nil {
return err
}
return nil

View file

@ -0,0 +1,16 @@
ARG NM_VERSION=
FROM gravitl/builder as builder
RUN apk add --update git build-base libmnl-dev iptables
WORKDIR /root/
RUN git clone https://git.zx2c4.com/wireguard-go && \
cd wireguard-go && \
make && \
make install
FROM gravitl/netmaker:${NM_VERSION}
RUN apk add --no-cache --update libmnl iptables openresolv iproute2
COPY --from=builder /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/

View file

@ -0,0 +1,23 @@
ARG NM_VERSION=
FROM gravitl/builder as builder
RUN apk add --update git build-base libmnl-dev iptables
WORKDIR /root/
RUN git clone https://git.zx2c4.com/wireguard-go && \
cd wireguard-go && \
make && \
make install
ENV WITH_WGQUICK=yes
RUN git clone https://git.zx2c4.com/wireguard-tools && \
cd wireguard-tools && \
cd src && \
make && \
make install
FROM gravitl/netmaker:${NM_VERSION}
RUN apk add --no-cache --update bash libmnl iptables openresolv iproute2
COPY --from=builder /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/

View file

@ -7,7 +7,6 @@ import (
"strconv"
"strings"
"time"
"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/dnslogic"
"github.com/gravitl/netmaker/functions"

View file

@ -48,7 +48,7 @@ type Node struct {
ExpirationDateTime int64 `json:"expdatetime" bson:"expdatetime" yaml:"expdatetime"`
LastPeerUpdate int64 `json:"lastpeerupdate" bson:"lastpeerupdate" yaml:"lastpeerupdate"`
LastCheckIn int64 `json:"lastcheckin" bson:"lastcheckin" yaml:"lastcheckin"`
MacAddress string `json:"macaddress" bson:"macaddress" yaml:"macaddress" validate:"required,mac,macaddress_unique"`
MacAddress string `json:"macaddress" bson:"macaddress" yaml:"macaddress" validate:"required,min=5,macaddress_unique"`
// checkin interval is depreciated at the network level. Set on server with CHECKIN_INTERVAL
CheckInInterval int32 `json:"checkininterval" bson:"checkininterval" yaml:"checkininterval"`
Password string `json:"password" bson:"password" yaml:"password" validate:"required,min=6"`

View file

@ -4,9 +4,9 @@ import (
"errors"
"io/ioutil"
"net/http"
"net"
"os"
"strconv"
"github.com/gravitl/netmaker/config"
)
@ -31,6 +31,7 @@ func GetServerConfig() config.ServerConfig {
cfg.AllowedOrigin = GetAllowedOrigin()
cfg.RestBackend = "off"
cfg.Verbosity = GetVerbose()
cfg.NodeID = GetNodeID()
cfg.CheckinInterval = GetCheckinInterval()
if IsRestBackend() {
cfg.RestBackend = "on"
@ -372,3 +373,30 @@ func IsSplitDNS() bool {
}
return issplit
}
func GetNodeID() string {
var id string
id = getMacAddr()
if os.Getenv("NODE_ID") != "" {
id = os.Getenv("NODE_ID")
} else if config.Config.Server.NodeID != "" {
id = config.Config.Server.NodeID
}
return id
}
// GetMacAddr - get's mac address
func getMacAddr() string {
ifas, err := net.Interfaces()
if err != nil {
return ""
}
var as []string
for _, ifa := range ifas {
a := ifa.HardwareAddr.String()
if a != "" {
as = append(as, a)
}
}
return as[0]
}

View file

@ -196,6 +196,7 @@ func AddNetwork(network string) (bool, error) {
IsServer: "yes",
DNSOn: "no",
Name: models.NODE_SERVER_NAME,
MacAddress: servercfg.GetNodeID(),
},
}, "")
log.Println("[netmaker] Server added to network " + network)