Skip to content

Commit 2aa7018

Browse files
Revert "Derive version in agent, ecs-init, and .rpm/.deb packages from the toplevel VERSION file #4423"; Update agent to 1.89.0
1 parent 1834778 commit 2aa7018

File tree

14 files changed

+228
-54
lines changed

14 files changed

+228
-54
lines changed

Makefile

+9-5
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ else
3030
GO_VERSION=$(shell cat ./GO_VERSION)
3131
endif
3232

33-
VERSION=$(shell cat VERSION)
34-
3533
export GO111MODULE=auto
3634

3735
all: docker
@@ -401,6 +399,7 @@ get-deps-init:
401399
GO111MODULE=on go install honnef.co/go/tools/cmd/staticcheck@v0.4.0
402400

403401
amazon-linux-sources.tgz:
402+
./scripts/update-version.sh
404403
cp packaging/amazon-linux-ami-integrated/ecs-agent.spec ecs-agent.spec
405404
cp packaging/amazon-linux-ami-integrated/ecs.conf ecs.conf
406405
cp packaging/amazon-linux-ami-integrated/ecs.service ecs.service
@@ -411,14 +410,15 @@ amazon-linux-sources.tgz:
411410

412411
.amazon-linux-rpm-integrated-done: amazon-linux-sources.tgz
413412
test -e SOURCES || ln -s . SOURCES
414-
rpmbuild --define "%version ${VERSION}" --define "%_topdir $(PWD)" -bb ecs-agent.spec
413+
rpmbuild --define "%_topdir $(PWD)" -bb ecs-agent.spec
415414
find RPMS/ -type f -exec cp {} . \;
416415
touch .amazon-linux-rpm-integrated-done
417416

418417
amazon-linux-rpm-integrated: .amazon-linux-rpm-integrated-done
419418

420419
# Make target for Amazon Linux Codebuild jobs
421420
.amazon-linux-rpm-codebuild-done: get-cni-sources
421+
./scripts/update-version.sh
422422
cp packaging/amazon-linux-ami-integrated/ecs-agent.spec ecs-agent.spec
423423
cp packaging/amazon-linux-ami-integrated/ecs.conf ecs.conf
424424
cp packaging/amazon-linux-ami-integrated/ecs.service ecs.service
@@ -427,27 +427,31 @@ amazon-linux-rpm-integrated: .amazon-linux-rpm-integrated-done
427427
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
428428
tar -czf ./sources.tgz ecs-init scripts misc agent amazon-ecs-cni-plugins amazon-vpc-cni-plugins agent-container Makefile VERSION GO_VERSION
429429
test -e SOURCES || ln -s . SOURCES
430-
rpmbuild --define "%version ${VERSION}" --define "%_topdir $(PWD)" -bb ecs-agent.spec
430+
rpmbuild --define "%_topdir $(PWD)" -bb ecs-agent.spec
431431
find RPMS/ -type f -exec cp {} . \;
432432
touch .amazon-linux-rpm-codebuild-done
433433

434434
amazon-linux-rpm-codebuild: .amazon-linux-rpm-codebuild-done
435435

436436
.generic-rpm-integrated-done: get-cni-sources
437+
./scripts/update-version.sh
437438
cp packaging/generic-rpm-integrated/amazon-ecs-init.spec amazon-ecs-init.spec
438439
cp packaging/generic-rpm-integrated/ecs.service ecs.service
439440
cp packaging/generic-rpm-integrated/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
440441
cp packaging/generic-rpm-integrated/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
441442
tar -czf ./sources.tgz ecs-init scripts misc agent amazon-ecs-cni-plugins amazon-vpc-cni-plugins agent-container Makefile VERSION GO_VERSION
442443
test -e SOURCES || ln -s . SOURCES
443-
rpmbuild --define "%version ${VERSION}" --define "%_topdir $(PWD)" -bb amazon-ecs-init.spec
444+
rpmbuild --define "%_topdir $(PWD)" -bb amazon-ecs-init.spec
444445
find RPMS/ -type f -exec cp {} . \;
445446
touch .generic-rpm-integrated-done
446447

447448
# Build init rpm
448449
generic-rpm-integrated: .generic-rpm-integrated-done
449450

451+
VERSION = $(shell cat ecs-init/ECSVERSION)
452+
450453
.generic-deb-integrated-done: get-cni-sources
454+
./scripts/update-version.sh
451455
mkdir -p BUILDROOT
452456
tar -czf ./amazon-ecs-init_${VERSION}.orig.tar.gz ecs-init scripts README.md
453457
cp -r packaging/generic-deb-integrated/debian Makefile ecs-init scripts misc agent agent-container amazon-ecs-cni-plugins amazon-vpc-cni-plugins README.md VERSION GO_VERSION BUILDROOT

scripts/version-gen.go renamed to agent/version/gen/version-gen.go

+19-22
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,27 @@ const versiongoTemplate = `// This is an autogenerated file and should not be ed
3939
// permissions and limitations under the License.
4040
4141
// Package version contains constants to indicate the current version of the
42-
// {{.Package}}. It is autogenerated
42+
// agent. It is autogenerated
4343
package version
4444
4545
// Please DO NOT commit any changes to this file (specifically the hash) except
46-
// for those created by running 'go run scripts/version-gen.go' at the root of the
46+
// for those created by running ./scripts/update-version at the root of the
4747
// repository. Only the 'Version' const should change in checked-in source code
4848
49-
// Version is the version of {{.Package}}
49+
// Version is the version of the Agent
5050
const Version = "{{.Version}}"
5151
52-
// GitDirty indicates the cleanliness of the git repo when this {{.Package}} was built
52+
// GitDirty indicates the cleanliness of the git repo when this agent was built
5353
const GitDirty = {{.Dirty}}
5454
55-
// GitShortHash is the short hash of this {{.Package}} build
55+
// GitShortHash is the short hash of this agent build
5656
const GitShortHash = "{{.Hash}}"
5757
`
5858

5959
type versionInfo struct {
6060
Version string
6161
Dirty bool
6262
Hash string
63-
Package string
6463
}
6564

6665
func gitDirty() bool {
@@ -83,7 +82,7 @@ func gitHash() string {
8382
}
8483

8584
func releaseCommitGitHash() (string, error) {
86-
fullHash, err := os.ReadFile(filepath.Join("..", "RELEASE_COMMIT"))
85+
fullHash, err := os.ReadFile(filepath.Join("..", "..", "RELEASE_COMMIT"))
8786
if err != nil {
8887
return "", fmt.Errorf("unable to read RELEASE_COMMIT file, err: %v", err)
8988
}
@@ -105,10 +104,12 @@ func selectGitHash() string {
105104
return hash
106105
}
107106

108-
// version-gen is a simple program that generates version files in the agent and ecs-init go modules.
109-
// It contains information about the agent's version, commit hash, and repository cleanliness.
107+
// version-gen is a simple program that generates the agent's version file,
108+
// containing information about the agent's version, commit hash, and repository
109+
// cleanliness.
110110
func main() {
111-
versionStr, _ := os.ReadFile("VERSION")
111+
112+
versionStr, _ := os.ReadFile(filepath.Join("..", "..", "VERSION"))
112113

113114
// default values
114115
info := versionInfo{
@@ -130,18 +131,14 @@ func main() {
130131
info.Hash = selectGitHash()
131132
}
132133

133-
for _, dir := range []string{"agent", "ecs-init"} {
134-
info.Package = dir
135-
136-
outFile, err := os.Create(filepath.Join(dir, "version", "version.go"))
137-
if err != nil {
138-
log.Fatalf("Unable to create output version file: %v", err)
139-
}
140-
t := template.Must(template.New("version").Parse(versiongoTemplate))
134+
outFile, err := os.Create("version.go")
135+
if err != nil {
136+
log.Fatalf("Unable to create output version file: %v", err)
137+
}
138+
t := template.Must(template.New("version").Parse(versiongoTemplate))
141139

142-
err = t.Execute(outFile, info)
143-
if err != nil {
144-
log.Fatalf("Error applying template: %v", err)
145-
}
140+
err = t.Execute(outFile, info)
141+
if err != nil {
142+
log.Fatalf("Error applying template: %v", err)
146143
}
147144
}

agent/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package version
1919

2020
// Please DO NOT commit any changes to this file (specifically the hash) except
21-
// for those created by running 'go run scripts/version-gen.go' at the root of the
21+
// for those created by running ./scripts/update-version at the root of the
2222
// repository. Only the 'Version' const should change in checked-in source code
2323

2424
// Version is the version of agent

ecs-init/ECSVERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.89.0

ecs-init/config/common.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"strings"
2323

2424
"github.com/aws/amazon-ecs-agent/ecs-init/config/awsrulesfn"
25-
"github.com/aws/amazon-ecs-agent/ecs-init/version"
2625
"github.com/cihub/seelog"
2726
godocker "github.com/fsouza/go-dockerclient"
2827
"github.com/pkg/errors"
@@ -43,6 +42,11 @@ const (
4342
// Used to mount /proc for agent container
4443
ProcFS = "/proc"
4544

45+
// DefaultAgentVersion is the version of the agent that will be
46+
// fetched if required. This should look like v1.2.3 or an
47+
// 8-character sha, as is downloadable from S3.
48+
DefaultAgentVersion = "v1.89.0"
49+
4650
// AgentPartitionBucketName is the name of the paritional s3 bucket that stores the agent
4751
AgentPartitionBucketName = "amazon-ecs-agent"
4852

@@ -106,11 +110,6 @@ const (
106110
ECSAgentAppArmorDefaultProfileName = "ecs-agent-default"
107111
)
108112

109-
// DefaultAgentVersion is the version of the agent that will be
110-
// fetched if required. This should look like v1.2.3 or an
111-
// 8-character sha, as is downloadable from S3.
112-
var DefaultAgentVersion = "v" + version.Version
113-
114113
// partitionBucketRegion provides the "partitional" bucket region
115114
// suitable for downloading agent from.
116115
var partitionBucketRegion = map[string]string{

ecs-init/version/formatting.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import "fmt"
1818
// String construct the version info of ecs-init
1919
func String() string {
2020
dirtyMark := ""
21-
if GitDirty {
21+
// Note that GitDirty is defined via command-line linker flags, so
22+
// it must be a string rather than a bool
23+
if GitDirty == "true" {
2224
dirtyMark = "*"
2325
}
2426
return fmt.Sprintf("ecs-init version %s (%s%s)", Version, dirtyMark, GitShortHash)

ecs-init/version/version.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is an autogenerated file and should not be edited.
22

3-
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
// Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License"). You may
66
// not use this file except in compliance with the License. A copy of the
@@ -14,18 +14,14 @@
1414
// permissions and limitations under the License.
1515

1616
// Package version contains constants to indicate the current version of the
17-
// ecs-init. It is autogenerated
17+
// ecs-init. It is autogenerated.
1818
package version
1919

20-
// Please DO NOT commit any changes to this file (specifically the hash) except
21-
// for those created by running 'go run scripts/version-gen.go' at the root of the
22-
// repository. Only the 'Version' const should change in checked-in source code
23-
24-
// Version is the version of ecs-init
25-
const Version = "1.89.0"
20+
// Version is the version of the ecs-init
21+
var Version string = "1.63.0"
2622

2723
// GitDirty indicates the cleanliness of the git repo when this ecs-init was built
28-
const GitDirty = true
24+
var GitDirty string = "true"
2925

3026
// GitShortHash is the short hash of this ecs-init build
31-
const GitShortHash = "4843cd00"
27+
var GitShortHash string = "0be4d2e1"

packaging/amazon-linux-ami-integrated/ecs-agent.spec

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
%global agent_image ecs-agent-v%{version}.tar
2727

2828
Name: ecs-init
29-
Version: %{version}
29+
Version: 1.89.0
3030
Release: 1%{?dist}
3131
License: Apache 2.0
3232
Summary: Amazon Elastic Container Service initialization application

packaging/generic-rpm-integrated/amazon-ecs-init.spec

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
%global agent_image ecs-agent-v%{version}.tar
2020

2121
Name: amazon-ecs-init
22-
Version: %{version}
22+
Version: 1.89.0
2323
Release: 1
2424
License: Apache 2.0
2525
Summary: Amazon Elastic Container Service initialization application

scripts/build

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ if [[ "${version_gen}" == "true" ]]; then
6262
cp agent/version/version.go agent/version/_version.go
6363
trap "cd \"${ROOT}\"; mv agent/version/_version.go agent/version/version.go" EXIT SIGHUP SIGINT SIGTERM
6464

65+
cd ./agent/version/
6566
# Turn off go module here because version-gen.go is a separate program (i.e. "package main")
6667
# and no dependency needed to be fetched (but if go mod is on it will try to fetch dependency causing
6768
# this script to fail when we run it in a container with network mode "none").
6869
echo "running version gen"
69-
GO111MODULE=off go run scripts/version-gen.go
70+
GO111MODULE=off go run gen/version-gen.go
7071
fi
7172

7273
if [[ "${with_pause}" == "true" ]]; then

scripts/gobuild-agent-init

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the
5+
# "License"). You may not use this file except in compliance
6+
# with the License. A copy of the License is located at
7+
#
8+
# http://aws.amazon.com/apache2.0/
9+
#
10+
# or in the "license" file accompanying this file. This file is
11+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
# CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and
14+
# limitations under the License.
15+
set -x
16+
set -e
17+
export TOPWD="$(pwd)"
18+
export BUILDDIR="$(mktemp -d)"
19+
export SRCPATH="${BUILDDIR}/src/github.com/aws/amazon-ecs-agent"
20+
export GITPATH="${BUILDDIR}/src/github.com/aws"
21+
export GO111MODULE="auto"
22+
23+
if [ -d "${TOPWD}/.git" ]; then
24+
version=$(cat "${TOPWD}/ecs-init/ECSVERSION")
25+
git_hash=$(git rev-parse --short=8 HEAD)
26+
git_dirty=false
27+
28+
if [[ "$(git status --porcelain)" != "" ]]; then
29+
git_dirty=true
30+
fi
31+
32+
VERSION_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.Version=${version}"
33+
GIT_HASH_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.GitShortHash=${git_hash}"
34+
GIT_DIRTY_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.GitDirty=${git_dirty}"
35+
fi
36+
37+
# build cni-plugins
38+
mkdir -p "${GITPATH}"
39+
ls "${TOPWD}"
40+
ln -s "${TOPWD}/amazon-ecs-cni-plugins" "${GITPATH}"
41+
cd "${GITPATH}/amazon-ecs-cni-plugins" && make plugins
42+
mkdir -p ${SRCPATH}/misc/plugins && cp -a ./bin/plugins/. ${SRCPATH}/misc/plugins
43+
ls ${SRCPATH}/misc/plugins
44+
45+
mkdir -p "{SRCPATH}"
46+
ln -s "${TOPWD}/amazon-ecs-volume-plugin" "${SRCPATH}"
47+
cd "${SRCPATH}"
48+
CGO_ENABLED=0 go build -x -ldflags "-s ${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
49+
-o "${SRCPATH}/amazon-ecs-volume-plugin" "${SRCPATH}/volumes/amazon-ecs-volume-plugin"
50+
rm -r "${BUILDDIR}"
51+
52+
mkdir -p "${SRCPATH}"
53+
ln -s "${TOPWD}/ecs-init" "${SRCPATH}"
54+
cd "${SRCPATH}/ecs-init"

scripts/gobuild.sh

+19-6
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,35 @@ export GO111MODULE="auto"
2424
# if it's already installed the script will set env vars and exit
2525
source ./scripts/install-golang.sh
2626

27-
# regenerate version files for accurate version info
28-
go run scripts/version-gen.go
27+
if [ -d "${TOPWD}/.git" ]; then
28+
version=$(cat "${TOPWD}/ecs-init/ECSVERSION")
29+
git_hash=$(git rev-parse --short=8 HEAD)
30+
git_dirty=false
31+
32+
if [[ "$(git status --porcelain)" != "" ]]; then
33+
git_dirty=true
34+
fi
35+
36+
VERSION_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.Version=${version}"
37+
GIT_HASH_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.GitShortHash=${git_hash}"
38+
GIT_DIRTY_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.GitDirty=${git_dirty}"
39+
fi
2940

3041
mkdir -p "${SRCPATH}"
3142
ln -s "${TOPWD}/ecs-init" "${SRCPATH}"
3243
cd "${SRCPATH}/ecs-init"
3344
if [[ "$1" == "dev" ]]; then
34-
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build \
35-
-o "${TOPWD}/amazon-ecs-init"
45+
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build -ldflags "${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
46+
-o "${TOPWD}/amazon-ecs-init"
3647
else
3748
tags=""
3849
if [[ "$1" != "" ]]; then
3950
tags="-tags '$1'"
4051
fi
4152
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build -a ${tags} -x \
42-
-o "${TOPWD}/amazon-ecs-init"
53+
-ldflags "-s ${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
54+
-o "${TOPWD}/amazon-ecs-init"
4355
fi
44-
CGO_ENABLED=0 go build -x -o "${TOPWD}/amazon-ecs-volume-plugin" "./volumes/amazon-ecs-volume-plugin"
56+
CGO_ENABLED=0 go build -x -ldflags "-s ${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
57+
-o "${TOPWD}/amazon-ecs-volume-plugin" "./volumes/amazon-ecs-volume-plugin"
4558
rm -r "${BUILDDIR}"

scripts/update-version

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -e
3+
4+
version=${1:?Must specify version as the only argument (e.g. 1.0.0)}
5+
6+
# Normalize to working directory being build root (up one level from ./scripts)
7+
ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )
8+
cd "${ROOT}"
9+
10+
echo -n "$version" > VERSION
11+
export ECS_UNKNOWN_VERSION=true
12+
13+
cd ./agent/version/
14+
# Turn off go module for version-gen.go - see scripts/build.
15+
GO111MODULE=off go run gen/version-gen.go
16+
cd "${ROOT}"
17+
18+
git add agent/version/version.go VERSION
19+
20+
# TODO, the changelog bump could also be automated
21+
echo "Please edit the changelog and commit the version bump"

0 commit comments

Comments
 (0)