Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEM-62 daemon: implement mvp functionality #6

Merged
merged 41 commits into from Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9c259be
daemon: implement basic endpoints for network start and stop
bobheadxi Nov 5, 2018
234b4e2
config: add newline at end of generated config
bobheadxi Nov 5, 2018
4ac7746
config: fix erroneous doc
bobheadxi Nov 5, 2018
0ba363d
chore: add workaround for go mod behaviour with go get counterfeiter
bobheadxi Nov 5, 2018
f322f44
config: add DataDirectory configuration for ipfs node data
bobheadxi Nov 5, 2018
541273e
cmd: streamline cmd code, add documentation on usage
bobheadxi Nov 5, 2018
c057346
chore: download test docker-compose into tmp
bobheadxi Nov 5, 2018
0edade8
config: bump default IPFS version
bobheadxi Nov 5, 2018
6f92f6e
cmd: add version
bobheadxi Nov 5, 2018
a890e01
chore: add automated release build and uploading
bobheadxi Nov 5, 2018
47fc200
orchestrator: rename host to address
bobheadxi Nov 5, 2018
f72a92a
cmd: improve help text
bobheadxi Nov 5, 2018
e33c346
ctl: add prototype CLI controller
bobheadxi Nov 5, 2018
597f62f
cmd: improve help text
bobheadxi Nov 5, 2018
bac8d02
config: rename ssl to tls
bobheadxi Nov 5, 2018
b71492e
cmd: improve help text for unknown commands
bobheadxi Nov 5, 2018
bd57aed
chore: bump version of go-ipfs used in CI
bobheadxi Nov 5, 2018
807c25c
config: add example configuration and make script
bobheadxi Nov 5, 2018
54608eb
ipfs: resolve absolute path for data directories
bobheadxi Nov 5, 2018
de2657f
config: update path to test configuration file
bobheadxi Nov 5, 2018
9815805
ipfs: implement prototype node stats retriever
bobheadxi Nov 5, 2018
5bee7fd
ipfs: create files and directories with permissions from config
bobheadxi Nov 5, 2018
939e369
make: build before config gen
bobheadxi Nov 5, 2018
f9e9854
config: use string for modeperm
bobheadxi Nov 5, 2018
60eab29
config: reduce generated indentation
bobheadxi Nov 5, 2018
fd195e9
ipfs: provide ModePerm in constructor test
bobheadxi Nov 5, 2018
8eef8a0
orchestrator: prototype networkstats endpoint
bobheadxi Nov 5, 2018
d3f8501
orchestrator: run migrations in dev mode
bobheadxi Nov 6, 2018
0b45c8d
cmd: improve ctl behaviour
bobheadxi Nov 6, 2018
1b18e71
chore: run tests under sudo
bobheadxi Nov 6, 2018
da00dc9
ipfs: expose ports explicitly on tcp protocol
bobheadxi Nov 6, 2018
285a90d
ipfs: improve logging, add duration trace
bobheadxi Nov 6, 2018
aba1c4f
chore: set path explicitly
bobheadxi Nov 6, 2018
b6890df
docs: add ctl documentation
bobheadxi Nov 6, 2018
9a90df3
orchestrator: add tests for network status
bobheadxi Nov 6, 2018
958cf07
chore: reduce patch target
bobheadxi Nov 6, 2018
92abffc
daemon: improve shutdown management
bobheadxi Nov 6, 2018
c061d43
registry: set api port registry to listen on all interfaces
bobheadxi Nov 7, 2018
b0164b3
docs: add package documentation
bobheadxi Nov 7, 2018
fd0a55f
ipfs: improve CreateNode failure case logging and cleanup
bobheadxi Nov 7, 2018
9f8658d
ipfs: remove container by name if container fails to start
bobheadxi Nov 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@ ipfs-orchestrator

# generated
/config.json
/release

# test
tmp
Expand Down
16 changes: 16 additions & 0 deletions .scripts/release.sh
@@ -0,0 +1,16 @@
#! /bin/bash

export GO111MODULE=on

go get -u github.com/mitchellh/gox
go mod tidy

