Skip to content

Commit

Permalink
Merge pull request #724 from mesg-foundation/feature/remove-system-se…
Browse files Browse the repository at this point in the history
…rvices

Remove system services
  • Loading branch information
NicolasMahe committed Jan 23, 2019
2 parents 30d9120 + 47bcc8c commit 89a8731
Show file tree
Hide file tree
Showing 18 changed files with 20 additions and 353 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -23,7 +23,7 @@ jobs:
keys:
- test-cache-{{ .Branch }}-{{ .Environment.CIRCLE_PREVIOUS_BUILD_NUM }}
- test-cache-{{ .Branch }}
- run: mkdir -p ~/.mesg && ln -s ~/project/systemservices/sources ~/.mesg/systemservices
- run: mkdir -p ~/.mesg
- run: go mod download
- run: go test -v -timeout 300s -p 1 -tags=integration -coverprofile=coverage.txt ./...
- save_cache:
Expand Down
4 changes: 2 additions & 2 deletions .dockerignore
Expand Up @@ -16,5 +16,5 @@ docs/
scripts/
docker-images/

# prevent go build cache to break inside Docker on changes to systemservices/sources.
systemservices/sources
# prevent go build cache to break inside Docker on changes to systemservices.
systemservices
12 changes: 5 additions & 7 deletions api/api.go
Expand Up @@ -3,23 +3,21 @@ package api
import (
"github.com/mesg-foundation/core/container"
"github.com/mesg-foundation/core/database"
"github.com/mesg-foundation/core/systemservices"
)

// API exposes all functionalities of MESG core.
type API struct {
db database.ServiceDB
execDB database.ExecutionDB
systemservices *systemservices.SystemServices
container container.Container
db database.ServiceDB
execDB database.ExecutionDB
container container.Container
}

// Option is a configuration func for MESG.
type Option func(*API)

