Skip to content

Commit

Permalink
added setup node, updated vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
ivcosla committed Apr 19, 2019
1 parent b312750 commit 59eef9a
Show file tree
Hide file tree
Showing 134 changed files with 33,290 additions and 382 deletions.
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ config: ## Generate skywire.json

clean: ## Clean project: remove created binaries and apps
-rm -rf ./apps
-rm -f ./skywire-node ./skywire-cli ./manager-node ./thereallssh-cli
-rm -f ./skywire-node ./skywire-cli ./setup-node ./manager-node ./thereallssh-cli

install: ## Install `skywire-node`, `skywire-cli`, `manager-node`, `therealssh-cli`
${OPTS} go install ./cmd/skywire-node ./cmd/skywire-cli ./cmd/manager-node ./cmd/therealssh-cli
${OPTS} go install ./cmd/skywire-node ./cmd/skywire-cli ./cmd/setup-node ./cmd/manager-node ./cmd/therealssh-cli

rerun: stop
${OPTS} go build -race -o ./skywire-node ./cmd/skywire-node
Expand All @@ -50,6 +50,7 @@ vendorcheck: ## Run vendorcheck
GO111MODULE=off vendorcheck ./pkg/...
GO111MODULE=off vendorcheck ./cmd/apps/...
GO111MODULE=off vendorcheck ./cmd/manager-node/...
GO111MODULE=off vendorcheck ./cmd/setup-node/...
GO111MODULE=off vendorcheck ./cmd/skywire-cli/...
GO111MODULE=off vendorcheck ./cmd/skywire-node/...
# vendorcheck fails on ./cmd/therealssh-cli
Expand Down Expand Up @@ -90,7 +91,6 @@ format: ## Formats the code. Must have goimports installed (use make install-lin
dep: ## Sorts dependencies
${OPTS} go mod vendor -v


# Apps
host-apps: ## Build app
${OPTS} go build -race -o ./apps/chat.v1.0 ./cmd/apps/chat
Expand All @@ -104,12 +104,14 @@ host-apps: ## Build app
bin: ## Build `skywire-node`, `skywire-cli`, `manager-node`, `therealssh-cli`
${OPTS} go build -race -o ./skywire-node ./cmd/skywire-node
${OPTS} go build -race -o ./skywire-cli ./cmd/skywire-cli
${OPTS} go build -race -o ./setup-node ./cmd/setup-node
${OPTS} go build -race -o ./manager-node ./cmd/manager-node
${OPTS} go build -race -o ./therealssh-cli ./cmd/therealssh-cli

release: ## Build skywire-node`, skywire-cli, manager-node, therealssh-cli and apps without -race flag
${OPTS} go build -o ./skywire-node ./cmd/skywire-node
${OPTS} go build -o ./skywire-cli ./cmd/skywire-cli
${OPTS} go build -o ./setup-node ./cmd/setup-node
${OPTS} go build -o ./manager-node ./cmd/manager-node
${OPTS} go build -o ./therealssh-cli ./cmd/therealssh-cli
${OPTS} go build -o ./apps/chat.v1.0 ./cmd/apps/chat
Expand Down Expand Up @@ -143,14 +145,22 @@ docker-apps: ## Build apps binaries for dockerized skywire-node. `go build` with
docker-bin: ## Build `skywire-node`, `skywire-cli`, `manager-node`, `therealssh-cli`. `go build` with ${DOCKER_OPTS}
${DOCKER_OPTS} go build -race -o ./node/skywire-node ./cmd/skywire-node

docker-volume: docker-apps docker-bin bin ## Prepare docker volume for dockerized skywire-node
docker-volume: dep docker-apps docker-bin bin ## Prepare docker volume for dockerized skywire-node
-${DOCKER_OPTS} go build -o ./docker/skywire-services/setup-node ./cmd/setup-node
-./skywire-cli node gen-config -o ./node/skywire.json -r
perl -pi -e 's/localhost//g' ./node/skywire.json # To make node accessible from outside with skywire-cli

docker-run: docker-clean docker-image docker-network docker-volume ## Run dockerized skywire-node ${DOCKER_NODE} in image ${DOCKER_IMAGE} with network ${DOCKER_NETWORK}
docker run -it -v $(shell pwd)/node:/sky --network=${DOCKER_NETWORK} \
--name=${DOCKER_NODE} ${DOCKER_IMAGE} bash -c "cd /sky && ./skywire-node skywire.json"

docker-setup-node: ## Runs setup-node in detached state in ${DOCKER_NETWORK}
-docker container rm setup-node -f
docker run -d --network=${DOCKER_NETWORK} \
--name=setup-node \
--hostname=setup-node skywire-services \
bash -c "./setup-node setup-node.json"

docker-stop: ## Stop running dockerized skywire-node ${DOCKER_NODE}
-docker container stop ${DOCKER_NODE}

Expand Down
86 changes: 86 additions & 0 deletions cmd/setup-node/commands/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package commands

import (
"context"
"encoding/json"
"log"
"log/syslog"
"net/http"
"os"

"github.com/prometheus/client_golang/prometheus/promhttp"
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cobra"

"github.com/skycoin/skywire/internal/metrics"
"github.com/skycoin/skywire/pkg/setup"
)

var (
metricsAddr string
syslogAddr string
tag string
)

