Skip to content

Commit

Permalink
Revert "Derive version in agent, ecs-init, and .rpm/.deb packages fro…
Browse files Browse the repository at this point in the history
…m the toplevel VERSION file #4423"; Update agent to 1.89.0
  • Loading branch information
prateekchaudhry committed Nov 19, 2024
1 parent 1834778 commit 2aa7018
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 54 deletions.
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ else
GO_VERSION=$(shell cat ./GO_VERSION)
endif

VERSION=$(shell cat VERSION)

export GO111MODULE=auto

all: docker
Expand Down Expand Up @@ -401,6 +399,7 @@ get-deps-init:
GO111MODULE=on go install honnef.co/go/tools/cmd/[email protected]

amazon-linux-sources.tgz:
./scripts/update-version.sh
cp packaging/amazon-linux-ami-integrated/ecs-agent.spec ecs-agent.spec
cp packaging/amazon-linux-ami-integrated/ecs.conf ecs.conf
cp packaging/amazon-linux-ami-integrated/ecs.service ecs.service
Expand All @@ -411,14 +410,15 @@ amazon-linux-sources.tgz:

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

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

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

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

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

# Build init rpm
generic-rpm-integrated: .generic-rpm-integrated-done

VERSION = $(shell cat ecs-init/ECSVERSION)

.generic-deb-integrated-done: get-cni-sources
./scripts/update-version.sh
mkdir -p BUILDROOT
tar -czf ./amazon-ecs-init_${VERSION}.orig.tar.gz ecs-init scripts README.md
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
Expand Down
41 changes: 19 additions & 22 deletions scripts/version-gen.go → agent/version/gen/version-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,27 @@ const versiongoTemplate = `// This is an autogenerated file and should not be ed
// permissions and limitations under the License.
// Package version contains constants to indicate the current version of the
// {{.Package}}. It is autogenerated
// agent. It is autogenerated
package version
// Please DO NOT commit any changes to this file (specifically the hash) except
// for those created by running 'go run scripts/version-gen.go' at the root of the
// 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 {{.Package}}
// Version is the version of the Agent
const Version = "{{.Version}}"
// GitDirty indicates the cleanliness of the git repo when this {{.Package}} was built
// GitDirty indicates the cleanliness of the git repo when this agent was built
const GitDirty = {{.Dirty}}
// GitShortHash is the short hash of this {{.Package}} build
// GitShortHash is the short hash of this agent build
const GitShortHash = "{{.Hash}}"
`

type versionInfo struct {
Version string
Dirty bool
Hash string
Package string
}

