예제 #1
0
func (provisioner *WindowsProvisioner) checkDockerVersion() bool {
	log.Debug("Checking docker version (secure)")

	ip, err := provisioner.Driver.GetIP()
	if err != nil {
		return false
	}

	dockerVersionSecureCmd := "docker -H tcp://127.0.0.1:2376 --tlsverify=false " +
		" --tlscacert=" + provisioner.AuthOptions.CaCertRemotePath +
		" --tlscert=" + provisioner.AuthOptions.ServerCertRemotePath +
		" --tlskey=" + provisioner.AuthOptions.ServerKeyRemotePath +
		" version"

	d := provisioner.Driver
	out, err, exit := drivers.WinRMRunCmd(
		ip,
		d.GetSSHUsername(),
		d.GetSSHPassword(),
		dockerVersionSecureCmd)
	if (err != nil) || (exit != 0) {
		log.Warn("Error getting WinRM command to get docker version (secure),",
			"out:", out, ", err:", err, ", exit:", exit)
		return false
	}

	if strings.Contains(out, expectedDockerBuiltDate) {
		return true
	}
	return false
}
예제 #2
0
func (provisioner *WindowsProvisioner) openDockerPortOnHost() bool {
	ip, err := provisioner.Driver.GetIP()
	if err != nil {
		return false
	}

	d := provisioner.Driver
	out, err, exit := drivers.WinRMRunCmd(ip,
		d.GetSSHUsername(),
		d.GetSSHPassword(),
		openPortCmd)
	if (err != nil) || (exit != 0) {
		log.Warn("failed to enable firewall rule for docker:", out, ", err:", err, ", exit:", exit)
		return false
	}
	return true
}
예제 #3
0
func (provisioner *WindowsProvisioner) dockerDaemonResponding() bool {
	log.Debug("Checking docker daemon")

	ip, err := provisioner.Driver.GetIP()
	if err != nil {
		return false
	}

	d := provisioner.Driver
	out, err, exit := drivers.WinRMRunCmd(
		ip,
		d.GetSSHUsername(),
		d.GetSSHPassword(),
		dockerVersionCmd)
	if (err != nil) || (exit != 0) {
		log.Warn("Error getting WinRM command to check if the daemon is up,",
			"out:", out, ", err:", err, ", exit:", exit)
		return false
	}

	// The daemon is up if the command worked.  Carry on.
	return true
}
예제 #4
0
// Update Docker client on the Azure VM to get the BugFix for docker
// pull failing
func (provisioner *WindowsProvisioner) updateDocker() bool {
	log.Debug("Updating docker on host")

	ip, err := provisioner.Driver.GetIP()
	if err != nil {
		return false
	}

	// download the PS script to update docker
	d := provisioner.Driver
	out, err, exit := drivers.WinRMRunCmd(ip,
		d.GetSSHUsername(),
		d.GetSSHPassword(),
		getDockerUpdateCmd)
	if (err != nil) || (exit != 0) {
		log.Warn("failed to execute cmd: ", getDockerUpdateCmd, ", err:", err, ", exit:", exit)
		return false
	}

	// wait for docker service to be ready before we can update it.
	for i := 0; i <= 60; i++ {
		out, err, exit = drivers.WinRMRunCmd(ip,
			d.GetSSHUsername(),
			d.GetSSHPassword(),
			checkDockerCmd)
		if (err != nil) || (exit != 0) {
			log.Warn("failed to execute cmd: ", checkDockerCmd, ", err:", err, ", exit: ", exit)
			return false
		}

		// if service hasn't yet started running, sleep and check again
		if out == "" {
			time.Sleep(time.Duration(5) * time.Second)
			continue
		}

		// if stdout is not empty, it means Docker has begun,
		// leave retry-loop
		break
	}

	// execute the downloaded PS script
	out, err, exit = drivers.WinRMRunCmd(ip,
		d.GetSSHUsername(),
		d.GetSSHPassword(),
		updateDockerCmd)
	if (err != nil) || (exit != 0) {
		log.Warn("failed to execute cmd: ", updateDockerCmd, ", err:", err, ", exit:", exit)
		return false
	}

	// restart docker in secure mode since the update docker script
	// starts it in insecure mode

	// a. create the tag file since this is used by runDockerDaemon.cmd script
	out, err, exit = drivers.WinRMRunCmd(ip,
		d.GetSSHUsername(),
		d.GetSSHPassword(),
		createTagFileCmd)
	if (err != nil) || (exit != 0) {
		log.Warn("failed to execute cmd: ", createTagFileCmd, ", err:", err, ", exit:", exit)
		return false
	}

	// b. restart docker service
	out, err, exit = drivers.WinRMRunCmd(ip,
		d.GetSSHUsername(),
		d.GetSSHPassword(),
		restartDockerCmd)
	if (err != nil) || (exit != 0) {
		log.Warn("failed to execute cmd: ", restartDockerCmd, ", err:", err, ", exit:", exit)
		return false
	}

	return true
}