Skip to content

Commit

Permalink
Merge pull request #1118 from yunhee-l/version-api
Browse files Browse the repository at this point in the history
Bug - Fixed a bug where -version fails due to its dependency on docker client, removing docker version from -version output
  • Loading branch information
yhlee-aws authored Dec 1, 2017
2 parents 0ed2ed3 + d71caff commit 6527d7d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
9 changes: 0 additions & 9 deletions agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions agent/app/agent_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
1 change: 0 additions & 1 deletion agent/app/agent_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
6 changes: 3 additions & 3 deletions agent/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand All @@ -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()
Expand Down
18 changes: 6 additions & 12 deletions agent/version/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@

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:
//
// 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"
Expand All @@ -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.
Expand Down

0 comments on commit 6527d7d

Please sign in to comment.