Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d33dcbb
feat: interactive setup
Maith8Ae Feb 18, 2021
3960911
add --interactive option
Maith8Ae Feb 26, 2021
8c87633
add console
Maith8Ae Feb 26, 2021
982db89
add .backup-unset and implement interactive create/unlock
Maith8Ae Mar 1, 2021
a054bd6
update opendex.sh
Maith8Ae Mar 2, 2021
770715b
fix: opendex-launcher version match
Maith8Ae Mar 3, 2021
3d1684c
fix: macOS OPENDEX_DOCKER_HOME path
Maith8Ae Mar 3, 2021
34dab3c
chore: add warming up
Maith8Ae Mar 3, 2021
25362c2
fix: opendex-launcher version match
Maith8Ae Mar 3, 2021
a75b2f7
chore: refine help text
Maith8Ae Mar 3, 2021
ccceadb
chore: refine launcher help text
Maith8Ae Mar 3, 2021
2de4784
fix: gnu tar cannot extract zip
Maith8Ae Mar 4, 2021
b7bd205
fix: use bash instead of sh
Maith8Ae Mar 4, 2021
efb6c1a
fix: use sh
Maith8Ae Mar 4, 2021
ed39fba
fix: unzip without question
Maith8Ae Mar 4, 2021
fc6c625
fix: read
Maith8Ae Mar 4, 2021
b848fea
chore: add commit hash to the version
Maith8Ae Mar 4, 2021
d19f26e
chore: update launcher version
Maith8Ae Mar 4, 2021
57a164b
use gunzip on linux
Maith8Ae Mar 10, 2021
9700fbe
print table
Maith8Ae Mar 10, 2021
16c454f
fix table
Maith8Ae Mar 10, 2021
b4d9a95
refine container name grepping
Maith8Ae Mar 12, 2021
e33311b
reorder create/unlock functions
Maith8Ae Mar 15, 2021
4ff421b
implement status command
Maith8Ae Mar 17, 2021
85a4404
fix "Container missing"
Maith8Ae Mar 17, 2021
d74b188
bypass unlock error
Maith8Ae Mar 17, 2021
7f56faa
chdir before cleanup
Maith8Ae Mar 17, 2021
8cb9e85
hide "Still waiting..." when light clients syncing
Maith8Ae Mar 17, 2021
797eb20
update banner
Maith8Ae Mar 17, 2021
8c3c55c
add "loading opendex console"
Maith8Ae Mar 17, 2021
2cce34c
show "starting..." when opendexd getinfo got "no connection established"
Maith8Ae Mar 17, 2021
e7cdfdb
replace tabs with spaces in banner
Maith8Ae Mar 17, 2021
4f32ff7
use opendex-launcher down in console
Maith8Ae Mar 17, 2021
9e61060
fix "type not a pointer: string"
Maith8Ae Mar 22, 2021
fb806f3
trim spaces around choice
Maith8Ae Mar 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
name: Build binary launcher
strategy:
matrix:
go-version: [ 1.15.x ]
go-version: [ 1.16.x ]
os: [ linux, darwin, windows ]
arch: [ amd64, arm64 ]
exclude:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
name: Build artifacts
strategy:
matrix:
go-version: [ 1.15.x ]
go-version: [ 1.16.x ]
os: [ linux, darwin, windows ]
arch: [ amd64, arm64 ]
exclude:
Expand Down
22 changes: 21 additions & 1 deletion launcher/cmd/console.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
package cmd

// TODO console
import (
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(consoleCmd)
}

var consoleCmd = &cobra.Command{
Use: "console",
Short: "Start the console",
PreRunE: func(cmd *cobra.Command, args []string) error {
return launcher.Apply()
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := newContext()
defer cancel()
return launcher.StartConsole(ctx)
},
}

22 changes: 0 additions & 22 deletions launcher/cmd/restart.go

This file was deleted.