var rootCmd = &cobra.Command{
Use: "setup-node [config.json]",
Short: "Route Setup Node for skywire",
Run: func(_ *cobra.Command, args []string) {
configFile := "config.json"
if len(args) > 0 {
configFile = args[0]
}
conf := parseConfig(configFile)

logger := logging.MustGetLogger(tag)
if syslogAddr != "" {
hook, err := logrus_syslog.NewSyslogHook("udp", syslogAddr, syslog.LOG_INFO, tag)
if err != nil {
logger.Fatalf("Unable to connect to syslog daemon on %v", syslogAddr)
}
logging.AddHook(hook)
}

sn, err := setup.NewNode(conf, metrics.NewPrometheus("setupnode"))
if err != nil {
logger.Fatal("Failed to setup Node: ", err)
}

go func() {
http.Handle("/metrics", promhttp.Handler())
if err := http.ListenAndServe(metricsAddr, nil); err != nil {
logger.Println("Failed to start metrics API:", err)
}
}()

logger.Fatal(sn.Serve(context.Background()))
},
}

func init() {
rootCmd.Flags().StringVarP(&metricsAddr, "metrics", "m", ":2121", "address to bind metrics API to")
rootCmd.Flags().StringVar(&syslogAddr, "syslog", "", "syslog server address. E.g. localhost:514")
rootCmd.Flags().StringVar(&tag, "tag", "setup-node", "logging tag")
}

func parseConfig(path string) *setup.Config {
file, err := os.Open(path)
if err != nil {
log.Fatalf("Failed to open config: %s", err)
}

conf := &setup.Config{}
if err := json.NewDecoder(file).Decode(&conf); err != nil {
log.Fatalf("Failed to decode %s: %s", path, err)
}

return conf
}

// Execute executes root CLI command.
func Execute() {
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
}
10 changes: 10 additions & 0 deletions cmd/setup-node/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"public_key": "024ec47420176680816e0406250e7156465e4531f5b26057c9f6297bb0303558c7",
"secret_key": "42bca4df2f3189b28872d40e6c61aacd5e85b8e91f8fea65780af27c142419e5",
"messaging": {
"discovery": "http://skywire.skycoin.net:8001",
"server_count": 1
},
"transport_discovery": "http://skywire.skycoin.net:8003",
"log_level": "info"
}
7 changes: 7 additions & 0 deletions cmd/setup-node/setup-node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/skycoin/skywire/cmd/setup-node/commands"

func main() {
commands.Execute()
}
44 changes: 4 additions & 40 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,27 @@ module github.com/skycoin/skywire
go 1.12

require (
github.com/FiloSottile/vendorcheck v0.0.0-20160511012517-d6d54d1b5894 // indirect
github.com/Masterminds/semver v1.4.2 // indirect
github.com/Masterminds/vcs v1.13.0 // indirect
github.com/acroca/go-symbols v0.1.1 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/boltdb/bolt v1.3.1 // indirect
github.com/calebthompson/ftree v0.2.0 // indirect
github.com/dvyukov/go-fuzz v0.0.0-20190402070214-9cfa592d5792 // indirect
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
github.com/ernesto-jimenez/gogen v0.0.0-20180125220232-d7d4131e6607 // indirect
github.com/fatih/gomodifytags v0.0.0-20180914191908-141225bf62b6 // indirect
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6
github.com/go-chi/chi v4.0.2+incompatible
github.com/go-delve/delve v1.2.0 // indirect
github.com/godbus/dbus v4.1.0+incompatible // indirect
github.com/golang/dep v0.5.1 // indirect
github.com/golangci/golangci-lint v1.16.0 // indirect
github.com/google/uuid v1.1.1
github.com/gorilla/securecookie v1.1.1
github.com/gorilla/sessions v1.1.3 // indirect
github.com/hanwen/go-fuse v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
github.com/jmank88/nuts v0.3.0 // indirect
github.com/karrick/godirwalk v1.8.0 // indirect
github.com/keegancsmith/rpc v1.1.0 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/kr/pty v1.1.3
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mibk/dupl v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/nightlyone/lockfile v0.0.0-20180618180623-0ad87eef1443 // indirect
github.com/oniony/TMSU v0.7.4 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/ramya-rao-a/go-outline v0.0.0-20181122025142-7182a932836a // indirect
github.com/rogpeppe/godef v1.1.1 // indirect
github.com/sdboyer/constext v0.0.0-20170321163424-836a14457353 // indirect
github.com/prometheus/client_golang v0.9.2
github.com/sirupsen/logrus v1.4.0
github.com/skycoin/skycoin v0.25.1
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518 // indirect
github.com/stamblerre/gocode v0.0.0-20190327203809-810592086997 // indirect
github.com/stephens2424/writerset v1.0.2 // indirect
github.com/stretchr/testify v1.3.0
github.com/tools/godep v0.0.0-20180126220526-ce0bfadeb516 // indirect
github.com/uudashr/gopkgs v2.0.1+incompatible // indirect
github.com/visualfc/fastmod v0.0.0-20190131104758-c069a47540eb // indirect
github.com/visualfc/gocode v0.0.0-20190319040811-fab173807d9b // indirect
github.com/visualfc/gotools v0.0.0-20190218124934-6d12497f1bd5 // indirect
go.etcd.io/bbolt v1.3.2
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
golang.org/x/net v0.0.0-20190324223953-e3b2ff56ed87
golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc // indirect
golang.org/x/tools v0.0.0-20190325223049-1d95b17f1b04 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)
Loading

0 comments on commit 59eef9a

Please sign in to comment.