Skip to content

Commit

Permalink
Refined engine implementations
Browse files Browse the repository at this point in the history
Adapt the CLI to the host install model for 18.09.

Signed-off-by: Daniel Hiltgen <[email protected]>
(cherry picked from commit 342afe4)
Signed-off-by: Daniel Hiltgen <[email protected]>
  • Loading branch information
Daniel Hiltgen committed Sep 21, 2018
1 parent eacb812 commit f07f51f
Show file tree
Hide file tree
Showing 19 changed files with 476 additions and 432 deletions.
10 changes: 7 additions & 3 deletions cli/command/engine/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/docker/licensing/model"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"golang.org/x/sys/unix"
)

type activateOptions struct {
Expand Down Expand Up @@ -68,7 +67,7 @@ https://hub.docker.com/ then specify the file with the '--license' flag.
}

func runActivate(cli command.Cli, options activateOptions) error {
if unix.Geteuid() != 0 {
if !isRoot() {
return errors.New("must be privileged to activate engine")
}
ctx := context.Background()
Expand Down Expand Up @@ -108,12 +107,17 @@ func runActivate(cli command.Cli, options activateOptions) error {
EngineVersion: options.version,
}

return client.ActivateEngine(ctx, opts, cli.Out(), authConfig,
err = client.ActivateEngine(ctx, opts, cli.Out(), authConfig,
func(ctx context.Context) error {
client := cli.Client()
_, err := client.Ping(ctx)
return err
})
if err != nil {
return err
}
fmt.Fprintln(cli.Out(), "To complete the activation, please restart docker with 'systemctl restart docker'")
return nil
}

func getLicenses(ctx context.Context, authConfig *types.AuthConfig, cli command.Cli, options activateOptions) (*model.IssuedLicense, error) {
Expand Down
2 changes: 2 additions & 0 deletions cli/command/engine/activate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestActivateNoContainerd(t *testing.T) {
return nil, fmt.Errorf("some error")
},
)
isRoot = func() bool { return true }
cmd := newActivateCommand(testCli)
cmd.Flags().Set("license", "invalidpath")
cmd.SilenceUsage = true
Expand All @@ -28,6 +29,7 @@ func TestActivateBadLicense(t *testing.T) {
return &fakeContainerizedEngineClient{}, nil
},
)
isRoot = func() bool { return true }
cmd := newActivateCommand(testCli)
cmd.SilenceUsage = true
cmd.SilenceErrors = true
Expand Down
13 changes: 13 additions & 0 deletions cli/command/engine/activate_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !windows

package engine

import (
"golang.org/x/sys/unix"
)

var (
isRoot = func() bool {
return unix.Geteuid() == 0
}
)
9 changes: 9 additions & 0 deletions cli/command/engine/activate_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build windows

package engine

var (
isRoot = func() bool {
return true
}
)
109 changes: 54 additions & 55 deletions cli/command/engine/check.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package engine

import (
"context"
"fmt"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/internal/versions"
clitypes "github.com/docker/cli/types"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"golang.org/x/sys/unix"
)

const (
Expand Down Expand Up @@ -37,7 +39,7 @@ func newCheckForUpdatesCommand(dockerCli command.Cli) *cobra.Command {
},
}
flags := cmd.Flags()
flags.StringVar(&options.registryPrefix, "registry-prefix", "", "Override the existing location where engine images are pulled")
flags.StringVar(&options.registryPrefix, "registry-prefix", "docker.io/store/docker", "Override the existing location where engine images are pulled")
flags.BoolVar(&options.downgrades, "downgrades", false, "Report downgrades (default omits older versions)")
flags.BoolVar(&options.preReleases, "pre-releases", false, "Include pre-release versions")
flags.BoolVar(&options.upgrades, "upgrades", true, "Report available upgrades")
Expand All @@ -49,70 +51,67 @@ func newCheckForUpdatesCommand(dockerCli command.Cli) *cobra.Command {
}

func runCheck(dockerCli command.Cli, options checkOptions) error {
if unix.Geteuid() != 0 {
if !isRoot() {
return errors.New("must be privileged to activate engine")
}
ctx := context.Background()
client := dockerCli.Client()
serverVersion, err := client.ServerVersion(ctx)
if err != nil {
return err
}

/*
ctx := context.Background()
client, err := dockerCli.NewContainerizedEngineClient(options.sockPath)
if err != nil {
return errors.Wrap(err, "unable to access local containerd")
}
defer client.Close()
versions, err := client.GetEngineVersions(ctx, dockerCli.RegistryClient(false), currentVersion, imageName)
if err != nil {
return err
}
availVersions, err := versions.GetEngineVersions(ctx, dockerCli.RegistryClient(false), options.registryPrefix, serverVersion)
if err != nil {
return err
}

availUpdates := []clitypes.Update{
{Type: "current", Version: currentVersion},
}
if len(versions.Patches) > 0 {
availUpdates = append(availUpdates,
processVersions(
currentVersion,
"patch",
options.preReleases,
versions.Patches)...)
}
if options.upgrades {
availUpdates = append(availUpdates,
processVersions(
currentVersion,
"upgrade",
options.preReleases,
versions.Upgrades)...)
}
if options.downgrades {
availUpdates = append(availUpdates,
processVersions(
currentVersion,
"downgrade",
options.preReleases,
versions.Downgrades)...)
}
availUpdates := []clitypes.Update{
{Type: "current", Version: serverVersion.Version},
}
if len(availVersions.Patches) > 0 {
availUpdates = append(availUpdates,
processVersions(
serverVersion.Version,
"patch",
options.preReleases,
availVersions.Patches)...)
}
if options.upgrades {
availUpdates = append(availUpdates,
processVersions(
serverVersion.Version,
"upgrade",
options.preReleases,
availVersions.Upgrades)...)
}
if options.downgrades {
availUpdates = append(availUpdates,
processVersions(
serverVersion.Version,
"downgrade",
options.preReleases,
availVersions.Downgrades)...)
}

format := options.format
if len(format) == 0 {
format = formatter.TableFormatKey
}
format := options.format
if len(format) == 0 {
format = formatter.TableFormatKey
}

updatesCtx := formatter.Context{
Output: dockerCli.Out(),
Format: formatter.NewUpdatesFormat(format, options.quiet),
Trunc: false,
}
return formatter.UpdatesWrite(updatesCtx, availUpdates)
*/
return nil
updatesCtx := formatter.Context{
Output: dockerCli.Out(),
Format: formatter.NewUpdatesFormat(format, options.quiet),
Trunc: false,
}
return formatter.UpdatesWrite(updatesCtx, availUpdates)
}

func processVersions(currentVersion, verType string,
includePrerelease bool,
versions []clitypes.DockerVersion) []clitypes.Update {
availVersions []clitypes.DockerVersion) []clitypes.Update {
availUpdates := []clitypes.Update{}
for _, ver := range versions {
for _, ver := range availVersions {
if !includePrerelease && ver.Prerelease() != "" {
continue
}
Expand Down
Loading

0 comments on commit f07f51f

Please sign in to comment.