Exemplo n.º 1
0
func getServicesFirstContainerUuid(serviceUuid string) (string, error) {
	service, err := tutum.GetService(serviceUuid)
	if err != nil {
		return "", err
	}
	return getUuidFromUri(service.Containers[0]), nil // ??? URI or Uuid?
}
Exemplo n.º 2
0
func redeployService(serviceNameToRedeploy string, haproxyServiceName string) error {
	// tutum User, ApiKey should be set in environment TUTUM_USER, TUTUM_APIKEY

	serviceList, err := tutum.ListServices()
	if err != nil {
		return err
	}

	redeployedServiceUuid, err := getServiceUuid(serviceNameToRedeploy, serviceList.Objects)
	if err != nil {
		return err
	}
	haproxyServiceUuid, err := getServiceUuid(haproxyServiceName, serviceList.Objects)
	if err != nil {
		return err
	}
	haproxyContainerUuid, err := getServicesFirstContainerUuid(haproxyServiceUuid)
	if err != nil {
		return err
	}

	redeployedService, err := tutum.GetService(redeployedServiceUuid)
	if err != nil {
		return err
	}

	log.Printf("redeploying service %s (%s) via haproxy %s (%s)",
		redeployedService.Name, redeployedServiceUuid, haproxyServiceName, haproxyServiceUuid)

	for i := range redeployedService.Containers {
		err = doRedeployContainer(redeployedService.Containers[i], redeployedService, haproxyContainerUuid)
		if err != nil {
			return err
		}
		time.Sleep(25 * time.Second)
	}

	// future improvement: do final check via haproxy

	log.Printf("successfully redeployed service %s (%s) via haproxy %s (%s)",
		redeployedService.Name, redeployedServiceUuid, haproxyServiceName, haproxyServiceUuid)

	return nil
}