Ejemplo n.º 1
0
//If image is running, ping healthcheck.
//	If not healthy, get latest version from docker registry, stop old and start new
//Otherwise, start latest version from docker registry
//Ensure started container is healthy
func up(applications []Application, airplaneMode bool) {
	healthChecker := healthcheck.HealthChecker{1, 1, 60}
	for _, app := range applications {
		fmt.Printf("%s", app.ImageName)
		var start = true

		if docker.IsImageRunning(app.ImageName) {
			fmt.Println(" checking")
			if healthcheck.IsHealthy(app.HealthCheck, healthChecker) {
				fmt.Println(" - healthy")
				start = false
			} else {
				fmt.Println(" unhealthy. Restarting")
				latestVersion := getLatestVersion(app.ImageName, airplaneMode)
				image := fmt.Sprintf("%s:%s", strings.Split(app.ImageName, ":")[0], latestVersion)
				docker.Stop([]docker.Container{docker.GetContainerIdFromImageName(image)})
			}
		} else {
			fmt.Println(" starting")
		}

		if start {
			image := fmt.Sprintf("%s:%s", strings.Split(app.ImageName, ":")[0], getLatestVersion(app.ImageName, airplaneMode))
			docker.Start(app.Service, image, app.Ports)
			fmt.Printf("  - Healthcheck: %s\n    ", app.HealthCheck.Description())
			if !healthcheck.AttemptHealthCheck(app.HealthCheck, healthChecker) {
				os.Exit(1)
			}
		}

		fmt.Println("")
	}
}
Ejemplo n.º 2
0
//If image is running, stop and refresh with latest version from docker registry.
//Otherwise, start latest version from docker registry
//Ensure started container is healthy
func refresh(appNames string, pathToYml string, airplaneMode bool) {
	fmt.Println("Fetching latest versions of applications from docker hub")
	apps := splitCommas(appNames)

	internalApplications := getInternalApplications(pathToYml)

	registeredApps := filterAppsAndExpandDepends(apps, internalApplications, airplaneMode)

	var appsInStartOrder []Application
	for i := len(registeredApps) - 1; i >= 0; i-- {
		appsInStartOrder = append(appsInStartOrder, registeredApps[i])
	}

	healthChecker := healthcheck.HealthChecker{1, 1, 30}
	for _, app := range appsInStartOrder {
		var start = true
		latestVersion := getLatestVersion(app.ImageName, airplaneMode)

		if docker.IsImageRunning(app.ImageName) {
			fmt.Println(" checking")
			currentVersion := docker.GetImageVersion(app.ImageName)

			image := fmt.Sprintf("%s:%s", currentVersion, latestVersion)
			fmt.Printf("Running Version [%s:%s], Latest Version: [%s:%s]\n", app.ImageName, currentVersion, app.ImageName, latestVersion)
			if currentVersion != latestVersion {
				fmt.Printf("Stopping Version [%s:%s]\n", app.ImageName, currentVersion)
				docker.Stop([]docker.Container{docker.GetContainerIdFromImageName(fmt.Sprintf("%s:%s", app.ImageName, currentVersion))})
			} else {
				if healthcheck.IsHealthy(app.HealthCheck, healthChecker) {
					fmt.Println(" - healthy")
					start = false
				} else {
					fmt.Println(" unhealthy. Restarting")
					docker.Stop([]docker.Container{docker.GetContainerIdFromImageName(image)})
				}
			}
		} else {
			fmt.Println(" starting")
		}

		if start {
			newImage := fmt.Sprintf("%s:%s", app.ImageName, latestVersion)
			docker.Start(app.Service, newImage, app.Ports)
			fmt.Printf("  - Healthcheck: %s\n    ", app.HealthCheck.Description())
			if !healthcheck.AttemptHealthCheck(app.HealthCheck, healthChecker) {
				os.Exit(1)
			}
		}

		fmt.Println("")
	}
}