diff --git a/cli/commands/start.go b/cli/commands/start.go index b15cfcc..bef8e92 100644 --- a/cli/commands/start.go +++ b/cli/commands/start.go @@ -7,7 +7,6 @@ import ( "github.com/CityOfZion/neo-local/cli/services" "github.com/CityOfZion/neo-local/cli/stack" - "github.com/fatih/color" "github.com/urfave/cli" "github.com/docker/docker/api/types" @@ -38,21 +37,21 @@ func (s Start) ToCommand() cli.Command { func (s Start) action() func(c *cli.Context) error { return func(c *cli.Context) error { - verbose := c.Bool("v") - if verbose { - log.Println("Verbose logging is enabled") - } - - saveState := c.Bool("ss") - if saveState { - log.Println("Save state is enabled, existing environment will not be destroyed") - } else { - log.Printf( - "Save state is %s, existing environment will be %s", - color.RedString("disabled"), - color.RedString("destroyed"), - ) - } + // verbose := c.Bool("v") + // if verbose { + // log.Println("Verbose logging is enabled") + // } + + // saveState := c.Bool("ss") + // if saveState { + // log.Println("Save state is enabled, existing environment will not be destroyed") + // } else { + // log.Printf( + // "Save state is %s, existing environment will be %s", + // color.RedString("disabled"), + // color.RedString("destroyed"), + // ) + // } ctx := context.Background() cli, err := client.NewEnvClient() @@ -70,11 +69,13 @@ func (s Start) action() func(c *cli.Context) error { return err } - services := stack.Services() - - for _, service := range services { + for _, service := range stack.Services() { resp, err := cli.ContainerCreate( - ctx, service.Config(), nil, nil, service.ContainerName(), + ctx, + service.Config(), + service.HostConfig, + nil, + service.ContainerName(), ) if err != nil { return err @@ -94,13 +95,17 @@ func (s Start) action() func(c *cli.Context) error { func (s Start) flags() []cli.Flag { return []cli.Flag{ - cli.BoolFlag{ - Name: "save-state, ss", - Usage: "Any state in the existing environment will be saved (default: false)", - }, - cli.BoolFlag{ - Name: "verbose, v", - Usage: "Enable verbose logging (default: false)", - }, + // cli.BoolFlag{ + // Name: "pull-images, pi", + // Usage: "Pull the latest Docker images (default: true)", + // }, + // cli.BoolFlag{ + // Name: "save-state, ss", + // Usage: "Any state in the existing environment will be saved (default: false)", + // }, + // cli.BoolFlag{ + // Name: "verbose, v", + // Usage: "Enable verbose logging (default: false)", + // }, } } diff --git a/cli/services/docker.go b/cli/services/docker.go index 37866c3..a91369e 100644 --- a/cli/services/docker.go +++ b/cli/services/docker.go @@ -5,6 +5,7 @@ import ( "log" "github.com/CityOfZion/neo-local/cli/logger" + "github.com/CityOfZion/neo-local/cli/stack" "github.com/docker/docker/api/types" "github.com/docker/docker/client" "golang.org/x/net/context" @@ -25,14 +26,20 @@ func CheckDockerRunning(ctx context.Context, cli *client.Client) bool { func PullDockerImages(ctx context.Context, cli *client.Client) error { log.Println("Pulling Docker images") - for _, imageName := range dockerImageNames() { - prefix := fmt.Sprintf("↪ %s", imageName) + for _, service := range stack.Services() { + prefix := fmt.Sprintf("↪ %s", service.ImageName()) s := logger.NewSpinner(prefix) s.Start() - reader, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{}) + reader, err := cli.ImagePull( + ctx, service.ImageName(), types.ImagePullOptions{}, + ) if err != nil { - return fmt.Errorf("Error when pulling Docker image '%s': %s", imageName, err) + return fmt.Errorf( + "Error when pulling Docker image '%s': %s", + service.ImageName(), + err, + ) } defer reader.Close() @@ -40,15 +47,4 @@ func PullDockerImages(ctx context.Context, cli *client.Client) error { } return nil -} - -func dockerImageNames() []string { - return []string{ - "cityofzion/neo-local-faucet:latest", - "cityofzion/neo-privatenet:2.7.6", - "cityofzion/neo-python:v0.8.1", - "library/postgres:10.5", - "registry.gitlab.com/cityofzion/neo-scan/api:latest", - "registry.gitlab.com/cityofzion/neo-scan/sync:latest", - } -} +} \ No newline at end of file diff --git a/cli/stack/faucet.go b/cli/stack/faucet.go new file mode 100644 index 0000000..ba930df --- /dev/null +++ b/cli/stack/faucet.go @@ -0,0 +1,36 @@ +package stack + +import ( + "github.com/docker/docker/api/types/container" + "github.com/docker/go-connections/nat" +) + +// NewFaucet creates a new service for the cityofzion/neo-local-faucet image. +func NewFaucet() Service { + return Service{ + Author: "cityofzion", + ContainerConfig: &container.Config{ + Env: []string{ + "NEOSCAN=neo-scan-api:4000", + }, + ExposedPorts: map[nat.Port]struct{}{ + "4002/tcp": {}, + }, + }, + HostConfig: &container.HostConfig{ + // Links: []string{"neo-scan-api:4000"}, TODO: Add when container exists for linking. + PortBindings: map[nat.Port][]nat.PortBinding{ + "4002/tcp": { + { + HostIP: "0.0.0.0", + HostPort: "4002", + }, + }, + }, + Privileged: false, + PublishAllPorts: true, + }, + Image: "neo-local-faucet", + Tag: "latest", + } +} diff --git a/cli/stack/postgres.go b/cli/stack/postgres.go index b589f9a..ded1648 100644 --- a/cli/stack/postgres.go +++ b/cli/stack/postgres.go @@ -5,10 +5,11 @@ import ( "github.com/docker/go-connections/nat" ) -// NewPostgres creates a new service for the Postgres container. +// NewPostgres creates a new service for the library/postgres container. func NewPostgres() Service { return Service{ - ContainerConfig: container.Config{ + Author: "library", + ContainerConfig: &container.Config{ Env: []string{ "POSTGRES_DB=neoscan_prodv", "POSTGRES_PASSWORD=postgres", @@ -16,7 +17,8 @@ func NewPostgres() Service { }, ExposedPorts: map[nat.Port]struct{}{"5432/tcp": {}}, }, - Image: "library/postgres", - Tag: "10.5", + HostConfig: nil, + Image: "postgres", + Tag: "10.5", } } diff --git a/cli/stack/service.go b/cli/stack/service.go index 02c8cf3..023b28b 100644 --- a/cli/stack/service.go +++ b/cli/stack/service.go @@ -9,7 +9,9 @@ import ( type ( // Service defines a Docker container to run within the stack. Service struct { - ContainerConfig container.Config + Author string + ContainerConfig *container.Config + HostConfig *container.HostConfig Image string Tag string } @@ -19,7 +21,7 @@ type ( func (s Service) Config() *container.Config { config := s.ContainerConfig config.Image = s.ImageName() - return &config + return config } // ContainerName is the Docker container name. @@ -29,12 +31,5 @@ func (s Service) ContainerName() string { // ImageName is the full Docker image name for the service, including the tag. func (s Service) ImageName() string { - return fmt.Sprintf("%s:%s", s.Image, s.Tag) -} - -// Services returns all the services within the Docker stack. -func Services() []Service { - return []Service{ - NewPostgres(), - } + return fmt.Sprintf("%s/%s:%s", s.Author, s.Image, s.Tag) } diff --git a/cli/stack/services.go b/cli/stack/services.go new file mode 100644 index 0000000..37f6008 --- /dev/null +++ b/cli/stack/services.go @@ -0,0 +1,9 @@ +package stack + +// Services returns all the services within the Docker stack. +func Services() []Service { + return []Service{ + NewFaucet(), + NewPostgres(), + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 664f67a..beb0068 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -104,4 +104,4 @@ services: POSTGRES_USER: postgres expose: - 5432 - image: postgres:10.5 + image: library/postgres:10.5