RELEASE=$(git describe --tags --always)
TARGETS="linux/amd64 linux/386 linux/arm darwin/amd64 windows/amd64"

mkdir -p release

gox -output="release/ipfs-orchestrator-$RELEASE-{{.OS}}-{{.Arch}}" \
-ldflags "-X main.Version=$RELEASE" \
-osarch="$TARGETS" \
.
23 changes: 19 additions & 4 deletions .travis.yml
@@ -1,4 +1,5 @@
language: go
sudo: required
go:
- "1.11"
services:
Expand All @@ -9,7 +10,7 @@ env: GO111MODULE=on
install:
- go get -u golang.org/x/lint/golint
- go mod download
- docker pull ipfs/go-ipfs:v0.4.17
- docker pull ipfs/go-ipfs:v0.4.18

before_script:
- go vet ./...
Expand All @@ -20,10 +21,24 @@ before_script:
script:
- diff -u <(echo -n) <(gofmt -d -s `find . -type f -name '*.go' -not -path "./vendor/*"`)
- diff -u <(echo -n) <(golint `go list ./... | grep -v /vendor/`)
- go test -race -short -coverprofile=coverage.txt ./...
- sudo -E env "PATH=$PATH" go test -race -short -coverprofile=coverage.txt ./...

after_success:
- bash <(curl -s https://codecov.io/bash)

notifications:
email: false
before_deploy:
- make release

deploy:
provider: releases
skip_cleanup: true
api_key:
secure: OkfTO/W+l2Gdr1Y9a/tbOl9ymVJuUTe/JHFVPJ3rPlvvEb/Hc2EMCQ1J28GCKCUQJu1rygBgvOEMlVLnN7rSQKcSfJ3uLGcFg7SbxbwW0d6ZegCCfoqzKDzmpGXvcsPILyj0o56aOuBZkSNvjgLMTM+bbIUA0KxFg4XEPIdvYvPSDpDNMww+uv/MTtk+qOuyiAJhNgdkoMZoB1HjXKP02wWZEux10Cs2+V18XZ5jIH6oRnVXH2Km8YJ1xT4c0NtxHSXo7kYGwTtq+280F3xppXWLRuWDsc4lal8wgD1FTh/jmIauAcoLbhkGYH07Tlqgn54JkNplMkA6nzzGQmba/jlyldblyRXKN7Tpi76Xn2c/TEucdkEXkPthpJgiCKjCup7ywPuA4mLv70QJ9z0JoOil+LBoht2u+f4oP/pds+hHnUDqUQrVb/RKMSPUKefOxGTtjZaqdmZft21CbwCzkvDvBpibN7ZXs1FLVSqdbIevAe86JkfVj0jl9TxhFq34h/VLq2C9qVWVEXbQU2T2C97XBwBe3PqIn97W6kN/K8mA+mAOKvkGxkDGla1EwEInxEJ2h+qJNECHorGebDj3FjoW2nqNfXJEIQ8IVSgDS3FUTRZ52pPEsiI6gGVEHxBZKC5/ZkFUD4PumyjCzBfKOwgG54dJ6iZy6AxPU3r81L4=
file_glob: true
file: release/ipfs-orchestrator-*
on:
tags: true
repo: RTradeLtd/ipfs-orchestrator

notifications:
email: false
23 changes: 17 additions & 6 deletions Makefile
@@ -1,23 +1,30 @@
GO=env GO111MODULE=on go
GONOMOD=env GO111MODULE=off go
IPFSCONTAINERS=`docker ps -a -q --filter="name=ipfs-*"`
TESTCOMPOSE=https://raw.githubusercontent.com/RTradeLtd/Temporal/V2/test/docker-compose.yml
COMPOSECOMMAND=env ADDR_NODE1=1 ADDR_NODE2=2 docker-compose -f test/docker-compose.yml
COMPOSECOMMAND=env ADDR_NODE1=1 ADDR_NODE2=2 docker-compose -f tmp/docker-compose.yml
VERSION=`git describe --always --tags`

all: deps check build

.PHONY: build
build:
go build
go build -ldflags "-X main.Version=$(VERSION)"

.PHONY: install
install: deps
go install
go install -ldflags "-X main.Version=$(VERSION)"

.PHONY: config
config: build
./ipfs-orchestrator -config ./config.example.json init

# Install dependencies
.PHONY: deps
deps:
$(GO) mod vendor
go get -u github.com/maxbrunsfeld/counterfeiter
$(GO) get github.com/maxbrunsfeld/counterfeiter
$(GO) mod tidy

# Run simple checks
.PHONY: check
Expand All @@ -32,8 +39,8 @@ test:

.PHONY: testenv
testenv:
mkdir -p test
curl $(TESTCOMPOSE) --output test/docker-compose.yml
mkdir -p tmp
curl $(TESTCOMPOSE) --output tmp/docker-compose.yml
$(COMPOSECOMMAND) up -d postgres

# Generate protobuf code from definitions
Expand All @@ -53,3 +60,7 @@ clean:
mock:
counterfeiter -o ./ipfs/mock/ipfs.mock.go \
./ipfs/ipfs.go NodeClient

.PHONY: release
release:
bash .scripts/release.sh
29 changes: 27 additions & 2 deletions README.md
Expand Up @@ -11,7 +11,19 @@ distributed and decentralized storage technologies.

## Installation and Usage

Coming soon!
```bash
$> go get -u github.com/RTradeLtd/ipfs-orchestrator
```

Releases are also be available from the
[Releases](https://github.com/RTradeLtd/ipfs-orchestrator/releases) page.

```bash
$> ipfs-orchestrator init
$> ipfs-orchestrator daemon --address $MY_HOST
```

Further documentation is available via `ipfs-orchestrator --help`.

## Development

Expand All @@ -27,7 +39,7 @@ $> go get github.com/RTradeLtd/ipfs-orchestrator
Dependencies can be installed using the provided Makefile:

```bash
$> make # installs dependencies and build binary
$> make # installs dependencies and builds a binary
```

### Testing
Expand All @@ -39,3 +51,16 @@ $> make test
```

You can remove leftover assets using `make clean`.

### ctl

An experimental, lightweight controller for the gRPC API is available via the
`ipfs-orchestrator ctl` command, which exposes a client via the
[ctl](https://github.com/bobheadxi/ctl) library.

```bash
$> ipfs-orchestrator ctl help
$> ipfs-orchestrator -dev ctl StartNetwork Network=test-network
$> ipfs-orchestrator -dev ctl NetworkStats Network=test-network
$> ipfs-orchestrator -dev ctl StopNetwork Network=test-network
```
50 changes: 50 additions & 0 deletions client/client.go
@@ -0,0 +1,50 @@
package client

import (
"fmt"

"github.com/RTradeLtd/grpc/utils"
ipfs_orchestrator "github.com/RTradeLtd/ipfs-orchestrator/protobuf"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

"github.com/RTradeLtd/ipfs-orchestrator/config"
)

// IPFSOrchestratorClient is a lighweight container for the orchestrator's
// gRPC API client
type IPFSOrchestratorClient struct {
ipfs_orchestrator.ServiceClient
grpc *grpc.ClientConn
}

// New instantiates a new orchestrator API client
func New(opts config.API, devMode bool) (*IPFSOrchestratorClient, error) {
c := &IPFSOrchestratorClient{}
// set up parameters for core conn
dialOpts := make([]grpc.DialOption, 0)
if opts.TLS.CertPath != "" {
creds, err := credentials.NewClientTLSFromFile(opts.TLS.CertPath, "")
if err != nil {
return nil, fmt.Errorf("could not load tls cert: %s", err)
}
dialOpts = append(dialOpts,
grpc.WithTransportCredentials(creds),
grpc.WithPerRPCCredentials(utils.NewCredentials(opts.Key, !devMode)))
} else {
dialOpts = append(dialOpts, grpc.WithInsecure())
}

// connect to orchestrator
var err error
c.grpc, err = grpc.Dial(opts.Host+":"+opts.Port, dialOpts...)
if err != nil {
return nil, fmt.Errorf("failed to connect to core service: %s", err.Error())
}
c.ServiceClient = ipfs_orchestrator.NewServiceClient(c.grpc)
return c, nil
}

// Close shuts down the client's gRPC connection
func (i *IPFSOrchestratorClient) Close() { i.grpc.Close() }
3 changes: 3 additions & 0 deletions client/doc.go
@@ -0,0 +1,3 @@
// Package client provides a simple wrapper around the generated gRPC client for
// the ipfs-orchestrator
package client
3 changes: 3 additions & 0 deletions codecov.yml
Expand Up @@ -6,3 +6,6 @@ coverage:
project:
default:
threshold: 1
patch:
default:
target: 50%
34 changes: 34 additions & 0 deletions config.example.json
@@ -0,0 +1,34 @@
{
"ipfs": {
"version": "v0.4.18",
"data_dir": "/",
"perm_mode": "0700",
"ports": {
"swarm": [
"4001-5000"
],
"api": [
"5001-6000"
],
"gateway": [
"8001-9000"
]
}
},
"api": {
"host": "127.0.0.1",
"port": "9111",
"key": "",
"tls": {
"cert": "",
"key": ""
}
},
"postgres": {
"name": "",
"url": "127.0.0.1",
"port": "5432",
"username": "",
"password": ""
}
}
22 changes: 15 additions & 7 deletions config/config.go
Expand Up @@ -11,7 +11,7 @@ import (
)

// DefaultIPFSVersion declares the current default version of go-ipfs to use
const DefaultIPFSVersion = "v0.4.17"
const DefaultIPFSVersion = "v0.4.18"

// IPFSOrchestratorConfig configures the orchestration daemon
type IPFSOrchestratorConfig struct {
Expand All @@ -22,8 +22,10 @@ type IPFSOrchestratorConfig struct {

// IPFS configures settings relevant to IPFS nodes
type IPFS struct {
Version string `json:"version"`
Ports `json:"ports"`
Version string `json:"version"`
DataDirectory string `json:"data_dir"`
ModePerm string `json:"perm_mode"`
Ports `json:"ports"`
}

// Ports declares port-range configuration for IPFS nodes. Elements of each
Expand All @@ -39,7 +41,7 @@ type API struct {
Host string `json:"host"`
Port string `json:"port"`
Key string `json:"key"`
TLS `json:"ssl"`
TLS `json:"tls"`
}

// TLS declares HTTPS configuration for the daemon's gRPC API
Expand Down Expand Up @@ -73,7 +75,7 @@ func LoadConfig(configPath string) (IPFSOrchestratorConfig, error) {
return cfg, nil
}

// GenerateConfig writes a empty TemporalConfig template to given filepath
// GenerateConfig writes an empty orchestrator config template to given filepath
func GenerateConfig(configPath string) error {
template := &IPFSOrchestratorConfig{}
template.setDefaults()
Expand All @@ -83,16 +85,22 @@ func GenerateConfig(configPath string) error {
}

var pretty bytes.Buffer
if err = json.Indent(&pretty, b, "", "\t"); err != nil {
if err = json.Indent(&pretty, b, "", " "); err != nil {
return err
}
return ioutil.WriteFile(configPath, pretty.Bytes(), os.ModePerm)
return ioutil.WriteFile(configPath, append(pretty.Bytes(), '\n'), os.ModePerm)
}

func (c *IPFSOrchestratorConfig) setDefaults() {
if c.IPFS.Version == "" {
c.IPFS.Version = DefaultIPFSVersion
}
if c.IPFS.DataDirectory == "" {
c.IPFS.DataDirectory = "/"
}
if c.IPFS.ModePerm == "" {
c.IPFS.ModePerm = "0700"
}
if c.API.Host == "" {
c.API.Host = "127.0.0.1"
}
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Expand Up @@ -17,7 +17,7 @@ func TestLoadConfig(t *testing.T) {
}{
{"invalid path", args{""}, IPFSOrchestratorConfig{}, true},
{"invalid file", args{"./config.go"}, IPFSOrchestratorConfig{}, true},
{"valid dev config", args{"../dev/config.json"}, New(), false},
{"valid dev config", args{"../config.example.json"}, New(), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions config/doc.go
@@ -0,0 +1,2 @@
// Package config provides configuration definitions for the ipfs-orchestrator
package config