// New creates a new API with given options.
func New(db database.ServiceDB, execDB database.ExecutionDB, systemservices *systemservices.SystemServices, options ...Option) (*API, error) {
a := &API{db: db, execDB: execDB, systemservices: systemservices}
func New(db database.ServiceDB, execDB database.ExecutionDB, options ...Option) (*API, error) {
a := &API{db: db, execDB: execDB}
for _, option := range options {
option(a)
}
Expand Down
5 changes: 1 addition & 4 deletions api/api_test.go
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/mesg-foundation/core/container"
"github.com/mesg-foundation/core/container/dockertest"
"github.com/mesg-foundation/core/database"
"github.com/mesg-foundation/core/systemservices"
"github.com/stretchr/testify/require"
)

Expand All @@ -28,9 +27,7 @@ func newAPIAndDockerTest(t *testing.T) (*API, *dockertest.Testing, func()) {
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

ss := systemservices.New()

a, err := New(db, execDB, ss, ContainerOption(container))
a, err := New(db, execDB, ContainerOption(container))
require.NoError(t, err)

closer := func() {
Expand Down
5 changes: 0 additions & 5 deletions config/config.go
Expand Up @@ -47,10 +47,6 @@ type Config struct {
}
}

SystemServices struct {
RelativePath string
}

Docker struct {
Socket string
Core struct {
Expand All @@ -74,7 +70,6 @@ func New() (*Config, error) {
c.Core.Image = "mesg/core:" + strings.Split(version.Version, " ")[0]
c.Core.Name = "core"
c.Core.Path = filepath.Join(home, ".mesg")
c.SystemServices.RelativePath = "systemservices"
c.Core.Database.ServiceRelativePath = filepath.Join("database", "services")
c.Core.Database.ExecutionRelativePath = filepath.Join("database", "executions")
c.Docker.Core.Path = "/mesg"
Expand Down
1 change: 0 additions & 1 deletion config/config_test.go
Expand Up @@ -22,7 +22,6 @@ func TestDefaultValue(t *testing.T) {
require.Equal(t, filepath.Join("database", "services"), c.Core.Database.ServiceRelativePath)
require.Equal(t, filepath.Join("database", "executions"), c.Core.Database.ExecutionRelativePath)
require.Equal(t, "core", c.Core.Name)
require.Equal(t, "systemservices", c.SystemServices.RelativePath)
require.Equal(t, "/mesg", c.Docker.Core.Path)
require.Equal(t, "/var/run/docker.sock", c.Docker.Socket)
require.True(t, strings.HasPrefix(c.Core.Image, "mesg/core:"))
Expand Down
12 changes: 2 additions & 10 deletions core/main.go
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/mesg-foundation/core/database"
"github.com/mesg-foundation/core/interface/grpc"
"github.com/mesg-foundation/core/logger"
"github.com/mesg-foundation/core/systemservices"
"github.com/mesg-foundation/core/systemservices/deployer"
"github.com/mesg-foundation/core/version"
"github.com/mesg-foundation/core/x/xsignal"
"github.com/sirupsen/logrus"
Expand All @@ -30,20 +28,14 @@ func initGRPCServer(c *config.Config) (*grpc.Server, error) {
}

// init api.
ss := systemservices.New()
a, err := api.New(db, execDB, ss)
a, err := api.New(db, execDB)
if err != nil {
return nil, err
}

// init system services.
systemServicesPath := filepath.Join(c.Core.Path, c.SystemServices.RelativePath)
d := deployer.New(a, systemServicesPath, ss)
if err := d.Deploy(systemservices.SystemServicesList); err != nil {
return nil, err
}

return grpc.New(c.Server.Address, a, ss), nil
return grpc.New(c.Server.Address, a), nil
}

func main() {
Expand Down
6 changes: 0 additions & 6 deletions daemon/daemon.go
Expand Up @@ -2,7 +2,6 @@ package daemon

import (
"io"
"path/filepath"

"github.com/mesg-foundation/core/config"
"github.com/mesg-foundation/core/container"
Expand Down Expand Up @@ -74,11 +73,6 @@ func (d *ContainerDaemon) buildServiceOptions(sharedNetworkID string) container.
Target: d.cfg.Docker.Core.Path,
Bind: true,
},
{
Source: filepath.Join(d.cfg.Core.Path, d.cfg.SystemServices.RelativePath),
Target: filepath.Join(d.cfg.Docker.Core.Path, d.cfg.SystemServices.RelativePath),
Bind: true,
},
},
Ports: []container.Port{
{
Expand Down
2 changes: 0 additions & 2 deletions dev-core
Expand Up @@ -36,9 +36,7 @@ else
fi

# create a symlink for system services.
rm -rf "$HOME/.mesg/systemservices"
mkdir -p "$HOME/.mesg/"
ln -s "$DIR/systemservices/sources" "$HOME/.mesg/systemservices"

echo "build mesg/core image"
if [[ ! $BINCACHED ]] || [[ ! $DOCKERCACHED ]]; then
Expand Down
6 changes: 2 additions & 4 deletions interface/grpc/core/core_test.go
Expand Up @@ -6,8 +6,6 @@ import (
"path/filepath"
"testing"

"github.com/mesg-foundation/core/systemservices"

"github.com/docker/docker/pkg/archive"
"github.com/mesg-foundation/core/api"
"github.com/mesg-foundation/core/container"
Expand All @@ -33,10 +31,10 @@ func newServerWithContainer(t *testing.T, c container.Container) (*Server, func(
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

a, err := api.New(db, execDB, systemservices.New(), api.ContainerOption(c))
a, err := api.New(db, execDB, api.ContainerOption(c))
require.NoError(t, err)

server := NewServer(a, nil)
server := NewServer(a)

closer := func() {
db.Close()
Expand Down
6 changes: 2 additions & 4 deletions interface/grpc/core/type.go
Expand Up @@ -2,16 +2,14 @@ package core

import (
"github.com/mesg-foundation/core/api"
"github.com/mesg-foundation/core/systemservices"
)

// Server is the type to aggregate all the APIs.
type Server struct {
api *api.API
ss *systemservices.SystemServices
}

// NewServer creates a new Server.
func NewServer(api *api.API, ss *systemservices.SystemServices) *Server {
return &Server{api: api, ss: ss}
func NewServer(api *api.API) *Server {
return &Server{api: api}
}
7 changes: 2 additions & 5 deletions interface/grpc/server.go
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/mesg-foundation/core/interface/grpc/service"
"github.com/mesg-foundation/core/protobuf/coreapi"
"github.com/mesg-foundation/core/protobuf/serviceapi"
"github.com/mesg-foundation/core/systemservices"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
Expand All @@ -20,7 +19,6 @@ import (
// Server contains the server config.
type Server struct {
api *api.API
ss *systemservices.SystemServices

instance *grpc.Server
closed bool
Expand All @@ -31,10 +29,9 @@ type Server struct {
}

// New returns a new gRPC server.
func New(address string, api *api.API, ss *systemservices.SystemServices) *Server {
func New(address string, api *api.API) *Server {
return &Server{
api: api,
ss: ss,
address: address,
network: "tcp",
}
Expand Down Expand Up @@ -96,7 +93,7 @@ func (s *Server) Close() {

// register all server
func (s *Server) register() error {
coreServer := core.NewServer(s.api, s.ss)
coreServer := core.NewServer(s.api)
serviceServer := service.NewServer(s.api)

serviceapi.RegisterServiceServer(s.instance, serviceServer)
Expand Down
4 changes: 2 additions & 2 deletions interface/grpc/server_test.go
Expand Up @@ -12,7 +12,7 @@ const (
)

func TestServerServe(t *testing.T) {
s := New("localhost:50052", nil, nil)
s := New("localhost:50052", nil)
go func() {
time.Sleep(waitForServe)
s.Close()
Expand All @@ -32,7 +32,7 @@ func TestServerServeNoAddress(t *testing.T) {
}

func TestServerListenAfterClose(t *testing.T) {
s := New("localhost:50052", nil, nil)
s := New("localhost:50052", nil)
go s.Serve()
time.Sleep(waitForServe)
s.Close()
Expand Down
3 changes: 1 addition & 2 deletions interface/grpc/service/service_test.go
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/docker/docker/pkg/archive"
"github.com/mesg-foundation/core/api"
"github.com/mesg-foundation/core/database"
"github.com/mesg-foundation/core/systemservices"
"github.com/stretchr/testify/require"
)

Expand All @@ -31,7 +30,7 @@ func newServer(t *testing.T) (*Server, func()) {
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

a, err := api.New(db, execDB, systemservices.New())
a, err := api.New(db, execDB)
require.NoError(t, err)

server := NewServer(a)
Expand Down

0 comments on commit 89a8731

Please sign in to comment.