From 36f5b1619425c44dfb4db8e17974436e736cceb0 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Sat, 4 Apr 2015 10:03:31 -0700 Subject: [PATCH] Add option to disable startup of services --- config/types.go | 22 +++++++++++----------- docker/factory.go | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/config/types.go b/config/types.go index de6c931d..09c16b0d 100644 --- a/config/types.go +++ b/config/types.go @@ -47,17 +47,17 @@ type Config struct { CloudInit CloudInit `yaml:"cloud_init,omitempty"` Console ConsoleConfig `yaml:"console,omitempty"` Debug bool `yaml:"debug,omitempty"` - //Disable []string `yaml:"disable,omitempty"` - EnabledAddons []string `yaml:"enabled_addons,omitempty"` - Modules []string `yaml:"modules,omitempty"` - Network NetworkConfig `yaml:"network,omitempty"` - Ssh SshConfig `yaml:"ssh,omitempty"` - State StateConfig `yaml:"state,omitempty"` - SystemContainers map[string]*project.ServiceConfig `yaml:"system_containers,omitempty"` - SystemDocker DockerConfig `yaml:"system_docker,omitempty"` - Upgrade UpgradeConfig `yaml:"upgrade,omitempty"` - UserContainers []ContainerConfig `yaml:"user_containers,omitempty"` - UserDocker DockerConfig `yaml:"user_docker,omitempty"` + Disable []string `yaml:"disable,omitempty"` + EnabledAddons []string `yaml:"enabled_addons,omitempty"` + Modules []string `yaml:"modules,omitempty"` + Network NetworkConfig `yaml:"network,omitempty"` + Ssh SshConfig `yaml:"ssh,omitempty"` + State StateConfig `yaml:"state,omitempty"` + SystemContainers map[string]*project.ServiceConfig `yaml:"system_containers,omitempty"` + SystemDocker DockerConfig `yaml:"system_docker,omitempty"` + Upgrade UpgradeConfig `yaml:"upgrade,omitempty"` + UserContainers []ContainerConfig `yaml:"user_containers,omitempty"` + UserDocker DockerConfig `yaml:"user_docker,omitempty"` } type ConsoleConfig struct { diff --git a/docker/factory.go b/docker/factory.go index c9d76153..a00ef599 100644 --- a/docker/factory.go +++ b/docker/factory.go @@ -4,10 +4,12 @@ import ( log "github.com/Sirupsen/logrus" "github.com/rancherio/os/config" + "github.com/rancherio/os/util" "github.com/rancherio/rancher-compose/project" ) type ContainerFactory struct { + cfg *config.Config } type containerBasedService struct { @@ -18,11 +20,23 @@ type containerBasedService struct { cfg *config.Config } +func NewContainerFactory(cfg *config.Config) *ContainerFactory { + return &ContainerFactory{ + cfg: cfg, + } +} + func (c *containerBasedService) Up() error { container := c.container containerCfg := c.container.ContainerCfg - if containerCfg.CreateOnly { + create := containerCfg.CreateOnly + + if util.Contains(c.cfg.Disable, c.name) { + create = true + } + + if create { container.Create() c.project.Notify(project.CONTAINER_CREATED, c, map[string]string{ project.CONTAINER_ID: container.Container.ID, @@ -65,5 +79,6 @@ func (c *ContainerFactory) Create(project *project.Project, name string, service project: project, container: container, serviceConfig: serviceConfig, + cfg: c.cfg, }, nil }