示例#1
0
func getVersionDir(version dockerversion.Version) string {
	versionPath := version.SemVer.String()
	if version.IsExperimental() {
		versionPath = dockerversion.ExperimentalAlias
	}
	return filepath.Join(getVersionsDir(), versionPath)
}
示例#2
0
func downloadRelease(version dockerversion.Version) {
	url := buildDownloadURL(version)
	binaryName := getBinaryName()
	binaryPath := filepath.Join(getVersionDir(version), binaryName)
	if version.ShouldUseArchivedRelease() {
		archivedFile := path.Join("docker", binaryName)
		downloadArchivedFileWithChecksum(url, archivedFile, binaryPath)
	} else {
		downloadFileWithChecksum(url, binaryPath)
	}
	writeDebug("Downloaded Docker %s to %s.", version, binaryPath)
}
示例#3
0
func versionExists(version dockerversion.Version) bool {
	if version.IsExperimental() {
		return true
	}

	availableVersions := getAvailableVersions(version.SemVer.String())

	for _, availableVersion := range availableVersions {
		if version.Equals(availableVersion) {
			return true
		}
	}
	return false
}
示例#4
0
func isVersionInstalled(version dockerversion.Version) bool {
	writeDebug("Checking if version is installed: %s", version)
	installedVersions := getInstalledVersions("*")

	for _, availableVersion := range installedVersions {
		writeDebug("Checking version: %s", availableVersion)
		if version.Equals(availableVersion) {
			writeDebug("Version %s is installed", version)
			return true
		}
	}

	return false
}
示例#5
0
func alias(alias string, version dockerversion.Version) {
	if alias == "" || version.IsEmpty() {
		die("The alias command requires both an alias name and a version.", nil, retCodeInvalidArgument)
	}

	if !isVersionInstalled(version) {
		die("The aliased version, %s, is not installed.", nil, retCodeInvalidArgument, version)
	}

	aliasPath := getAliasPath(alias)
	if _, err := os.Stat(aliasPath); err == nil {
		writeDebug("Overwriting existing alias.")
	}

	writeFile(aliasPath, version.SemVer.String())
	writeInfo("Aliased %s to %s.", alias, version)
}
示例#6
0
func uninstall(version dockerversion.Version) {
	if version.IsEmpty() {
		die("The uninstall command requires that a version is specified.", nil, retCodeInvalidArgument)
	}

	current, _ := getCurrentDockerVersion()
	if current.Equals(version) {
		die("Cannot uninstall the currently active Docker version.", nil, retCodeInvalidOperation)
	}

	versionDir := getVersionDir(version)
	if _, err := os.Stat(versionDir); os.IsNotExist(err) {
		writeWarning("%s is not installed.", version)
		return
	}

	err := os.RemoveAll(versionDir)
	if err != nil {
		die("Unable to uninstall Docker version %s located in %s.", err, retCodeRuntimeError, version, versionDir)
	}

	writeInfo("Uninstalled Docker %s.", version)
}
示例#7
0
func install(version dockerversion.Version) {
	writeDebug("dvm install %s", version)

	if version.IsEmpty() {
		die("The install command requires that a version is specified or the DOCKER_VERSION environment variable is set.", nil, retCodeInvalidArgument)
	}

	if nocheck {
		writeDebug("Skipping version validation!")
	}

	if !nocheck && !versionExists(version) {
		die("Version %s not found - try `dvm ls-remote` to browse available versions.", nil, retCodeInvalidOperation, version)
	}

	versionDir := getVersionDir(version)

	if version.IsExperimental() && pathExists(versionDir) {
		// Always install latest of experimental build
		err := os.RemoveAll(versionDir)
		if err != nil {
			die("Unable to remove experimental version at %s.", err, retCodeRuntimeError, versionDir)
		}
	}

	if _, err := os.Stat(versionDir); err == nil {
		writeWarning("%s is already installed", version)
		use(version)
		return
	}

	writeInfo("Installing %s...", version)

	downloadRelease(version)
	use(version)
}
示例#8
0
func buildDownloadURL(version dockerversion.Version) string {
	dockerVersion := version.SemVer.String()
	if version.IsExperimental() {
		dockerVersion = "latest"
	}

	if mirrorURL == "" {
		mirrorURL = "https://get.docker.com/builds"
		if version.IsExperimental() {
			writeDebug("Downloading from experimental builds mirror")
			mirrorURL = "https://experimental.docker.com/builds"
		}
	}

	// New Docker versions are released in a zip file, vs. the old way of releasing the client binary only
	if version.ShouldUseArchivedRelease() {
		return fmt.Sprintf("%s/%s/%s/docker-%s%s", mirrorURL, dockerOS, dockerArch, dockerVersion, archiveFileExt)
	}

	return fmt.Sprintf("%s/%s/%s/docker-%s%s", mirrorURL, dockerOS, dockerArch, dockerVersion, binaryFileExt)
}
示例#9
0
func use(version dockerversion.Version) {
	writeDebug("dvm use %s", version)

	if version.IsEmpty() {
		die("The use command requires that a version is specified or the DOCKER_VERSION environment variable is set.", nil, retCodeInvalidOperation)
	}

	if version.HasAlias() && aliasExists(version.Alias) {
		aliasedVersion, _ := ioutil.ReadFile(getAliasPath(version.Alias))
		version.SemVer = semver.MustParse(string(aliasedVersion))
		writeDebug("Using alias: %s -> %s", version.Alias, version.SemVer)
	}

	ensureVersionIsInstalled(version)

	if version.IsSystem() {
		version, _ = getSystemDockerVersion()
	} else if version.IsExperimental() {
		version, _ = getExperimentalDockerVersion()
	}

	removePreviousDockerVersionFromPath()
	if !version.IsSystem() {
		prependDockerVersionToPath(version)
	}

	writePathScript()
	writeInfo("Now using Docker %s", version)
}