Esempio n. 1
0
func StageServices(cfg *config.CloudConfig, services ...string) error {
	p, err := newProject("stage-services", cfg, nil, nil)
	if err != nil {
		return err
	}

	for _, service := range services {
		bytes, err := network.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(m)
		if err != nil {
			return fmt.Errorf("Failed to marshal YAML configuration: %s : %v", service, err)
		}

		err = p.Load(bytes)
		if err != nil {
			return fmt.Errorf("Failed to load %s : %v", service, err)
		}
	}

	// Reduce service configurations to just image and labels
	for _, serviceName := range p.ServiceConfigs.Keys() {
		serviceConfig, _ := p.ServiceConfigs.Get(serviceName)
		p.ServiceConfigs.Add(serviceName, &composeConfig.ServiceConfig{
			Image:  serviceConfig.Image,
			Labels: serviceConfig.Labels,
		})
	}

	return p.Pull(context.Background())
}
Esempio n. 2
0
func LoadService(p *project.Project, cfg *config.CloudConfig, useNetwork bool, service string) error {
	bytes, err := network.LoadServiceResource(service, useNetwork, cfg)
	if err != nil {
		return err
	}

	m := map[interface{}]interface{}{}
	if err = yaml.Unmarshal(bytes, &m); err != nil {
		return fmt.Errorf("Failed to parse YAML configuration for %s: %v", service, err)
	}

	m = adjustContainerNames(m)

	bytes, err = yaml.Marshal(m)
	if err != nil {
		return fmt.Errorf("Failed to marshal YAML configuration for %s: %v", service, err)
	}

	if err = p.Load(bytes); err != nil {
		return fmt.Errorf("Failed to load %s: %v", service, err)
	}

	return nil
}