func gitDirty() bool {
Expand All @@ -83,7 +82,7 @@ func gitHash() string {
}

func releaseCommitGitHash() (string, error) {
fullHash, err := os.ReadFile(filepath.Join("..", "RELEASE_COMMIT"))
fullHash, err := os.ReadFile(filepath.Join("..", "..", "RELEASE_COMMIT"))
if err != nil {
return "", fmt.Errorf("unable to read RELEASE_COMMIT file, err: %v", err)
}
Expand All @@ -105,10 +104,12 @@ func selectGitHash() string {
return hash
}

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

versionStr, _ := os.ReadFile(filepath.Join("..", "..", "VERSION"))

// default values
info := versionInfo{
Expand All @@ -130,18 +131,14 @@ func main() {
info.Hash = selectGitHash()
}

for _, dir := range []string{"agent", "ecs-init"} {
info.Package = dir

outFile, err := os.Create(filepath.Join(dir, "version", "version.go"))
if err != nil {
log.Fatalf("Unable to create output version file: %v", err)
}
t := template.Must(template.New("version").Parse(versiongoTemplate))
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)
}
err = t.Execute(outFile, info)
if err != nil {
log.Fatalf("Error applying template: %v", err)
}
}
2 changes: 1 addition & 1 deletion agent/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package version

// Please DO NOT commit any changes to this file (specifically the hash) except
// for those created by running 'go run scripts/version-gen.go' at the root of the
// 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 agent
Expand Down
1 change: 1 addition & 0 deletions ecs-init/ECSVERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.89.0
11 changes: 5 additions & 6 deletions ecs-init/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"strings"

"github.com/aws/amazon-ecs-agent/ecs-init/config/awsrulesfn"
"github.com/aws/amazon-ecs-agent/ecs-init/version"
"github.com/cihub/seelog"
godocker "github.com/fsouza/go-dockerclient"
"github.com/pkg/errors"
Expand All @@ -43,6 +42,11 @@ const (
// Used to mount /proc for agent container
ProcFS = "/proc"

// DefaultAgentVersion is the version of the agent that will be
// fetched if required. This should look like v1.2.3 or an
// 8-character sha, as is downloadable from S3.
DefaultAgentVersion = "v1.89.0"

// AgentPartitionBucketName is the name of the paritional s3 bucket that stores the agent
AgentPartitionBucketName = "amazon-ecs-agent"

Expand Down Expand Up @@ -106,11 +110,6 @@ const (
ECSAgentAppArmorDefaultProfileName = "ecs-agent-default"
)

// DefaultAgentVersion is the version of the agent that will be
// fetched if required. This should look like v1.2.3 or an
// 8-character sha, as is downloadable from S3.
var DefaultAgentVersion = "v" + version.Version

// partitionBucketRegion provides the "partitional" bucket region
// suitable for downloading agent from.
var partitionBucketRegion = map[string]string{
Expand Down
4 changes: 3 additions & 1 deletion ecs-init/version/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import "fmt"
// String construct the version info of ecs-init
func String() string {
dirtyMark := ""
if GitDirty {
// Note that GitDirty is defined via command-line linker flags, so
// it must be a string rather than a bool
if GitDirty == "true" {
dirtyMark = "*"
}
return fmt.Sprintf("ecs-init version %s (%s%s)", Version, dirtyMark, GitShortHash)
Expand Down
16 changes: 6 additions & 10 deletions ecs-init/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This is an autogenerated file and should not be edited.

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// Copyright 2014-2016 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
Expand All @@ -14,18 +14,14 @@
// permissions and limitations under the License.

// Package version contains constants to indicate the current version of the
// ecs-init. It is autogenerated
// ecs-init. It is autogenerated.
package version

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

// Version is the version of ecs-init
const Version = "1.89.0"
// Version is the version of the ecs-init
var Version string = "1.63.0"

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

// GitShortHash is the short hash of this ecs-init build
const GitShortHash = "4843cd00"
var GitShortHash string = "0be4d2e1"
2 changes: 1 addition & 1 deletion packaging/amazon-linux-ami-integrated/ecs-agent.spec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
%global agent_image ecs-agent-v%{version}.tar

Name: ecs-init
Version: %{version}
Version: 1.89.0
Release: 1%{?dist}
License: Apache 2.0
Summary: Amazon Elastic Container Service initialization application
Expand Down
2 changes: 1 addition & 1 deletion packaging/generic-rpm-integrated/amazon-ecs-init.spec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%global agent_image ecs-agent-v%{version}.tar

Name: amazon-ecs-init
Version: %{version}
Version: 1.89.0
Release: 1
License: Apache 2.0
Summary: Amazon Elastic Container Service initialization application
Expand Down
3 changes: 2 additions & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ if [[ "${version_gen}" == "true" ]]; then
cp agent/version/version.go agent/version/_version.go
trap "cd \"${ROOT}\"; mv agent/version/_version.go agent/version/version.go" EXIT SIGHUP SIGINT SIGTERM

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

if [[ "${with_pause}" == "true" ]]; then
Expand Down
54 changes: 54 additions & 0 deletions scripts/gobuild-agent-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# 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.
set -x
set -e
export TOPWD="$(pwd)"
export BUILDDIR="$(mktemp -d)"
export SRCPATH="${BUILDDIR}/src/github.com/aws/amazon-ecs-agent"
export GITPATH="${BUILDDIR}/src/github.com/aws"
export GO111MODULE="auto"

if [ -d "${TOPWD}/.git" ]; then
version=$(cat "${TOPWD}/ecs-init/ECSVERSION")
git_hash=$(git rev-parse --short=8 HEAD)
git_dirty=false

if [[ "$(git status --porcelain)" != "" ]]; then
git_dirty=true
fi

VERSION_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.Version=${version}"
GIT_HASH_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.GitShortHash=${git_hash}"
GIT_DIRTY_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.GitDirty=${git_dirty}"
fi

# build cni-plugins
mkdir -p "${GITPATH}"
ls "${TOPWD}"
ln -s "${TOPWD}/amazon-ecs-cni-plugins" "${GITPATH}"
cd "${GITPATH}/amazon-ecs-cni-plugins" && make plugins
mkdir -p ${SRCPATH}/misc/plugins && cp -a ./bin/plugins/. ${SRCPATH}/misc/plugins
ls ${SRCPATH}/misc/plugins

mkdir -p "{SRCPATH}"
ln -s "${TOPWD}/amazon-ecs-volume-plugin" "${SRCPATH}"
cd "${SRCPATH}"
CGO_ENABLED=0 go build -x -ldflags "-s ${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
-o "${SRCPATH}/amazon-ecs-volume-plugin" "${SRCPATH}/volumes/amazon-ecs-volume-plugin"
rm -r "${BUILDDIR}"

mkdir -p "${SRCPATH}"
ln -s "${TOPWD}/ecs-init" "${SRCPATH}"
cd "${SRCPATH}/ecs-init"
25 changes: 19 additions & 6 deletions scripts/gobuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,35 @@ export GO111MODULE="auto"
# if it's already installed the script will set env vars and exit
source ./scripts/install-golang.sh

# regenerate version files for accurate version info
go run scripts/version-gen.go
if [ -d "${TOPWD}/.git" ]; then
version=$(cat "${TOPWD}/ecs-init/ECSVERSION")
git_hash=$(git rev-parse --short=8 HEAD)
git_dirty=false

if [[ "$(git status --porcelain)" != "" ]]; then
git_dirty=true
fi

VERSION_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.Version=${version}"
GIT_HASH_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.GitShortHash=${git_hash}"
GIT_DIRTY_FLAG="-X github.com/aws/amazon-ecs-agent/ecs-init/version.GitDirty=${git_dirty}"
fi

mkdir -p "${SRCPATH}"
ln -s "${TOPWD}/ecs-init" "${SRCPATH}"
cd "${SRCPATH}/ecs-init"
if [[ "$1" == "dev" ]]; then
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build \
-o "${TOPWD}/amazon-ecs-init"
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build -ldflags "${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
-o "${TOPWD}/amazon-ecs-init"
else
tags=""
if [[ "$1" != "" ]]; then
tags="-tags '$1'"
fi
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build -a ${tags} -x \
-o "${TOPWD}/amazon-ecs-init"
-ldflags "-s ${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
-o "${TOPWD}/amazon-ecs-init"
fi
CGO_ENABLED=0 go build -x -o "${TOPWD}/amazon-ecs-volume-plugin" "./volumes/amazon-ecs-volume-plugin"
CGO_ENABLED=0 go build -x -ldflags "-s ${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
-o "${TOPWD}/amazon-ecs-volume-plugin" "./volumes/amazon-ecs-volume-plugin"
rm -r "${BUILDDIR}"
21 changes: 21 additions & 0 deletions scripts/update-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e

version=${1:?Must specify version as the only argument (e.g. 1.0.0)}

# Normalize to working directory being build root (up one level from ./scripts)
ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )
cd "${ROOT}"

echo -n "$version" > VERSION
export ECS_UNKNOWN_VERSION=true

cd ./agent/version/
# Turn off go module for version-gen.go - see scripts/build.
GO111MODULE=off go run gen/version-gen.go
cd "${ROOT}"

git add agent/version/version.go VERSION

# TODO, the changelog bump could also be automated
echo "Please edit the changelog and commit the version bump"
Loading

0 comments on commit 2aa7018

Please sign in to comment.