mirror of
https://github.com/rancher/os.git
synced 2025-07-06 11:36:15 +00:00
Stage services when they are enabled
This commit is contained in:
parent
e861ae65ca
commit
2f10f9052a
@ -132,26 +132,29 @@ func del(c *cli.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func enable(c *cli.Context) {
|
func enable(c *cli.Context) {
|
||||||
changed := false
|
|
||||||
cfg, err := config.LoadConfig()
|
cfg, err := config.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var enabledServices []string
|
||||||
|
|
||||||
for _, service := range c.Args() {
|
for _, service := range c.Args() {
|
||||||
if val, ok := cfg.Rancher.ServicesInclude[service]; !ok || !val {
|
if val, ok := cfg.Rancher.ServicesInclude[service]; !ok || !val {
|
||||||
if strings.HasPrefix(service, "/") && !strings.HasPrefix(service, "/var/lib/rancher/conf") {
|
if strings.HasPrefix(service, "/") && !strings.HasPrefix(service, "/var/lib/rancher/conf") {
|
||||||
logrus.Fatalf("ERROR: Service should be in path /var/lib/rancher/conf")
|
logrus.Fatalf("ERROR: Service should be in path /var/lib/rancher/conf")
|
||||||
}
|
}
|
||||||
if _, err := compose.LoadServiceResource(service, true, cfg); err != nil {
|
|
||||||
logrus.Fatalf("could not load service %s", service)
|
|
||||||
}
|
|
||||||
cfg.Rancher.ServicesInclude[service] = true
|
cfg.Rancher.ServicesInclude[service] = true
|
||||||
changed = true
|
enabledServices = append(enabledServices, service)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if changed {
|
if len(enabledServices) > 0 {
|
||||||
|
if err := compose.StageServices(cfg, enabledServices...); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := cfg.Save(); err != nil {
|
if err := cfg.Save(); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package compose
|
package compose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
yaml "github.com/cloudfoundry-incubator/candiedyaml"
|
yaml "github.com/cloudfoundry-incubator/candiedyaml"
|
||||||
"github.com/docker/libcompose/cli/logger"
|
"github.com/docker/libcompose/cli/logger"
|
||||||
@ -191,6 +192,46 @@ func newCoreServiceProject(cfg *config.CloudConfig, network bool) (*project.Proj
|
|||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StageServices(cfg *config.CloudConfig, services ...string) error {
|
||||||
|
p, err := newProject("stage-services", cfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, service := range services {
|
||||||
|
bytes, err := LoadServiceResource(service, true, cfg)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to load %s : %v", service, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
m := map[interface{}]interface{}{}
|
||||||
|
if err := yaml.Unmarshal(bytes, &m); err != nil {
|
||||||
|
return fmt.Errorf("Failed to parse YAML configuration: %s : %v", service, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes, err = yaml.Marshal(config.StringifyValues(m))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Errorf("Failed to marshal YAML configuration: %s : %v", service, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = p.Load(bytes)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Errorf("Failed to load %s : %v", service, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reduce service configurations to just image and labels
|
||||||
|
for serviceName, serviceConfig := range p.Configs {
|
||||||
|
p.Configs[serviceName] = &project.ServiceConfig{
|
||||||
|
Image: serviceConfig.Image,
|
||||||
|
Labels: serviceConfig.Labels,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.Pull()
|
||||||
|
}
|
||||||
|
|
||||||
func LoadServiceResource(name string, network bool, cfg *config.CloudConfig) ([]byte, error) {
|
func LoadServiceResource(name string, network bool, cfg *config.CloudConfig) ([]byte, error) {
|
||||||
return util.LoadResource(name, network, cfg.Rancher.Repositories.ToArray())
|
return util.LoadResource(name, network, cfg.Rancher.Repositories.ToArray())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user