Exemple #1
0
func (c *Container) getHash(imageName string) string {
	serviceConfig := *c.service.Config()
	imageInfo, err := c.client.InspectImage(imageName)
	if imageInfo != nil && err == nil {
		serviceConfig.Image = imageInfo.Id
	} else {
		serviceConfig.Image = imageName
	}

	return project.GetServiceHash(c.service.Name(), serviceConfig)
}
Exemple #2
0
func (c *Container) OutOfSync() (bool, error) {
	container, err := c.findExisting()
	if err != nil || container == nil {
		return false, err
	}

	info, err := c.client.InspectContainer(container.Id)
	if err != nil {
		return false, err
	}

	return info.Config.Labels[HASH.Str()] != project.GetServiceHash(c.service), nil
}
func (c *Container) createContainer(imageName string, configOverride *project.ServiceConfig) (*dockerclient.Container, error) {
	serviceConfig := c.service.serviceConfig
	if configOverride != nil {
		serviceConfig.Command = configOverride.Command
		serviceConfig.Tty = configOverride.Tty
	}
	config, err := ConvertToApi(serviceConfig)
	if err != nil {
		return nil, err
	}

	config.Image = imageName

	if config.Labels == nil {
		config.Labels = map[string]string{}
	}

	config.Labels[NAME.Str()] = c.name
	config.Labels[SERVICE.Str()] = c.service.name
	config.Labels[PROJECT.Str()] = c.service.context.Project.Name
	config.Labels[HASH.Str()] = project.GetServiceHash(c.service)

	err = c.populateAdditionalHostConfig(&config.HostConfig)
	if err != nil {
		return nil, err
	}

	logrus.Debugf("Creating container %s %#v", c.name, config)

	_, err = c.client.CreateContainer(config, c.name)
	if err != nil && err.Error() == "Not found" {
		logrus.Debugf("Not Found, pulling image %s", config.Image)
		if err = c.pull(config.Image); err != nil {
			return nil, err
		}
		if _, err = c.client.CreateContainer(config, c.name); err != nil {
			return nil, err
		}
	}

	if err != nil {
		logrus.Debugf("Failed to create container %s: %v", c.name, err)
		return nil, err
	}

	return c.findExisting()
}
Exemple #4
0
func addServices(p *project.Project, cfg *config.CloudConfig, enabled map[string]string, configs map[string]*project.ServiceConfig) {
	// Note: we ignore errors while loading services
	for name, serviceConfig := range configs {
		hash := project.GetServiceHash(name, *serviceConfig)

		if enabled[name] == hash {
			continue
		}

		if err := p.AddConfig(name, serviceConfig); err != nil {
			log.Infof("Failed loading service %s", name)
			continue
		}

		enabled[name] = hash
	}
}
Exemple #5
0
func (c *Container) createContainer(imageName string) (*dockerclient.APIContainers, error) {
	createOpts, err := ConvertToAPI(c.service.serviceConfig, c.name)
	if err != nil {
		return nil, err
	}

	createOpts.Config.Image = imageName

	if createOpts.Config.Labels == nil {
		createOpts.Config.Labels = map[string]string{}
	}

	createOpts.Config.Labels[NAME.Str()] = c.name
	createOpts.Config.Labels[SERVICE.Str()] = c.service.name
	createOpts.Config.Labels[PROJECT.Str()] = c.service.context.Project.Name
	createOpts.Config.Labels[HASH.Str()] = project.GetServiceHash(c.service)

	err = c.populateAdditionalHostConfig(createOpts.HostConfig)
	if err != nil {
		return nil, err
	}

	logrus.Debugf("Creating container %s %#v", c.name, createOpts)

	_, err = c.client.CreateContainer(*createOpts)
	if err != nil && err == dockerclient.ErrNoSuchImage {
		logrus.Debugf("Not Found, pulling image %s", createOpts.Config.Image)
		if err = c.pull(createOpts.Config.Image); err != nil {
			return nil, err
		}
		if _, err = c.client.CreateContainer(*createOpts); err != nil {
			return nil, err
		}
	}

	if err != nil {
		logrus.Debugf("Failed to create container %s: %v", c.name, err)
		return nil, err
	}

	return c.findExisting()
}
Exemple #6
0
func addServices(p *project.Project, enabled map[interface{}]interface{}, configs map[string]*project.ServiceConfig) map[interface{}]interface{} {
	// Note: we ignore errors while loading services
	unchanged := true
	for name, serviceConfig := range configs {
		hash := project.GetServiceHash(name, serviceConfig)

		if enabled[name] == hash {
			continue
		}

		if err := p.AddConfig(name, serviceConfig); err != nil {
			log.Infof("Failed loading service %s", name)
			continue
		}

		if unchanged {
			enabled = util.MapCopy(enabled)
			unchanged = false
		}
		enabled[name] = hash
	}
	return enabled
}
Exemple #7
0
func (c *Container) getHash() string {
	return project.GetServiceHash(c.service.Name(), *c.service.Config())
}