Exemplo n.º 1
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)
}
Exemplo n.º 2
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)
}
Exemplo n.º 3
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)
}
Exemplo n.º 4
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)
}