From d71caff653e775ec9a0fceb79b9bd1f41afa9671 Mon Sep 17 00:00:00 2001 From: Lee Date: Tue, 28 Nov 2017 16:47:38 -0800 Subject: [PATCH] app,version: removing docker version from -version api --- CHANGELOG.md | 3 +++ agent/app/agent.go | 9 --------- agent/app/agent_integ_test.go | 4 ++-- agent/app/agent_windows_test.go | 1 - agent/app/run.go | 6 +++--- agent/version/formatting.go | 18 ++++++------------ 6 files changed, 14 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a29a09f7e26..af5a4e7528c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ #Changelog +## Unreleased +* Bug - Fixed a bug where `-version` fails due to its dependency on docker client. [#1118](https://github.com/aws/amazon-ecs-agent/pull/1118) + ## 1.16.0 * Feature - Support pulling from Amazon ECR with specified IAM role in task definition * Feature - Enable support for task level CPU and memory constraints. diff --git a/agent/app/agent.go b/agent/app/agent.go index 948ff843283..078bc9af129 100644 --- a/agent/app/agent.go +++ b/agent/app/agent.go @@ -44,7 +44,6 @@ import ( "github.com/aws/amazon-ecs-agent/agent/statemanager" "github.com/aws/amazon-ecs-agent/agent/tcs/handler" "github.com/aws/amazon-ecs-agent/agent/utils" - "github.com/aws/amazon-ecs-agent/agent/version" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" aws_credentials "github.com/aws/aws-sdk-go/aws/credentials" @@ -71,8 +70,6 @@ var ( // object. Its purpose is to mostly demonstrate how to interact with the // ecsAgent type. type agent interface { - // printVersion prints the Agent version string - printVersion() int // printECSAttributes prints the Agent's capabilities based on // its environment printECSAttributes() int @@ -170,12 +167,6 @@ func newAgent( }, nil } -// printVersion prints the ECS Agent version string -func (agent *ecsAgent) printVersion() int { - version.PrintVersion(agent.dockerClient) - return exitcodes.ExitSuccess -} - // printECSAttributes prints the Agent's ECS Attributes based on its // environment func (agent *ecsAgent) printECSAttributes() int { diff --git a/agent/app/agent_integ_test.go b/agent/app/agent_integ_test.go index 67237ee3365..232e4ed0db9 100644 --- a/agent/app/agent_integ_test.go +++ b/agent/app/agent_integ_test.go @@ -32,7 +32,7 @@ func TestNewAgent(t *testing.T) { agent, err := newAgent(ctx, true, aws.Bool(true)) assert.NoError(t, err) - // printVersion should ensure that agent's cfg is set with + // printECSAttributes should ensure that agent's cfg is set with // valid values and not panic - assert.Equal(t, exitcodes.ExitSuccess, agent.printVersion()) + assert.Equal(t, exitcodes.ExitSuccess, agent.printECSAttributes()) } diff --git a/agent/app/agent_windows_test.go b/agent/app/agent_windows_test.go index 5be445caa5a..35187b1c03e 100644 --- a/agent/app/agent_windows_test.go +++ b/agent/app/agent_windows_test.go @@ -40,7 +40,6 @@ func (m *mockAgent) start() int { func (m *mockAgent) setTerminationHandler(handler sighandlers.TerminationHandler) { m.terminationHandler = handler } -func (m *mockAgent) printVersion() int { return 0 } func (m *mockAgent) printECSAttributes() int { return 0 } func (m *mockAgent) startWindowsService() int { return 0 } diff --git a/agent/app/run.go b/agent/app/run.go index 944d7054540..5bd1cbe27aa 100644 --- a/agent/app/run.go +++ b/agent/app/run.go @@ -19,6 +19,7 @@ import ( "github.com/aws/amazon-ecs-agent/agent/app/args" "github.com/aws/amazon-ecs-agent/agent/logger" "github.com/aws/amazon-ecs-agent/agent/sighandlers/exitcodes" + "github.com/aws/amazon-ecs-agent/agent/version" "github.com/aws/aws-sdk-go/aws" log "github.com/cihub/seelog" ) @@ -35,6 +36,8 @@ func Run(arguments []string) int { if *parsedArgs.License { return printLicense() + } else if *parsedArgs.Version { + return version.PrintVersion() } logger.SetLevel(*parsedArgs.LogLevel) @@ -50,9 +53,6 @@ func Run(arguments []string) int { } switch { - case *parsedArgs.Version: - // Print Agent's version and exit - return agent.printVersion() case *parsedArgs.ECSAttributes: // Print agent's ecs attributes based on its environment and exit return agent.printECSAttributes() diff --git a/agent/version/formatting.go b/agent/version/formatting.go index bbdda806052..6fb325870f6 100644 --- a/agent/version/formatting.go +++ b/agent/version/formatting.go @@ -13,11 +13,11 @@ package version -import "fmt" +import ( + "fmt" -type Versioner interface { - Version() (string, error) -} + "github.com/aws/amazon-ecs-agent/agent/sighandlers/exitcodes" +) // PrintVersions prints the version information on stdout as a multi-line // string. The output will look similar to the following: @@ -25,8 +25,7 @@ type Versioner interface { // Amazon ECS Agent: // Version: 0.0.3 // Commit: 4bdc7fc -// DockerVersion: 1.5.0 -func PrintVersion(extra ...Versioner) { +func PrintVersion() int { cleanliness := "" if GitDirty { cleanliness = "\tDirty: true\n" @@ -37,12 +36,7 @@ func PrintVersion(extra ...Versioner) { Commit: %v %v`, Version, GitShortHash, cleanliness) - for _, versioner := range extra { - if str, err := versioner.Version(); err == nil { - fmt.Printf("\t%v\n", str) - } - } - + return exitcodes.ExitSuccess } // String produces a human-readable string showing the agent version.