1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 22:32:14 +00:00

Stage services when they are enabled

This commit is contained in:
Josh Curl
2016-02-29 19:29:07 -08:00
parent e861ae65ca
commit 2f10f9052a
2 changed files with 50 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
package compose
import (
"fmt"
log "github.com/Sirupsen/logrus"
yaml "github.com/cloudfoundry-incubator/candiedyaml"
"github.com/docker/libcompose/cli/logger"
@@ -191,6 +192,46 @@ func newCoreServiceProject(cfg *config.CloudConfig, network bool) (*project.Proj
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) {
return util.LoadResource(name, network, cfg.Rancher.Repositories.ToArray())
}