From 1925fde51eeac8c7c574fc6be5efe1a8522538e4 Mon Sep 17 00:00:00 2001 From: Piradeep Kandasamy Date: Wed, 25 Sep 2019 15:30:54 -0700 Subject: [PATCH 01/19] Add additional logging to integ tests --- ecs-cli/integ/cmd/compose.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ecs-cli/integ/cmd/compose.go b/ecs-cli/integ/cmd/compose.go index 43cfeb89d..bf5c8d625 100644 --- a/ecs-cli/integ/cmd/compose.go +++ b/ecs-cli/integ/cmd/compose.go @@ -268,6 +268,7 @@ func testServiceHasAllRunningContainers(t *testing.T, p *Project, wantedNumOfCon containers := lines[1:] // Drop the headers if wantedNumOfContainers != len(containers) { t.Logf("Wanted = %d, got = %d running containers", wantedNumOfContainers, len(containers)) + t.Logf("Current running containers = %v", containers) return false } for _, container := range containers { @@ -276,6 +277,7 @@ func testServiceHasAllRunningContainers(t *testing.T, p *Project, wantedNumOfCon t.Logf("Container is not RUNNING: %s", container) return false } + t.Logf("Container is RUNNING: %s", container) } return true } From 498dc7b55ae6643174c263cb91f0013b270f6745 Mon Sep 17 00:00:00 2001 From: Neil Davies Date: Sun, 29 Sep 2019 13:23:23 -0400 Subject: [PATCH 02/19] Fix-933 Better splitting of SSM paramName from ARN --- ecs-cli/modules/cli/local/secrets/clients/clients.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ecs-cli/modules/cli/local/secrets/clients/clients.go b/ecs-cli/modules/cli/local/secrets/clients/clients.go index cc8d03599..1268443a6 100644 --- a/ecs-cli/modules/cli/local/secrets/clients/clients.go +++ b/ecs-cli/modules/cli/local/secrets/clients/clients.go @@ -62,8 +62,7 @@ func (d *SSMDecrypter) DecryptSecret(arnOrName string) (string, error) { // If the value is an ARN we need to retrieve the parameter name and update the region of the client. paramName := arnOrName if parsedARN, err := arnParser.Parse(arnOrName); err == nil { - resource := strings.Split(parsedARN.Resource, "/") // Resource is formatted as parameter/{paramName}. - paramName = strings.Join(resource[1:], "") + paramName = parsedARN.Resource[strings.Index(parsedARN.Resource, "/"):] // paramName is formatted as arn:parameter/{paramName} d.SSMAPI = d.getClient(region(parsedARN.Region)) } From c12de08d1f31de34a2c56868593f85a9afe19da4 Mon Sep 17 00:00:00 2001 From: Neil Davies Date: Sun, 29 Sep 2019 13:31:31 -0400 Subject: [PATCH 03/19] splitting with slash --- ecs-cli/modules/cli/local/secrets/clients/clients.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ecs-cli/modules/cli/local/secrets/clients/clients.go b/ecs-cli/modules/cli/local/secrets/clients/clients.go index 1268443a6..50dba6bcf 100644 --- a/ecs-cli/modules/cli/local/secrets/clients/clients.go +++ b/ecs-cli/modules/cli/local/secrets/clients/clients.go @@ -62,7 +62,8 @@ func (d *SSMDecrypter) DecryptSecret(arnOrName string) (string, error) { // If the value is an ARN we need to retrieve the parameter name and update the region of the client. paramName := arnOrName if parsedARN, err := arnParser.Parse(arnOrName); err == nil { - paramName = parsedARN.Resource[strings.Index(parsedARN.Resource, "/"):] // paramName is formatted as arn:parameter/{paramName} + resource := strings.Split(parsedARN.Resource, "/") // Resource is formatted as parameter/{paramName}. paramName = parsedARN.Resource[strings.Index(parsedARN.Resource, "/"):] // paramName is formatted as arn:parameter/{paramName} + paramName = strings.Join(resource[1:], "/") d.SSMAPI = d.getClient(region(parsedARN.Region)) } From 89288ce00c72dad321433e637ce2a0153a3aa2ba Mon Sep 17 00:00:00 2001 From: Neil Davies Date: Sun, 29 Sep 2019 13:36:22 -0400 Subject: [PATCH 04/19] adding test --- .../cli/local/secrets/clients/clients_test.go | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ecs-cli/modules/cli/local/secrets/clients/clients_test.go b/ecs-cli/modules/cli/local/secrets/clients/clients_test.go index 75efb32e2..c9ea0668e 100644 --- a/ecs-cli/modules/cli/local/secrets/clients/clients_test.go +++ b/ecs-cli/modules/cli/local/secrets/clients/clients_test.go @@ -116,6 +116,37 @@ func TestSSMDecrypter_DecryptSecret(t *testing.T) { pdxClient.EXPECT().GetParameter(gomock.Any()).Times(0), // Should not have called PDX ) + return &SSMDecrypter{ + SSMAPI: iadClient, + clients: m, + } + }, + }, + "with forward slash": { + input: "/TEST/DB/PASSWORD", + wantedSecret: "hello", + setupDecrypter: func(ctrl *gomock.Controller) *SSMDecrypter { + iadClient := mock_ssmiface.NewMockSSMAPI(ctrl) + pdxClient := mock_ssmiface.NewMockSSMAPI(ctrl) + + m := make(map[region]ssmiface.SSMAPI) + m["default"] = iadClient + m["us-east-1"] = iadClient + m["us-west-2"] = pdxClient + + gomock.InOrder( + iadClient.EXPECT().GetParameter(&ssm.GetParameterInput{ + Name: aws.String("/TEST/DB/PASSWORD"), + WithDecryption: aws.Bool(true), + }).Return(&ssm.GetParameterOutput{ + Parameter: &ssm.Parameter{ + Value: aws.String("hello"), + }, + }, nil), + + pdxClient.EXPECT().GetParameter(gomock.Any()).Times(0), // Should not have called PDX + ) + return &SSMDecrypter{ SSMAPI: iadClient, clients: m, From fce8ba0387b865c89a799110fccac716d7d7aa73 Mon Sep 17 00:00:00 2001 From: Neil Davies Date: Sun, 29 Sep 2019 13:39:16 -0400 Subject: [PATCH 05/19] comment for change --- ecs-cli/modules/cli/local/secrets/clients/clients.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecs-cli/modules/cli/local/secrets/clients/clients.go b/ecs-cli/modules/cli/local/secrets/clients/clients.go index 50dba6bcf..78f12743c 100644 --- a/ecs-cli/modules/cli/local/secrets/clients/clients.go +++ b/ecs-cli/modules/cli/local/secrets/clients/clients.go @@ -63,7 +63,7 @@ func (d *SSMDecrypter) DecryptSecret(arnOrName string) (string, error) { paramName := arnOrName if parsedARN, err := arnParser.Parse(arnOrName); err == nil { resource := strings.Split(parsedARN.Resource, "/") // Resource is formatted as parameter/{paramName}. paramName = parsedARN.Resource[strings.Index(parsedARN.Resource, "/"):] // paramName is formatted as arn:parameter/{paramName} - paramName = strings.Join(resource[1:], "/") + paramName = strings.Join(resource[1:], "/") // Put any extra slashes back in d.SSMAPI = d.getClient(region(parsedARN.Region)) } From 6beba781c3112f5c244e2aed36f86fed593a6ac8 Mon Sep 17 00:00:00 2001 From: Neil Davies Date: Sun, 29 Sep 2019 13:40:28 -0400 Subject: [PATCH 06/19] remove copy-pasta --- ecs-cli/modules/cli/local/secrets/clients/clients.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecs-cli/modules/cli/local/secrets/clients/clients.go b/ecs-cli/modules/cli/local/secrets/clients/clients.go index 78f12743c..71192176d 100644 --- a/ecs-cli/modules/cli/local/secrets/clients/clients.go +++ b/ecs-cli/modules/cli/local/secrets/clients/clients.go @@ -62,7 +62,7 @@ func (d *SSMDecrypter) DecryptSecret(arnOrName string) (string, error) { // If the value is an ARN we need to retrieve the parameter name and update the region of the client. paramName := arnOrName if parsedARN, err := arnParser.Parse(arnOrName); err == nil { - resource := strings.Split(parsedARN.Resource, "/") // Resource is formatted as parameter/{paramName}. paramName = parsedARN.Resource[strings.Index(parsedARN.Resource, "/"):] // paramName is formatted as arn:parameter/{paramName} + resource := strings.Split(parsedARN.Resource, "/") // Resource is formatted as parameter/{paramName}. paramName = strings.Join(resource[1:], "/") // Put any extra slashes back in d.SSMAPI = d.getClient(region(parsedARN.Region)) } From d954f8b523553f21528a36906eceb3c9d5af05ae Mon Sep 17 00:00:00 2001 From: Neil Davies Date: Mon, 30 Sep 2019 17:33:21 -0400 Subject: [PATCH 07/19] better parsing of paramName as per @hencrice --- ecs-cli/modules/cli/local/secrets/clients/clients.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ecs-cli/modules/cli/local/secrets/clients/clients.go b/ecs-cli/modules/cli/local/secrets/clients/clients.go index 71192176d..c659d9a82 100644 --- a/ecs-cli/modules/cli/local/secrets/clients/clients.go +++ b/ecs-cli/modules/cli/local/secrets/clients/clients.go @@ -15,8 +15,6 @@ package clients import ( - "strings" - "github.com/aws/amazon-ecs-cli/ecs-cli/modules/config" "github.com/aws/aws-sdk-go/aws" arnParser "github.com/aws/aws-sdk-go/aws/arn" @@ -62,8 +60,7 @@ func (d *SSMDecrypter) DecryptSecret(arnOrName string) (string, error) { // If the value is an ARN we need to retrieve the parameter name and update the region of the client. paramName := arnOrName if parsedARN, err := arnParser.Parse(arnOrName); err == nil { - resource := strings.Split(parsedARN.Resource, "/") // Resource is formatted as parameter/{paramName}. - paramName = strings.Join(resource[1:], "/") // Put any extra slashes back in + paramName = parsedARN.Resource[len("parameter/"):] // Resource is formatted as parameter/{paramName}. d.SSMAPI = d.getClient(region(parsedARN.Region)) } From a21d559776d2f6e783b8c6b62cbe00fc30933008 Mon Sep 17 00:00:00 2001 From: Yenlin Chen <3822365+hencrice@users.noreply.github.com> Date: Wed, 2 Oct 2019 17:21:38 -0700 Subject: [PATCH 08/19] Print out verbose messages for credential chain errors This flag will enable verbose error messages related to credential chain problems. Fixes #929. --- ecs-cli/modules/cli/local/secrets/clients/clients.go | 10 ++++++++-- ecs-cli/modules/config/config_v1.go | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ecs-cli/modules/cli/local/secrets/clients/clients.go b/ecs-cli/modules/cli/local/secrets/clients/clients.go index cc8d03599..6b21b74dd 100644 --- a/ecs-cli/modules/cli/local/secrets/clients/clients.go +++ b/ecs-cli/modules/cli/local/secrets/clients/clients.go @@ -84,7 +84,10 @@ func (d *SSMDecrypter) getClient(r region) ssmiface.SSMAPI { return c } c := ssm.New(session.Must(session.NewSessionWithOptions(session.Options{ - Config: aws.Config{Region: aws.String(string(r))}, + Config: aws.Config{ + Region: aws.String(string(r)), + CredentialsChainVerboseErrors: aws.Bool(true), + }, }))) d.clients[r] = c return c @@ -111,7 +114,10 @@ func (d *SecretsManagerDecrypter) getClient(r region) secretsmanageriface.Secret return c } c := secretsmanager.New(session.Must(session.NewSessionWithOptions(session.Options{ - Config: aws.Config{Region: aws.String(string(r))}, + Config: aws.Config{ + Region: aws.String(string(r)), + CredentialsChainVerboseErrors: aws.Bool(true), + }, }))) d.clients[r] = c return c diff --git a/ecs-cli/modules/config/config_v1.go b/ecs-cli/modules/config/config_v1.go index 1fd0139da..61b2c10c0 100644 --- a/ecs-cli/modules/config/config_v1.go +++ b/ecs-cli/modules/config/config_v1.go @@ -118,7 +118,9 @@ func NewLocalConfig(cluster string) *LocalConfig { // a) AWS_DEFAULT_PROFILE environment variable (defaults to 'default') // 5) EC2 Instance role func (cfg *LocalConfig) ToAWSSession(context *cli.Context) (*session.Session, error) { - svcConfig := aws.Config{} + svcConfig := aws.Config{ + CredentialsChainVerboseErrors: aws.Bool(true), + } if ecsEndpoint := RecursiveFlagSearch(context, flags.EndpointFlag); ecsEndpoint != "" { defaultResolver := endpoints.DefaultResolver() ecsCustomResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) { From bc7ffbf63a013074108a95ecd21b997fa9705076 Mon Sep 17 00:00:00 2001 From: Yenlin Chen <3822365+hencrice@users.noreply.github.com> Date: Thu, 3 Oct 2019 11:06:33 -0700 Subject: [PATCH 09/19] Update the AWS Config for CWlogs --- ecs-cli/modules/clients/aws/cloudwatchlogs/client.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ecs-cli/modules/clients/aws/cloudwatchlogs/client.go b/ecs-cli/modules/clients/aws/cloudwatchlogs/client.go index f33bc439e..b8c5edf58 100644 --- a/ecs-cli/modules/clients/aws/cloudwatchlogs/client.go +++ b/ecs-cli/modules/clients/aws/cloudwatchlogs/client.go @@ -34,7 +34,10 @@ type cwLogsClient struct { // NewCloudWatchLogsClient creates an instance of ec2Client object. func NewCloudWatchLogsClient(params *config.CommandConfig, logRegion string) Client { - newSession := params.Session.Copy(&aws.Config{Region: aws.String(logRegion)}) + newSession := params.Session.Copy(&aws.Config{ + Region: aws.String(logRegion), + CredentialsChainVerboseErrors: aws.Bool(true), + }) client := cloudwatchlogs.New(newSession) client.Handlers.Build.PushBackNamed(clients.CustomUserAgentHandler()) return &cwLogsClient{ From f083490ec0c2067e3289203392412ef4ac33a4c9 Mon Sep 17 00:00:00 2001 From: Yenlin Chen <3822365+hencrice@users.noreply.github.com> Date: Thu, 3 Oct 2019 11:38:16 -0700 Subject: [PATCH 10/19] Send optional fields as nil instead of "" to ECS Previously when sending certain requests that contain optional fields to ECS through the Go AWS SDK, we always send empty strings instead of nil for those optional fields that are not set. The service treats such an action as an explicit intent and hence fails to plug in the default values from the service side. This PR closes #927. Specifically, the repo 3. --- ecs-cli/modules/utils/compose/convert_task_definition.go | 8 ++++++-- ecs-cli/modules/utils/compose/ecs_params_reader.go | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ecs-cli/modules/utils/compose/convert_task_definition.go b/ecs-cli/modules/utils/compose/convert_task_definition.go index b15133516..bfb009583 100644 --- a/ecs-cli/modules/utils/compose/convert_task_definition.go +++ b/ecs-cli/modules/utils/compose/convert_task_definition.go @@ -286,8 +286,12 @@ func mergeVolumesWithoutHost(composeVolumes []string, ecsParams *ECSParams) ([]* if dVol.Name != "" { ecsVolume.DockerVolumeConfiguration = &ecs.DockerVolumeConfiguration{ Autoprovision: dVol.Autoprovision, - Driver: aws.String(dVol.Driver), - Scope: aws.String(dVol.Scope), + } + if dVol.Driver != nil { + ecsVolume.DockerVolumeConfiguration.Driver = dVol.Driver + } + if dVol.Scope != nil { + ecsVolume.DockerVolumeConfiguration.Scope = dVol.Scope } if dVol.DriverOptions != nil { ecsVolume.DockerVolumeConfiguration.DriverOpts = aws.StringMap(dVol.DriverOptions) diff --git a/ecs-cli/modules/utils/compose/ecs_params_reader.go b/ecs-cli/modules/utils/compose/ecs_params_reader.go index ef58e9b9b..3475eb2e1 100644 --- a/ecs-cli/modules/utils/compose/ecs_params_reader.go +++ b/ecs-cli/modules/utils/compose/ecs_params_reader.go @@ -75,9 +75,9 @@ type ContainerDef struct { type DockerVolume struct { Name string `yaml:"name"` - Scope string `yaml:"scope"` + Scope *string `yaml:"scope"` Autoprovision *bool `yaml:"autoprovision"` - Driver string `yaml:"driver"` + Driver *string `yaml:"driver"` DriverOptions map[string]string `yaml:"driver_opts"` Labels map[string]string `yaml:"labels"` } From 74edc65eff0e8b83760a4219a9f81ad9b4667f97 Mon Sep 17 00:00:00 2001 From: Yenlin Chen <3822365+hencrice@users.noreply.github.com> Date: Mon, 7 Oct 2019 10:27:11 -0700 Subject: [PATCH 11/19] Updated failed unit tests --- ecs-cli/modules/utils/compose/convert_task_definition_test.go | 4 ++-- ecs-cli/modules/utils/compose/ecs_params_reader_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ecs-cli/modules/utils/compose/convert_task_definition_test.go b/ecs-cli/modules/utils/compose/convert_task_definition_test.go index 9914d7984..ea188904d 100644 --- a/ecs-cli/modules/utils/compose/convert_task_definition_test.go +++ b/ecs-cli/modules/utils/compose/convert_task_definition_test.go @@ -1383,8 +1383,8 @@ func TestConvertToTaskDefinitionWithECSParamsVolumeWithoutNameError(t *testing.T DockerVolumes: []DockerVolume{ DockerVolume{ Autoprovision: aws.Bool(true), - Scope: "shared", - Driver: "local", + Scope: aws.String("shared"), + Driver: nil, DriverOptions: options, Labels: labels, }, diff --git a/ecs-cli/modules/utils/compose/ecs_params_reader_test.go b/ecs-cli/modules/utils/compose/ecs_params_reader_test.go index 250959132..375ad9887 100644 --- a/ecs-cli/modules/utils/compose/ecs_params_reader_test.go +++ b/ecs-cli/modules/utils/compose/ecs_params_reader_test.go @@ -647,9 +647,9 @@ task_definition: expectedVolumes := []DockerVolume{ DockerVolume{ Name: "my_volume", - Scope: "shared", + Scope: aws.String("shared"), Autoprovision: aws.Bool(true), - Driver: "doggyromcom", + Driver: aws.String("doggyromcom"), DriverOptions: map[string]string{ "pudding": "is-engaged-to-marry-Tum-Tum", "clyde": "professes-his-love-at-the-ceremony", From 2ce32d9cc90ff7518b245f4ce18c6fb624200416 Mon Sep 17 00:00:00 2001 From: Hsing-Hui Hsu Date: Wed, 9 Oct 2019 16:31:45 -0700 Subject: [PATCH 12/19] Support g4dn GPU instances Also correctly retrieve AMI for G3* GPU instances --- .../modules/clients/aws/amimetadata/client.go | 20 ++++++++++++------- .../clients/aws/amimetadata/client_test.go | 11 ++++++++++ .../aws/cloudformation/cluster_template.go | 6 ++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/ecs-cli/modules/clients/aws/amimetadata/client.go b/ecs-cli/modules/clients/aws/amimetadata/client.go index 92f3693bc..f69a76e5c 100644 --- a/ecs-cli/modules/clients/aws/amimetadata/client.go +++ b/ecs-cli/modules/clients/aws/amimetadata/client.go @@ -111,15 +111,21 @@ func isARM64Instance(instanceType string) bool { return false } +// See: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-gpu.html func isGPUInstance(instanceType string) bool { - if strings.HasPrefix(instanceType, "p2.") { - return true - } - if strings.HasPrefix(instanceType, "p3.") { - return true + var gpuInstanceClasses = []string{ + "p2.", + "p3.", + "p3dn.", + "g3.", + "g3s.", + "g4dn.", } - if strings.HasPrefix(instanceType, "p3dn.") { - return true + for _, instanceClass := range gpuInstanceClasses { + + if strings.HasPrefix(instanceType, instanceClass) { + return true + } } return false } diff --git a/ecs-cli/modules/clients/aws/amimetadata/client_test.go b/ecs-cli/modules/clients/aws/amimetadata/client_test.go index bafbd951c..07434f2ca 100644 --- a/ecs-cli/modules/clients/aws/amimetadata/client_test.go +++ b/ecs-cli/modules/clients/aws/amimetadata/client_test.go @@ -41,6 +41,17 @@ func TestMetadataClient_GetRecommendedECSLinuxAMI(t *testing.T) { }, nil, }, + { + // validate that we use GPU optimized AMI for GPU instances + "g4dn.xlarge", + func(ssmClient *mock_ssmiface.MockSSMAPI) *mock_ssmiface.MockSSMAPI { + ssmClient.EXPECT().GetParameter(gomock.Any()).Do(func(input *ssm.GetParameterInput) { + assert.Equal(t, amazonLinux2X86GPURecommendedParameterName, *input.Name) + }).Return(emptySSMParameterOutput(), nil) + return ssmClient + }, + nil, + }, { // validate that we use the generic AMI for other instances "t2.micro", diff --git a/ecs-cli/modules/clients/aws/cloudformation/cluster_template.go b/ecs-cli/modules/clients/aws/cloudformation/cluster_template.go index 335ea2253..c3bfa11f7 100644 --- a/ecs-cli/modules/clients/aws/cloudformation/cluster_template.go +++ b/ecs-cli/modules/clients/aws/cloudformation/cluster_template.go @@ -279,6 +279,12 @@ var clusterTemplate = ` "g3.4xlarge", "g3.8xlarge", "g3.16xlarge", + "g4dn.xlarge", + "g4dn.2xlarge", + "g4dn.4xlarge", + "g4dn.8xlarge", + "g4dn.12xlarge", + "g4dn.16xlarge", "p2.xlarge", "p2.8xlarge", "p2.16xlarge", From 9a6f7e8a69204574248af5da9d2395adee79f682 Mon Sep 17 00:00:00 2001 From: Yenlin Chen <3822365+hencrice@users.noreply.github.com> Date: Wed, 28 Aug 2019 14:28:22 -0700 Subject: [PATCH 13/19] feat(cicd): enable compilation through CodeBuild The logic to retrieve version number and the short git hash of the last commit are also modified so that they will be retrieved during compilation. --- RELEASE.md | 4 + buildspec.yml | 63 ++++++++++- ecs-cli/modules/version/formatter.go | 6 +- ecs-cli/modules/version/gen/version-gen.go | 123 --------------------- ecs-cli/modules/version/version.go | 19 ++-- 5 files changed, 75 insertions(+), 140 deletions(-) create mode 100644 RELEASE.md delete mode 100644 ecs-cli/modules/version/gen/version-gen.go diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 000000000..42ea22634 --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,4 @@ +TBD +=== + +Work in progress. \ No newline at end of file diff --git a/buildspec.yml b/buildspec.yml index 6d38c1754..e870a32a1 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -1,7 +1,66 @@ version: 0.2 phases: + install: + runtime-versions: + golang: 1.12 + pre_build: + commands: + # GOPATH is setup like the following in Codebuild standard 2.0 image + # /go:/codebuild/output/src + # so we copy all the source code to the appropriate location before + # invoking any go command + - echo "cd into $CODEBUILD_SRC_DIR" + - cd $CODEBUILD_SRC_DIR + - mkdir -p /go/src/github.com/aws/amazon-ecs-cli + - cp -R ./* /go/src/github.com/aws/amazon-ecs-cli/ + - ls -lah /go/src + # skip unit tests during PoC + # - | + # env -i PATH=$PATH GOPATH=`go env GOPATH` GOROOT=`go env GOROOT` GOCACHE=`go env GOCACHE` \ + # go test -race -v -cover github.com/aws/amazon-ecs-cli/ecs-cli/modules/... build: commands: - - make integ-test - - ./bin/local/ecs-cli.test \ No newline at end of file + - echo "Compilation context:" + - echo "CODEBUILD_SOURCE_VERSION=$CODEBUILD_SOURCE_VERSION" + # set the version number to the tag on HEAD or "development" if HEAD is + # not tagged + - VERSION=`git tag --points-at HEAD` + - | + if [ -z "$VERSION" ]; then + VERSION='development' + fi + - echo "VERSION=$VERSION" + - GIT_COMMIT_ID=`git rev-parse HEAD` + - echo "GIT_COMMIT_ID=$GIT_COMMIT_ID" + - GIT_SHORT_HASH=`git rev-parse --short=7 HEAD` + - echo "GIT_SHORT_HASH=$GIT_SHORT_HASH" + - echo "GOPATH=$GOPATH" + + - GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.Version=$VERSION -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.gitShortHash=$GIT_SHORT_HASH" -o aws/amazon-ecs-cli/ecs-cli-windows-amd64-$VERSION.exe github.com/aws/amazon-ecs-cli/ecs-cli/ + - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.Version=$VERSION -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.gitShortHash=$GIT_SHORT_HASH" -o aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION github.com/aws/amazon-ecs-cli/ecs-cli/ + - GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.Version=$VERSION -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.gitShortHash=$GIT_SHORT_HASH" -o aws/amazon-ecs-cli/ecs-cli-darwin-amd64-$VERSION github.com/aws/amazon-ecs-cli/ecs-cli/ + finally: + - echo "built artifacts:" + - ls -lah aws/amazon-ecs-cli/ + - ./aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION --version + post_build: + commands: + - echo "Creating latest artifacts..." + - cp aws/amazon-ecs-cli/ecs-cli-windows-amd64-$VERSION.exe aws/amazon-ecs-cli/ecs-cli-windows-amd64-latest.exe + - cp aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION aws/amazon-ecs-cli/ecs-cli-linux-amd64-latest + - cp aws/amazon-ecs-cli/ecs-cli-darwin-amd64-$VERSION aws/amazon-ecs-cli/ecs-cli-darwin-amd64-latest + - MANIFESTFILE="$GIT_COMMIT_ID.manifest" + - echo "aws/amazon-ecs-cli/ecs-cli-windows-amd64-$VERSION.exe" >> $MANIFESTFILE + - echo "aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION" >> $MANIFESTFILE + - echo "aws/amazon-ecs-cli/ecs-cli-darwin-amd64-$VERSION" >> $MANIFESTFILE + - echo "aws/amazon-ecs-cli/ecs-cli-windows-amd64-latest.exe" >> $MANIFESTFILE + - echo "aws/amazon-ecs-cli/ecs-cli-linux-amd64-latest" >> $MANIFESTFILE + - echo "aws/amazon-ecs-cli/ecs-cli-darwin-amd64-latest" >> $MANIFESTFILE + finally: + - ls -lah aws/amazon-ecs-cli/ +artifacts: + files: + - '**/*' + + diff --git a/ecs-cli/modules/version/formatter.go b/ecs-cli/modules/version/formatter.go index b7ff8d3fa..d59522214 100644 --- a/ecs-cli/modules/version/formatter.go +++ b/ecs-cli/modules/version/formatter.go @@ -15,9 +15,5 @@ package version // String produces a human-readable string showing the ecs-cli version. func String() string { - ret := Version + " (" - if GitDirty { - ret += "*" - } - return ret + GitShortHash + ")" + return Version + " (" + gitShortHash + ")" } diff --git a/ecs-cli/modules/version/gen/version-gen.go b/ecs-cli/modules/version/gen/version-gen.go deleted file mode 100644 index 8b38b119f..000000000 --- a/ecs-cli/modules/version/gen/version-gen.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"). You may -// not use this file except in compliance with the License. A copy of the -// License is located at -// -// http://aws.amazon.com/apache2.0/ -// -// or in the "license" file accompanying this file. This file is distributed -// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language governing -// permissions and limitations under the License. - -package main - -import ( - "io/ioutil" - "log" - "os" - "os/exec" - "path/filepath" - "strings" - "text/template" -) - -const versiongoTemplate = `// This is an autogenerated file and should not be edited. - -// Copyright 2015-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"). You may -// not use this file except in compliance with the License. A copy of the -// License is located at -// -// http://aws.amazon.com/apache2.0/ -// -// or in the "license" file accompanying this file. This file is distributed -// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language governing -// permissions and limitations under the License. - -// Package version contains constants to indicate the current version of the -// ecs-cli. It is autogenerated -package version - -// Please DO NOT commit any changes to this file (specifically the hash) except -// for those created by running ./scripts/update-version at the root of the -// repository. Only the 'Version' const should change in checked-in source code - -// Version is the version of the ECS CLI -const Version = "{{.Version}}" - -// GitDirty indicates the cleanliness of the git repo when this ecs-cli was built -const GitDirty = {{.Dirty}} - -// GitShortHash is the short hash of this ecs-cli build -const GitShortHash = "{{.Hash}}" -` - -type versionInfo struct { - Version string - Dirty bool - Hash string -} - -func gitDirty() bool { - cmd := exec.Command("git", "status", "--porcelain") - err := cmd.Run() - if err == nil { - return false - } - return true -} - -func gitHash() string { - cmd := exec.Command("git", "rev-parse", "--short=7", "HEAD") - hash, err := cmd.Output() - if err != nil { - return "UNKNOWN" - } - return strings.TrimSpace(string(hash)) -} - -// version-gen is a simple program that generates the ecs-cli's version file, -// containing information about the ecs-cli's version, commit hash, and repository -// cleanliness. -func main() { - - versionStr, err := ioutil.ReadFile(filepath.Join("..", "..", "..", "VERSION")) - if err != nil { - log.Fatal(err) - } - - // default values - info := versionInfo{ - Version: strings.TrimSpace(string(versionStr)), - Dirty: true, - Hash: "UNKNOWN", - } - - if strings.TrimSpace(os.Getenv("ECS_RELEASE")) == "cleanbuild" { - // 'clean' release; all other releases assumed dirty - info.Dirty = gitDirty() - } - if os.Getenv("ECS_UNKNOWN_VERSION") == "" { - // When the version file is updated, the above is set - // Setting UNKNOWN version allows the version committed in git to never - // have a commit hash so that it does not churn with every commit. This - // env var should not be set when building, and go generate should be - // run before any build, such that the commithash will be set correctly. - info.Hash = gitHash() - } - - outFile, err := os.Create("version.go") - if err != nil { - log.Fatalf("Unable to create output version file: %v", err) - } - t := template.Must(template.New("version").Parse(versiongoTemplate)) - - err = t.Execute(outFile, info) - if err != nil { - log.Fatalf("Error applying template: %v", err) - } -} diff --git a/ecs-cli/modules/version/version.go b/ecs-cli/modules/version/version.go index b82616add..79a214469 100644 --- a/ecs-cli/modules/version/version.go +++ b/ecs-cli/modules/version/version.go @@ -17,15 +17,14 @@ // ecs-cli. It is autogenerated package version -// Please DO NOT commit any changes to this file (specifically the hash) except -// for those created by running ./scripts/update-version at the root of the -// repository. Only the 'Version' const should change in checked-in source code +// Please DO NOT commit any changes to this file as these fields will be +// populated programmatically at compile time. -// Version is the version of the ECS CLI -const Version = "1.17.0" +// The version of the ECS CLI. Will be set at the compile time +// based on the tag of the latest commit on the `master` branch. If +// no tag exists, then the version will be set to "development" +var Version string -// GitDirty indicates the cleanliness of the git repo when this ecs-cli was built -const GitDirty = true - -// GitShortHash is the short hash of this ecs-cli build -const GitShortHash = "UNKNOWN" +// gitShortHash is the first 7 characters of the commit ID when the ECS CLI is +// compiled. +var gitShortHash string From 7ecca5d163cfa031b85df93db14a9abe18f2ae0d Mon Sep 17 00:00:00 2001 From: Yenlin Chen <3822365+hencrice@users.noreply.github.com> Date: Thu, 12 Sep 2019 14:27:13 -0700 Subject: [PATCH 14/19] chore: Inject build information When compiled locally on a contributor's computer with the Makefile, inject the version number, git dirty and git hash. --- buildspec.yml | 7 +++---- scripts/build_binary.sh | 14 +++----------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/buildspec.yml b/buildspec.yml index e870a32a1..2faac7b17 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -15,10 +15,9 @@ phases: - mkdir -p /go/src/github.com/aws/amazon-ecs-cli - cp -R ./* /go/src/github.com/aws/amazon-ecs-cli/ - ls -lah /go/src - # skip unit tests during PoC - # - | - # env -i PATH=$PATH GOPATH=`go env GOPATH` GOROOT=`go env GOROOT` GOCACHE=`go env GOCACHE` \ - # go test -race -v -cover github.com/aws/amazon-ecs-cli/ecs-cli/modules/... + - | + env -i PATH=$PATH GOPATH=`go env GOPATH` GOROOT=`go env GOROOT` GOCACHE=`go env GOCACHE` \ + go test -race -v -cover github.com/aws/amazon-ecs-cli/ecs-cli/modules/... build: commands: - echo "Compilation context:" diff --git a/scripts/build_binary.sh b/scripts/build_binary.sh index 1f71b637f..0deca28bc 100755 --- a/scripts/build_binary.sh +++ b/scripts/build_binary.sh @@ -19,15 +19,7 @@ cd "${ROOT}" # Builds the ecs-cli binary from source in the specified destination paths. mkdir -p $1 -# Versioning stuff. We run the generator to setup the version and then always -# restore ourselves to a clean state -cp ecs-cli/modules/version/version.go ecs-cli/modules/version/_version.go -trap "cd \"${ROOT}\"; mv ecs-cli/modules/version/_version.go ecs-cli/modules/version/version.go" EXIT SIGHUP SIGINT SIGTERM - -cd ./ecs-cli/modules/version/ -go run gen/version-gen.go - -cd "${ROOT}" - -GOOS=$TARGET_GOOS CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags '-s' -o $1/ecs-cli ./ecs-cli/ +GIT_DIRTY=`git diff --quiet || echo '*'` +GIT_SHORT_HASH="$GIT_DIRTY"`git rev-parse --short=7 HEAD` +GOOS=$TARGET_GOOS CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.Version=development -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.gitShortHash=$GIT_SHORT_HASH" -o $1/ecs-cli ./ecs-cli/ From ae14a5ec591eb5f86fab617517715f1e566f4727 Mon Sep 17 00:00:00 2001 From: Yenlin Chen <3822365+hencrice@users.noreply.github.com> Date: Tue, 5 Nov 2019 15:38:24 -0800 Subject: [PATCH 15/19] Updated the build script and buildspec to not show "development" as the version string when the commit is not tagged. --- buildspec.yml | 6 ------ ecs-cli/modules/version/formatter.go | 4 ++++ scripts/build_binary.sh | 6 +++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/buildspec.yml b/buildspec.yml index 2faac7b17..a22024993 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -22,13 +22,7 @@ phases: commands: - echo "Compilation context:" - echo "CODEBUILD_SOURCE_VERSION=$CODEBUILD_SOURCE_VERSION" - # set the version number to the tag on HEAD or "development" if HEAD is - # not tagged - VERSION=`git tag --points-at HEAD` - - | - if [ -z "$VERSION" ]; then - VERSION='development' - fi - echo "VERSION=$VERSION" - GIT_COMMIT_ID=`git rev-parse HEAD` - echo "GIT_COMMIT_ID=$GIT_COMMIT_ID" diff --git a/ecs-cli/modules/version/formatter.go b/ecs-cli/modules/version/formatter.go index d59522214..8bc1f7cb7 100644 --- a/ecs-cli/modules/version/formatter.go +++ b/ecs-cli/modules/version/formatter.go @@ -15,5 +15,9 @@ package version // String produces a human-readable string showing the ecs-cli version. func String() string { + if Version == "" { + // This can only happen when the CLI is built locally + return "(" + gitShortHash + ")" + } return Version + " (" + gitShortHash + ")" } diff --git a/scripts/build_binary.sh b/scripts/build_binary.sh index 0deca28bc..80a1caa8a 100755 --- a/scripts/build_binary.sh +++ b/scripts/build_binary.sh @@ -20,6 +20,10 @@ cd "${ROOT}" mkdir -p $1 GIT_DIRTY=`git diff --quiet || echo '*'` +VERSION=`git tag --points-at HEAD` GIT_SHORT_HASH="$GIT_DIRTY"`git rev-parse --short=7 HEAD` -GOOS=$TARGET_GOOS CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.Version=development -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.gitShortHash=$GIT_SHORT_HASH" -o $1/ecs-cli ./ecs-cli/ +GOOS=$TARGET_GOOS CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags \ +"-s -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.Version=$VERSION \ +-X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.gitShortHash=$GIT_SHORT_HASH" \ +-o $1/ecs-cli ./ecs-cli/ From 3fa691119c9562e91fffd087b7a2c8fc867645c1 Mon Sep 17 00:00:00 2001 From: Yenlin Chen <3822365+hencrice@users.noreply.github.com> Date: Wed, 6 Nov 2019 13:20:10 -0800 Subject: [PATCH 16/19] Decouple the part that sources the semantic version number from git tag from the rest of the CI/CD effort All changes to the version package were removed for now. --- VERSION | 2 +- buildspec.yml | 52 +++++---- ecs-cli/modules/version/formatter.go | 8 +- ecs-cli/modules/version/gen/version-gen.go | 123 +++++++++++++++++++++ ecs-cli/modules/version/version.go | 19 ++-- scripts/build_binary.sh | 18 +-- 6 files changed, 182 insertions(+), 40 deletions(-) create mode 100644 ecs-cli/modules/version/gen/version-gen.go diff --git a/VERSION b/VERSION index 092afa15d..73d74673c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.0 +1.17.0 \ No newline at end of file diff --git a/buildspec.yml b/buildspec.yml index a22024993..5e34aa138 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -3,42 +3,60 @@ version: 0.2 phases: install: runtime-versions: - golang: 1.12 + golang: 1.13 pre_build: commands: # GOPATH is setup like the following in Codebuild standard 2.0 image # /go:/codebuild/output/src # so we copy all the source code to the appropriate location before # invoking any go command - - echo "cd into $CODEBUILD_SRC_DIR" - - cd $CODEBUILD_SRC_DIR + - ls -lah - mkdir -p /go/src/github.com/aws/amazon-ecs-cli - - cp -R ./* /go/src/github.com/aws/amazon-ecs-cli/ - - ls -lah /go/src - - | - env -i PATH=$PATH GOPATH=`go env GOPATH` GOROOT=`go env GOROOT` GOCACHE=`go env GOCACHE` \ - go test -race -v -cover github.com/aws/amazon-ecs-cli/ecs-cli/modules/... + - cp -R . /go/src/github.com/aws/amazon-ecs-cli/ + # - | + # env -i PATH=$PATH GOPATH=`go env GOPATH` GOROOT=`go env GOROOT` GOCACHE=`go env GOCACHE` \ + # go test -race -v -cover github.com/aws/amazon-ecs-cli/ecs-cli/modules/... + # make a copy of the version.go because `go run gen/version-gen.go` will + # modify it. + - cp /go/src/github.com/aws/amazon-ecs-cli/ecs-cli/modules/version/version.go /go/src/github.com/aws/amazon-ecs-cli/ecs-cli/modules/version/_version.go + # need to cd into the version package because version-gen.go assumes the relative + # location of the VERSION file. + - cd /go/src/github.com/aws/amazon-ecs-cli/ecs-cli/modules/version/ + # since we are running the go program inside a Linux container, has to hardcode + # the GOOS and GOARCH correspondinly regardless of what the host OS is. + - GOOS=linux GOARCH=amd64 ECS_RELEASE=cleanbuild go run gen/version-gen.go build: commands: + - echo "cd into $CODEBUILD_SRC_DIR" + - cd $CODEBUILD_SRC_DIR - echo "Compilation context:" - echo "CODEBUILD_SOURCE_VERSION=$CODEBUILD_SOURCE_VERSION" - VERSION=`git tag --points-at HEAD` - echo "VERSION=$VERSION" - GIT_COMMIT_ID=`git rev-parse HEAD` - echo "GIT_COMMIT_ID=$GIT_COMMIT_ID" - - GIT_SHORT_HASH=`git rev-parse --short=7 HEAD` - - echo "GIT_SHORT_HASH=$GIT_SHORT_HASH" + # TODO: Get rid of the VERSION file after we fully switch to the new CI/CD + - CHECKED_IN_VERSION=`cat /go/src/github.com/aws/amazon-ecs-cli/VERSION` + - echo "VERSION_FILE=$CHECKED_IN_VERSION" - echo "GOPATH=$GOPATH" - - - GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.Version=$VERSION -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.gitShortHash=$GIT_SHORT_HASH" -o aws/amazon-ecs-cli/ecs-cli-windows-amd64-$VERSION.exe github.com/aws/amazon-ecs-cli/ecs-cli/ - - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.Version=$VERSION -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.gitShortHash=$GIT_SHORT_HASH" -o aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION github.com/aws/amazon-ecs-cli/ecs-cli/ - - GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.Version=$VERSION -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.gitShortHash=$GIT_SHORT_HASH" -o aws/amazon-ecs-cli/ecs-cli-darwin-amd64-$VERSION github.com/aws/amazon-ecs-cli/ecs-cli/ + - | + # $CHECKED_IN_VERSION is not prefixed with "v", only the semantic version number, + # such as 1.17.0 instead of v1.17.0, which is what normal version tags look like. + if [ "$VERSION" != "v$CHECKED_IN_VERSION" ]; then + echo "the VERSION file contains a version number that is different from the git tag. file: $CHECKED_IN_VERSION, tag: $VERSION" + exit 1 + fi + - GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s" -o aws/amazon-ecs-cli/ecs-cli-windows-amd64-$VERSION.exe github.com/aws/amazon-ecs-cli/ecs-cli/ + - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s" -o aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION github.com/aws/amazon-ecs-cli/ecs-cli/ + - GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s" -o aws/amazon-ecs-cli/ecs-cli-darwin-amd64-$VERSION github.com/aws/amazon-ecs-cli/ecs-cli/ finally: - echo "built artifacts:" - ls -lah aws/amazon-ecs-cli/ - ./aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION --version post_build: commands: + # restore the version file + - mv /go/src/github.com/aws/amazon-ecs-cli/ecs-cli/modules/version/_version.go /go/src/github.com/aws/amazon-ecs-cli/ecs-cli/modules/version/version.go - echo "Creating latest artifacts..." - cp aws/amazon-ecs-cli/ecs-cli-windows-amd64-$VERSION.exe aws/amazon-ecs-cli/ecs-cli-windows-amd64-latest.exe - cp aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION aws/amazon-ecs-cli/ecs-cli-linux-amd64-latest @@ -50,10 +68,6 @@ phases: - echo "aws/amazon-ecs-cli/ecs-cli-windows-amd64-latest.exe" >> $MANIFESTFILE - echo "aws/amazon-ecs-cli/ecs-cli-linux-amd64-latest" >> $MANIFESTFILE - echo "aws/amazon-ecs-cli/ecs-cli-darwin-amd64-latest" >> $MANIFESTFILE - finally: - - ls -lah aws/amazon-ecs-cli/ artifacts: files: - - '**/*' - - + - '**/*' \ No newline at end of file diff --git a/ecs-cli/modules/version/formatter.go b/ecs-cli/modules/version/formatter.go index 8bc1f7cb7..b7ff8d3fa 100644 --- a/ecs-cli/modules/version/formatter.go +++ b/ecs-cli/modules/version/formatter.go @@ -15,9 +15,9 @@ package version // String produces a human-readable string showing the ecs-cli version. func String() string { - if Version == "" { - // This can only happen when the CLI is built locally - return "(" + gitShortHash + ")" + ret := Version + " (" + if GitDirty { + ret += "*" } - return Version + " (" + gitShortHash + ")" + return ret + GitShortHash + ")" } diff --git a/ecs-cli/modules/version/gen/version-gen.go b/ecs-cli/modules/version/gen/version-gen.go new file mode 100644 index 000000000..8b38b119f --- /dev/null +++ b/ecs-cli/modules/version/gen/version-gen.go @@ -0,0 +1,123 @@ +// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package main + +import ( + "io/ioutil" + "log" + "os" + "os/exec" + "path/filepath" + "strings" + "text/template" +) + +const versiongoTemplate = `// This is an autogenerated file and should not be edited. + +// Copyright 2015-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +// Package version contains constants to indicate the current version of the +// ecs-cli. It is autogenerated +package version + +// Please DO NOT commit any changes to this file (specifically the hash) except +// for those created by running ./scripts/update-version at the root of the +// repository. Only the 'Version' const should change in checked-in source code + +// Version is the version of the ECS CLI +const Version = "{{.Version}}" + +// GitDirty indicates the cleanliness of the git repo when this ecs-cli was built +const GitDirty = {{.Dirty}} + +// GitShortHash is the short hash of this ecs-cli build +const GitShortHash = "{{.Hash}}" +` + +type versionInfo struct { + Version string + Dirty bool + Hash string +} + +func gitDirty() bool { + cmd := exec.Command("git", "status", "--porcelain") + err := cmd.Run() + if err == nil { + return false + } + return true +} + +func gitHash() string { + cmd := exec.Command("git", "rev-parse", "--short=7", "HEAD") + hash, err := cmd.Output() + if err != nil { + return "UNKNOWN" + } + return strings.TrimSpace(string(hash)) +} + +// version-gen is a simple program that generates the ecs-cli's version file, +// containing information about the ecs-cli's version, commit hash, and repository +// cleanliness. +func main() { + + versionStr, err := ioutil.ReadFile(filepath.Join("..", "..", "..", "VERSION")) + if err != nil { + log.Fatal(err) + } + + // default values + info := versionInfo{ + Version: strings.TrimSpace(string(versionStr)), + Dirty: true, + Hash: "UNKNOWN", + } + + if strings.TrimSpace(os.Getenv("ECS_RELEASE")) == "cleanbuild" { + // 'clean' release; all other releases assumed dirty + info.Dirty = gitDirty() + } + if os.Getenv("ECS_UNKNOWN_VERSION") == "" { + // When the version file is updated, the above is set + // Setting UNKNOWN version allows the version committed in git to never + // have a commit hash so that it does not churn with every commit. This + // env var should not be set when building, and go generate should be + // run before any build, such that the commithash will be set correctly. + info.Hash = gitHash() + } + + outFile, err := os.Create("version.go") + if err != nil { + log.Fatalf("Unable to create output version file: %v", err) + } + t := template.Must(template.New("version").Parse(versiongoTemplate)) + + err = t.Execute(outFile, info) + if err != nil { + log.Fatalf("Error applying template: %v", err) + } +} diff --git a/ecs-cli/modules/version/version.go b/ecs-cli/modules/version/version.go index 79a214469..b82616add 100644 --- a/ecs-cli/modules/version/version.go +++ b/ecs-cli/modules/version/version.go @@ -17,14 +17,15 @@ // ecs-cli. It is autogenerated package version -// Please DO NOT commit any changes to this file as these fields will be -// populated programmatically at compile time. +// Please DO NOT commit any changes to this file (specifically the hash) except +// for those created by running ./scripts/update-version at the root of the +// repository. Only the 'Version' const should change in checked-in source code -// The version of the ECS CLI. Will be set at the compile time -// based on the tag of the latest commit on the `master` branch. If -// no tag exists, then the version will be set to "development" -var Version string +// Version is the version of the ECS CLI +const Version = "1.17.0" -// gitShortHash is the first 7 characters of the commit ID when the ECS CLI is -// compiled. -var gitShortHash string +// GitDirty indicates the cleanliness of the git repo when this ecs-cli was built +const GitDirty = true + +// GitShortHash is the short hash of this ecs-cli build +const GitShortHash = "UNKNOWN" diff --git a/scripts/build_binary.sh b/scripts/build_binary.sh index 80a1caa8a..1f71b637f 100755 --- a/scripts/build_binary.sh +++ b/scripts/build_binary.sh @@ -19,11 +19,15 @@ cd "${ROOT}" # Builds the ecs-cli binary from source in the specified destination paths. mkdir -p $1 -GIT_DIRTY=`git diff --quiet || echo '*'` -VERSION=`git tag --points-at HEAD` -GIT_SHORT_HASH="$GIT_DIRTY"`git rev-parse --short=7 HEAD` -GOOS=$TARGET_GOOS CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags \ -"-s -X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.Version=$VERSION \ --X github.com/aws/amazon-ecs-cli/ecs-cli/modules/version.gitShortHash=$GIT_SHORT_HASH" \ --o $1/ecs-cli ./ecs-cli/ +# Versioning stuff. We run the generator to setup the version and then always +# restore ourselves to a clean state +cp ecs-cli/modules/version/version.go ecs-cli/modules/version/_version.go +trap "cd \"${ROOT}\"; mv ecs-cli/modules/version/_version.go ecs-cli/modules/version/version.go" EXIT SIGHUP SIGINT SIGTERM + +cd ./ecs-cli/modules/version/ +go run gen/version-gen.go + +cd "${ROOT}" + +GOOS=$TARGET_GOOS CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags '-s' -o $1/ecs-cli ./ecs-cli/ From 5f724dac6a5ba052571f50f9040dd4024eb94cd4 Mon Sep 17 00:00:00 2001 From: Yenlin Chen <3822365+hencrice@users.noreply.github.com> Date: Thu, 7 Nov 2019 15:29:44 -0800 Subject: [PATCH 17/19] removed the release note file since we will be using CHANGELOG.md --- RELEASE.md | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 RELEASE.md diff --git a/RELEASE.md b/RELEASE.md deleted file mode 100644 index 42ea22634..000000000 --- a/RELEASE.md +++ /dev/null @@ -1,4 +0,0 @@ -TBD -=== - -Work in progress. \ No newline at end of file From 239d9fb0ca97b22c75bc3d27dd412249f56642f7 Mon Sep 17 00:00:00 2001 From: Yenlin Chen <3822365+hencrice@users.noreply.github.com> Date: Mon, 11 Nov 2019 14:05:57 -0800 Subject: [PATCH 18/19] Make it actually run the unit tests --- buildspec.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildspec.yml b/buildspec.yml index 5e34aa138..461c61447 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -13,9 +13,9 @@ phases: - ls -lah - mkdir -p /go/src/github.com/aws/amazon-ecs-cli - cp -R . /go/src/github.com/aws/amazon-ecs-cli/ - # - | - # env -i PATH=$PATH GOPATH=`go env GOPATH` GOROOT=`go env GOROOT` GOCACHE=`go env GOCACHE` \ - # go test -race -v -cover github.com/aws/amazon-ecs-cli/ecs-cli/modules/... + - | + env -i PATH=$PATH GOPATH=`go env GOPATH` GOROOT=`go env GOROOT` GOCACHE=`go env GOCACHE` \ + go test -race -v -cover github.com/aws/amazon-ecs-cli/ecs-cli/modules/... # make a copy of the version.go because `go run gen/version-gen.go` will # modify it. - cp /go/src/github.com/aws/amazon-ecs-cli/ecs-cli/modules/version/version.go /go/src/github.com/aws/amazon-ecs-cli/ecs-cli/modules/version/_version.go From a44661c237b3dac9ff561750fa40acee8fb7a672 Mon Sep 17 00:00:00 2001 From: Austin Ely Date: Fri, 8 Nov 2019 15:57:41 -0800 Subject: [PATCH 19/19] Bump version to v1.18.0 --- CHANGELOG.md | 8 ++++++++ VERSION | 2 +- ecs-cli/modules/version/version.go | 2 +- scripts/publish-staged | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6153ef83..07b83ef90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 1.18.0 +* Enhancement - Print verbose messages for credential chain errors (#937) +* Enhancement - Add G4 instance support (#940) +* Enhancement - Add more descriptive logging to integ tests (#931) +* Bug - Pull correct AMI type for G3 instance types. (#940) +* Bug - Send optional fields as nil instead of "" to ECS (#938) +* Bug - ecs-cli local up can now read from parameter store when forward slashes exist in parameter name (#935) + ## 1.17.0 * Feature - Add support for Firelens (#924) * Bug - Remove spurious log warning (#926) diff --git a/VERSION b/VERSION index 73d74673c..744068368 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.0 \ No newline at end of file +1.18.0 \ No newline at end of file diff --git a/ecs-cli/modules/version/version.go b/ecs-cli/modules/version/version.go index b82616add..7b5044a17 100644 --- a/ecs-cli/modules/version/version.go +++ b/ecs-cli/modules/version/version.go @@ -22,7 +22,7 @@ package version // repository. Only the 'Version' const should change in checked-in source code // Version is the version of the ECS CLI -const Version = "1.17.0" +const Version = "1.18.0" // GitDirty indicates the cleanliness of the git repo when this ecs-cli was built const GitDirty = true diff --git a/scripts/publish-staged b/scripts/publish-staged index 211fddf1a..e3035a176 100755 --- a/scripts/publish-staged +++ b/scripts/publish-staged @@ -43,7 +43,7 @@ usage() { } publish_s3() { - for tag in ${ARTIFACT_TAG_VERSION} ${ARTIFACT_TAG_SHA} ${ARTIFACT_TAG_LATEST}; do + for tag in ${ARTIFACT_TAG_VERSION} ${ARTIFACT_TAG_LATEST}; do echo "Publishing as ecs-cli-linux-amd64-${tag}" dexec s3_pull_push "s3://${STAGE_S3_BUCKET}/ecs-cli-linux-amd64-${tag}" "s3://${PUBLISH_S3_BUCKET}/ecs-cli-linux-amd64-${tag}" dexec s3_pull_push "s3://${STAGE_S3_BUCKET}/ecs-cli-linux-amd64-${tag}.md5" "s3://${PUBLISH_S3_BUCKET}/ecs-cli-linux-amd64-${tag}.md5"