Fix up host ports and env variables
This commit is contained in:
parent
7c830f58be
commit
98249948a1
8 changed files with 38 additions and 55 deletions
|
@ -15,7 +15,6 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var address = os.Getenv("HOST_ADDRESS")
|
|
||||||
var data = os.Getenv("DATA_PATH")
|
var data = os.Getenv("DATA_PATH")
|
||||||
|
|
||||||
// accountantServer is the internal object to manage the requests
|
// accountantServer is the internal object to manage the requests
|
||||||
|
@ -82,8 +81,9 @@ func (a *accountantServer) GetValue(_ context.Context, in *accounts.DataKey) (*a
|
||||||
// main
|
// main
|
||||||
func main() {
|
func main() {
|
||||||
// Verify the input
|
// Verify the input
|
||||||
|
var address = os.Getenv("ROVE_ACCOUNTANT_GRPC")
|
||||||
if len(address) == 0 {
|
if len(address) == 0 {
|
||||||
log.Fatal("No address set with $HOST_ADDRESS")
|
log.Fatal("No address set with $ROVE_ACCOUNTANT_GRPC")
|
||||||
}
|
}
|
||||||
|
|
||||||
persistence.SetPath(data)
|
persistence.SetPath(data)
|
||||||
|
|
|
@ -2,44 +2,42 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
"github.com/mdiluz/rove/pkg/rove"
|
"github.com/mdiluz/rove/pkg/rove"
|
||||||
)
|
)
|
||||||
|
|
||||||
var endpoint = os.Getenv("GRPC_ENDPOINT")
|
func main() {
|
||||||
var address = os.Getenv("HOST_ADDRESS")
|
|
||||||
|
|
||||||
func run() error {
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Create a new mux and register it with the gRPC engpoint
|
var endpoint = os.Getenv("ROVE_GRPC")
|
||||||
|
if len(endpoint) == 0 {
|
||||||
|
log.Fatal("Must set $ROVE_GRPC")
|
||||||
|
}
|
||||||
|
|
||||||
|
var address = os.Getenv("ROVE_HTTP")
|
||||||
|
if len(address) == 0 {
|
||||||
|
log.Fatal("Must set $ROVE_HTTP")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new mux and register it with the gRPC endpoint
|
||||||
fmt.Printf("Hosting reverse-proxy on %s for %s\n", address, endpoint)
|
fmt.Printf("Hosting reverse-proxy on %s for %s\n", address, endpoint)
|
||||||
mux := runtime.NewServeMux()
|
mux := runtime.NewServeMux()
|
||||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||||
err := rove.RegisterRoveHandlerFromEndpoint(ctx, mux, endpoint, opts)
|
if err := rove.RegisterRoveHandlerFromEndpoint(ctx, mux, endpoint, opts); err != nil {
|
||||||
if err != nil {
|
log.Fatal(err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the HTTP server and proxy calls to gRPC endpoint when needed
|
// Start the HTTP server and proxy calls to gRPC endpoint when needed
|
||||||
return http.ListenAndServe(address, mux)
|
if err := http.ListenAndServe(address, mux); err != nil {
|
||||||
}
|
log.Fatal(err)
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
defer glog.Flush()
|
|
||||||
|
|
||||||
if err := run(); err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var accountantAddress = os.Getenv("ACCOUNTANT_ADDRESS")
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// PersistentData will allow the server to load and save it's state
|
// PersistentData will allow the server to load and save it's state
|
||||||
PersistentData = iota
|
PersistentData = iota
|
||||||
|
@ -106,8 +104,9 @@ func (s *Server) Initialise(fillWorld bool) (err error) {
|
||||||
s.sync.Add(1)
|
s.sync.Add(1)
|
||||||
|
|
||||||
// Connect to the accountant
|
// Connect to the accountant
|
||||||
|
accountantAddress := os.Getenv("ROVE_ACCOUNTANT_GRPC")
|
||||||
if len(accountantAddress) == 0 {
|
if len(accountantAddress) == 0 {
|
||||||
log.Fatal("must set ACCOUNTANT_ADDRESS")
|
log.Fatal("must set $ROVE_ACCOUNTANT_GRPC")
|
||||||
}
|
}
|
||||||
log.Printf("Dialing accountant on %s\n", accountantAddress)
|
log.Printf("Dialing accountant on %s\n", accountantAddress)
|
||||||
s.clientConn, err = grpc.Dial(accountantAddress, grpc.WithInsecure())
|
s.clientConn, err = grpc.Dial(accountantAddress, grpc.WithInsecure())
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ func TestNewServer_OptionPersistentData(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_Run(t *testing.T) {
|
func TestServer_Run(t *testing.T) {
|
||||||
|
os.Setenv("ROVE_ACCOUNTANT_GRPC", "n/a")
|
||||||
server := NewServer()
|
server := NewServer()
|
||||||
if server == nil {
|
if server == nil {
|
||||||
t.Error("Failed to create server")
|
t.Error("Failed to create server")
|
||||||
|
@ -45,6 +47,7 @@ func TestServer_Run(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_RunPersistentData(t *testing.T) {
|
func TestServer_RunPersistentData(t *testing.T) {
|
||||||
|
os.Setenv("ROVE_ACCOUNTANT_GRPC", "n/a")
|
||||||
server := NewServer(OptionPersistentData())
|
server := NewServer(OptionPersistentData())
|
||||||
if server == nil {
|
if server == nil {
|
||||||
t.Error("Failed to create server")
|
t.Error("Failed to create server")
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/mdiluz/rove/cmd/rove-server/internal"
|
"github.com/mdiluz/rove/cmd/rove-server/internal"
|
||||||
"github.com/mdiluz/rove/pkg/persistence"
|
"github.com/mdiluz/rove/pkg/persistence"
|
||||||
|
@ -15,10 +14,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var ver = flag.Bool("version", false, "Display version number")
|
var ver = flag.Bool("version", false, "Display version number")
|
||||||
var quit = flag.Int("quit", 0, "Quit after n seconds, useful for testing")
|
|
||||||
|
|
||||||
// Address to host the server on, automatically selected if empty
|
|
||||||
var address = os.Getenv("HOST_ADDRESS")
|
|
||||||
|
|
||||||
// Path for persistent storage
|
// Path for persistent storage
|
||||||
var data = os.Getenv("DATA_PATH")
|
var data = os.Getenv("DATA_PATH")
|
||||||
|
@ -35,8 +30,10 @@ func InnerMain() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Address to host the server on, automatically selected if empty
|
||||||
|
var address = os.Getenv("ROVE_GRPC")
|
||||||
if len(address) == 0 {
|
if len(address) == 0 {
|
||||||
log.Fatalf("Must set HOST_ADDRESS")
|
log.Fatalf("Must set $ROVE_GRPC")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Initialising version %s...\n", version.Version)
|
log.Printf("Initialising version %s...\n", version.Version)
|
||||||
|
@ -76,14 +73,6 @@ func InnerMain() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Quit after a time if requested
|
|
||||||
if *quit != 0 {
|
|
||||||
go func() {
|
|
||||||
time.Sleep(time.Duration(*quit) * time.Second)
|
|
||||||
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run the server
|
// Run the server
|
||||||
s.Run()
|
s.Run()
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,3 @@ func Test_InnerMain_Version(t *testing.T) {
|
||||||
InnerMain()
|
InnerMain()
|
||||||
flag.Set("version", "0")
|
flag.Set("version", "0")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_InnerMain_Quit(t *testing.T) {
|
|
||||||
flag.Set("quit", "1")
|
|
||||||
InnerMain()
|
|
||||||
flag.Set("quit", "0")
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,9 +15,9 @@ import (
|
||||||
|
|
||||||
func Test_InnerMain(t *testing.T) {
|
func Test_InnerMain(t *testing.T) {
|
||||||
|
|
||||||
var address = os.Getenv("ROVE_SERVER_ADDRESS")
|
var address = os.Getenv("ROVE_GRPC")
|
||||||
if len(address) == 0 {
|
if len(address) == 0 {
|
||||||
log.Fatal("Must set ROVE_SERVER_ADDRESS")
|
log.Fatal("Must set $ROVE_GRPC")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the flags to act locally and use a temporary file
|
// Set up the flags to act locally and use a temporary file
|
||||||
|
|
|
@ -10,9 +10,9 @@ services:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
image: rove:latest
|
image: rove:latest
|
||||||
ports:
|
ports:
|
||||||
- "8081:8081"
|
- "9091:9091"
|
||||||
environment:
|
environment:
|
||||||
- HOST_ADDRESS=:8081
|
- ROVE_ACCOUNTANT_GRPC=:9091
|
||||||
- DATA_PATH=/mnt/rove-server
|
- DATA_PATH=/mnt/rove-server
|
||||||
volumes:
|
volumes:
|
||||||
- persistent-data:/mnt/rove-server:rw
|
- persistent-data:/mnt/rove-server:rw
|
||||||
|
@ -26,8 +26,8 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
environment:
|
environment:
|
||||||
- HOST_ADDRESS=:8080
|
- ROVE_HTTP=:8080
|
||||||
- GRPC_ENDPOINT=rove-server:8082
|
- ROVE_GRPC=:9090
|
||||||
command: [ ./rove-reverse-proxy ]
|
command: [ ./rove-reverse-proxy ]
|
||||||
|
|
||||||
rove-docs:
|
rove-docs:
|
||||||
|
@ -47,11 +47,11 @@ services:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
image: rove:latest
|
image: rove:latest
|
||||||
ports:
|
ports:
|
||||||
- "8082:8082"
|
- "9090:9090"
|
||||||
environment:
|
environment:
|
||||||
- HOST_ADDRESS=:8082
|
- ROVE_GRPC=:9090
|
||||||
- DATA_PATH=/mnt/rove-server
|
- DATA_PATH=/mnt/rove-server
|
||||||
- ACCOUNTANT_ADDRESS=rove-accountant:8081
|
- ROVE_ACCOUNTANT_GRPC=:9091
|
||||||
volumes:
|
volumes:
|
||||||
- persistent-data:/mnt/rove-server:rw
|
- persistent-data:/mnt/rove-server:rw
|
||||||
|
|
||||||
|
@ -62,8 +62,8 @@ services:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
image: rove:latest
|
image: rove:latest
|
||||||
environment:
|
environment:
|
||||||
- ACCOUNTANT_ADDRESS=rove-accountant:8081
|
- ROVE_ACCOUNTANT_GRPC=:9091
|
||||||
- ROVE_SERVER_ADDRESS=rove-reverse-proxy:8080
|
- ROVE_GRPC=rove-server:9090
|
||||||
command: [ "go", "test", "-v", "./...", "--tags=integration", "-cover", "-coverprofile=/mnt/coverage-data/c.out", "-count", "1" ]
|
command: [ "go", "test", "-v", "./...", "--tags=integration", "-cover", "-coverprofile=/mnt/coverage-data/c.out", "-count", "1" ]
|
||||||
volumes:
|
volumes:
|
||||||
- /tmp/coverage-data:/mnt/coverage-data:rw
|
- /tmp/coverage-data:/mnt/coverage-data:rw
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue