Skip to content

Commit 12cb750

Browse files
authored
Derive version in agent, ecs-init, and .rpm/.deb packages from the toplevel VERSION file (#4423)
1 parent ef99c22 commit 12cb750

File tree

13 files changed

+55
-228
lines changed

13 files changed

+55
-228
lines changed

Makefile

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

33+
VERSION=$(shell cat VERSION)
34+
3335
export GO111MODULE=auto
3436

3537
all: docker
@@ -390,7 +392,6 @@ get-deps-init:
390392
GO111MODULE=on go install honnef.co/go/tools/cmd/[email protected]
391393

392394
amazon-linux-sources.tgz:
393-
./scripts/update-version.sh
394395
cp packaging/amazon-linux-ami-integrated/ecs-agent.spec ecs-agent.spec
395396
cp packaging/amazon-linux-ami-integrated/ecs.conf ecs.conf
396397
cp packaging/amazon-linux-ami-integrated/ecs.service ecs.service
@@ -401,15 +402,14 @@ amazon-linux-sources.tgz:
401402

402403
.amazon-linux-rpm-integrated-done: amazon-linux-sources.tgz
403404
test -e SOURCES || ln -s . SOURCES
404-
rpmbuild --define "%_topdir $(PWD)" -bb ecs-agent.spec
405+
rpmbuild --define "%version ${VERSION}" --define "%_topdir $(PWD)" -bb ecs-agent.spec
405406
find RPMS/ -type f -exec cp {} . \;
406407
touch .amazon-linux-rpm-integrated-done
407408

408409
amazon-linux-rpm-integrated: .amazon-linux-rpm-integrated-done
409410

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

425425
amazon-linux-rpm-codebuild: .amazon-linux-rpm-codebuild-done
426426

427427
.generic-rpm-integrated-done: get-cni-sources
428-
./scripts/update-version.sh
429428
cp packaging/generic-rpm-integrated/amazon-ecs-init.spec amazon-ecs-init.spec
430429
cp packaging/generic-rpm-integrated/ecs.service ecs.service
431430
cp packaging/generic-rpm-integrated/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
432431
cp packaging/generic-rpm-integrated/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
433432
tar -czf ./sources.tgz ecs-init scripts misc agent amazon-ecs-cni-plugins amazon-vpc-cni-plugins agent-container Makefile VERSION GO_VERSION
434433
test -e SOURCES || ln -s . SOURCES
435-
rpmbuild --define "%_topdir $(PWD)" -bb amazon-ecs-init.spec
434+
rpmbuild --define "%version ${VERSION}" --define "%_topdir $(PWD)" -bb amazon-ecs-init.spec
436435
find RPMS/ -type f -exec cp {} . \;
437436
touch .generic-rpm-integrated-done
438437

439438
# Build init rpm
440439
generic-rpm-integrated: .generic-rpm-integrated-done
441440

442-
VERSION = $(shell cat ecs-init/ECSVERSION)
443-
444441
.generic-deb-integrated-done: get-cni-sources
445-
./scripts/update-version.sh
446442
mkdir -p BUILDROOT
447443
tar -czf ./amazon-ecs-init_${VERSION}.orig.tar.gz ecs-init scripts README.md
448444
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

agent/version/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
package version
1919

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

24-
// Version is the version of the Agent
24+
// Version is the version of agent
2525
const Version = "1.88.0"
2626

2727
// GitDirty indicates the cleanliness of the git repo when this agent was built

ecs-init/config/common.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ 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"
2526
"github.com/cihub/seelog"
2627
godocker "github.com/fsouza/go-dockerclient"
2728
"github.com/pkg/errors"
@@ -42,11 +43,6 @@ const (
4243
// Used to mount /proc for agent container
4344
ProcFS = "/proc"
4445

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.88.0"
49-
5046
// AgentPartitionBucketName is the name of the paritional s3 bucket that stores the agent
5147
AgentPartitionBucketName = "amazon-ecs-agent"
5248

@@ -110,6 +106,11 @@ const (
110106
ECSAgentAppArmorDefaultProfileName = "ecs-agent-default"
111107
)
112108

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+
113114
// partitionBucketRegion provides the "partitional" bucket region
114115
// suitable for downloading agent from.
115116
var partitionBucketRegion = map[string]string{

ecs-init/version/formatting.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import "fmt"
1818
// String construct the version info of ecs-init
1919
func String() string {
2020
dirtyMark := ""
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" {
21+
if GitDirty {
2422
dirtyMark = "*"
2523
}
2624
return fmt.Sprintf("ecs-init version %s (%s%s)", Version, dirtyMark, GitShortHash)

ecs-init/version/version.go

Lines changed: 10 additions & 6 deletions
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 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
// Copyright 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,14 +14,18 @@
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-
// Version is the version of the ecs-init
21-
var Version string = "1.63.0"
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.88.0"
2226

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

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

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

Lines changed: 1 addition & 1 deletion
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: 1.88.0
29+
Version: %{version}
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

Lines changed: 1 addition & 1 deletion
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: 1.88.0
22+
Version: %{version}
2323
Release: 1
2424
License: Apache 2.0
2525
Summary: Amazon Elastic Container Service initialization application

scripts/build

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ 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/
6665
# Turn off go module here because version-gen.go is a separate program (i.e. "package main")
6766
# and no dependency needed to be fetched (but if go mod is on it will try to fetch dependency causing
6867
# this script to fail when we run it in a container with network mode "none").
6968
echo "running version gen"
70-
GO111MODULE=off go run gen/version-gen.go
69+
GO111MODULE=off go run scripts/version-gen.go
7170
fi
7271

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

scripts/gobuild-agent-init

Lines changed: 0 additions & 54 deletions
This file was deleted.

scripts/gobuild.sh

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,22 @@ 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-
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
27+
# regenerate version files for accurate version info
28+
go run scripts/version-gen.go
4029

4130
mkdir -p "${SRCPATH}"
4231
ln -s "${TOPWD}/ecs-init" "${SRCPATH}"
4332
cd "${SRCPATH}/ecs-init"
4433
if [[ "$1" == "dev" ]]; then
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"
34+
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build \
35+
-o "${TOPWD}/amazon-ecs-init"
4736
else
4837
tags=""
4938
if [[ "$1" != "" ]]; then
5039
tags="-tags '$1'"
5140
fi
5241
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build -a ${tags} -x \
53-
-ldflags "-s ${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
54-
-o "${TOPWD}/amazon-ecs-init"
42+
-o "${TOPWD}/amazon-ecs-init"
5543
fi
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"
44+
CGO_ENABLED=0 go build -x -o "${TOPWD}/amazon-ecs-volume-plugin" "./volumes/amazon-ecs-volume-plugin"
5845
rm -r "${BUILDDIR}"

0 commit comments

Comments
 (0)