13 changes: 9 additions & 4 deletions launcher/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ import (
var (
rootCmd = &cobra.Command{
Use: "launcher",
Short: fmt.Sprintf("XUD environment launcher"),
Short: fmt.Sprintf("OpenDEX environment launcher"),
SilenceUsage: true,
SilenceErrors: true,
}
launcher *core.Launcher
)

func init() {
var err error

if err := os.Setenv("DOCKER_API_VERSION", "1.40"); err != nil {
panic(err)
}
var err error
launcher, err = core.NewLauncher()
if err != nil {
launcher = core.NewLauncher()
if err := launcher.Init(); err != nil {
panic(err)
}
err = launcher.AddServiceFlags(rootCmd)
Expand Down Expand Up @@ -69,3 +70,7 @@ func newContext() (context.Context, func()) {

return ctx, _cancel
}

func CommonPreRunE(cmd *cobra.Command, args []string) error {
return launcher.Apply()
}
6 changes: 3 additions & 3 deletions launcher/cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type SetupOptions struct {
NoPull bool
Interactive bool
}

var (
Expand All @@ -15,15 +16,14 @@ var (

func init() {
setupCmd.PersistentFlags().BoolVar(&setupOpts.NoPull, "nopull", false, "don't pull images")
setupCmd.PersistentFlags().BoolVarP(&setupOpts.Interactive, "interactive", "i", false, "interactive setup")
rootCmd.AddCommand(setupCmd)
}

var setupCmd = &cobra.Command{
Use: "setup",
Short: "Set up OpenDEX environment",
PreRunE: func(cmd *cobra.Command, args []string) error {
return launcher.Apply()
},
PreRunE: CommonPreRunE,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := newContext()
defer cancel()
Expand Down
3 changes: 2 additions & 1 deletion launcher/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var startCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := newContext()
defer cancel()
return launcher.Start(ctx)
// FIXME enable start multiple services
return launcher.Start(ctx, args[1])
},
}
101 changes: 93 additions & 8 deletions launcher/cmd/status.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,117 @@
package cmd

import (
"errors"
"fmt"
"github.com/opendexnetwork/opendex-docker/launcher/utils"
"github.com/spf13/cobra"
"os"
"os/exec"
"strings"
)

func init() {
rootCmd.AddCommand(statusCmd)
}

type StatusUpdate struct {
Service string
Status string
}

var statusCmd = &cobra.Command{
Use: "status",
Short: "Get service status",
PreRunE: func(cmd *cobra.Command, args []string) error {
return launcher.Apply()
},
PreRunE: CommonPreRunE,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := newContext()
defer cancel()
if len(args) < 1 {
return errors.New("service name required")

// Checking Docker
err := utils.Run(ctx, exec.Command("docker", "info"))
if err != nil {
return err
}
status, err := launcher.Status(ctx, args[0])

// Changing working directory
wd, err := os.Getwd()
if err != nil {
return err
}
fmt.Println(status)
defer os.Chdir(wd)

if err := os.Chdir(launcher.NetworkDir); err != nil {
return err
}

t := utils.SimpleTable{
Columns: []utils.TableColumn{
{
ID: "service",
Display: "SERVICE",
},
{
ID: "status",
Display: "STATUS",
},
},
Records: []utils.TableRecord{},
}

var statusMap = make(map[string]string)

names := args
if len(names) == 0 {
names = launcher.Services.Keys()
}

for _, name := range names {
if ! launcher.HasService(name) {
return fmt.Errorf("no such service: %s", name)
}
statusMap[name] = ""
t.Records = append(t.Records, utils.TableRecord{
Fields: map[string]string{
"service": name,
"status": "",
},
})
}

updates := make(chan StatusUpdate)

for _, name_ := range names {
name := name_
go func() {
status, err := launcher.Status(ctx, name)
if err != nil {
if strings.HasPrefix(err.Error(), "Error:") {
status = err.Error()
} else {
status = "Error: " + err.Error()
}
updates <- StatusUpdate{Service: name, Status: status}
return
}
updates <- StatusUpdate{Service: name, Status: status}
}()
}

t.Print()

i := 0

for i < len(names) {
update := <-updates
//fmt.Println(i, update)
t.PrintUpdate(utils.TableRecord{
Fields: map[string]string{
"service": update.Service,
"status": update.Status,
},
})
i++
}

return nil
},
}
2 changes: 1 addition & 1 deletion launcher/core/backupto.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (t *Launcher) BackupTo(ctx context.Context, location string) error {
if err := t.Gen(ctx); err != nil {
return err
}
if err := t.upOpendexd(ctx); err != nil {
if err := t.Opendexd.Start(ctx); err != nil {
return err
}
return nil
Expand Down
33 changes: 15 additions & 18 deletions launcher/core/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import (

func (t *Launcher) stopService(ctx context.Context, name string) error {
t.Logger.Debugf("Stopping %s", name)
s, err := t.GetService(name)
if err != nil {
return err
}
s := t.GetService(name)
if err := s.Stop(ctx); err != nil {
if strings.Contains(err.Error(), "No such container") {
t.Logger.Debugf("Service %s stopped already", name)
Expand Down Expand Up @@ -50,19 +47,7 @@ func (t *Launcher) stopService(ctx context.Context, name string) error {
return nil
}

func (t *Launcher) Create(ctx context.Context) error {
return nil
}

func (t *Launcher) Start(ctx context.Context) error {
return nil
}

func (t *Launcher) Restart(ctx context.Context) error {
return nil
}

func (t *Launcher) Stop(ctx context.Context) error {
func (t *Launcher) Stop(ctx context.Context, services ...string) error {
if t.Network != types.Simnet {
if err := t.stopService(ctx, "boltz"); err != nil {
return err
Expand Down Expand Up @@ -145,7 +130,8 @@ func (t *Launcher) finalDown(ctx context.Context) error {
return fmt.Errorf("create docker client: %w", err)
}

for _, service := range t.ServicesOrder {
for _, name := range t.Services.Keys() {
service := t.Services.Get(name)
containerName := fmt.Sprintf("%s_%s_1", t.Network, service)
_, err := client.ContainerInspect(ctx, containerName)
if err != nil {
Expand Down Expand Up @@ -183,6 +169,17 @@ func (t *Launcher) finalDown(ctx context.Context) error {
}

func (t *Launcher) Cleanup(ctx context.Context) error {
// Changing working directory
wd, err := os.Getwd()
if err != nil {
return err
}
defer os.Chdir(wd)

if err := os.Chdir(t.NetworkDir); err != nil {
return err
}

// stop all running services
if err := t.Stop(ctx); err != nil {
return fmt.Errorf("stop: %w", err)
Expand Down
28 changes: 28 additions & 0 deletions launcher/core/collections/ordered_map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package collections

type OrderedMap struct {
m map[string]interface{}
keys []string
}

func NewOrderedMap() *OrderedMap {
return &OrderedMap{
m: make(map[string]interface{}),
keys: []string{},
}
}

func (t *OrderedMap) Get(key string) interface{} {
return t.m[key]
}

func (t *OrderedMap) Put(key string, value interface{}) {
if _, existed := t.m[key]; !existed {
t.keys = append(t.keys, key)
}
t.m[key] = value
}

func (t *OrderedMap) Keys() []string {
return t.keys
}
Loading