Skip to content

Commit

Permalink
Derive version in agent, ecs-init, and .rpm/.deb packages from the to…
Browse files Browse the repository at this point in the history
…plevel VERSION file (#4423)
  • Loading branch information
tinnywang authored Nov 8, 2024
1 parent ef99c22 commit 12cb750
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 228 deletions.
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ else
GO_VERSION=$(shell cat ./GO_VERSION)
endif

VERSION=$(shell cat VERSION)

export GO111MODULE=auto

all: docker
Expand Down Expand Up @@ -390,7 +392,6 @@ 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 @@ -401,15 +402,14 @@ amazon-linux-sources.tgz:

.amazon-linux-rpm-integrated-done: amazon-linux-sources.tgz
test -e SOURCES || ln -s . SOURCES
rpmbuild --define "%_topdir $(PWD)" -bb ecs-agent.spec
rpmbuild --define "%version ${VERSION}" --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 @@ -418,31 +418,27 @@ 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 "%_topdir $(PWD)" -bb ecs-agent.spec
rpmbuild --define "%version ${VERSION}" --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 "%_topdir $(PWD)" -bb amazon-ecs-init.spec
rpmbuild --define "%version ${VERSION}" --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
4 changes: 2 additions & 2 deletions agent/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
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
// 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 the Agent
// Version is the version of agent
const Version = "1.88.0"

// GitDirty indicates the cleanliness of the git repo when this agent was built
Expand Down
11 changes: 6 additions & 5 deletions ecs-init/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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 @@ -42,11 +43,6 @@ 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.88.0"

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

Expand Down Expand Up @@ -110,6 +106,11 @@ 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: 1 addition & 3 deletions ecs-init/version/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import "fmt"
// String construct the version info of ecs-init
func String() string {
dirtyMark := ""
// Note that GitDirty is defined via command-line linker flags, so
// it must be a string rather than a bool
if GitDirty == "true" {
if GitDirty {
dirtyMark = "*"
}
return fmt.Sprintf("ecs-init version %s (%s%s)", Version, dirtyMark, GitShortHash)
Expand Down
16 changes: 10 additions & 6 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 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 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,14 +14,18 @@
// 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

// Version is the version of the ecs-init
var Version string = "1.63.0"
// 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.88.0"

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

// GitShortHash is the short hash of this ecs-init build
var GitShortHash string = "0be4d2e1"
const GitShortHash = "c9040caf"
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: 1.88.0
Version: %{version}
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: 1.88.0
Version: %{version}
Release: 1
License: Apache 2.0
Summary: Amazon Elastic Container Service initialization application
Expand Down
3 changes: 1 addition & 2 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ 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 gen/version-gen.go
GO111MODULE=off go run scripts/version-gen.go
fi

if [[ "${with_pause}" == "true" ]]; then
Expand Down
54 changes: 0 additions & 54 deletions scripts/gobuild-agent-init

This file was deleted.

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

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
# regenerate version files for accurate version info
go run scripts/version-gen.go

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 -ldflags "${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
-o "${TOPWD}/amazon-ecs-init"
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build \
-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 \
-ldflags "-s ${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
-o "${TOPWD}/amazon-ecs-init"
-o "${TOPWD}/amazon-ecs-init"
fi
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"
CGO_ENABLED=0 go build -x -o "${TOPWD}/amazon-ecs-volume-plugin" "./volumes/amazon-ecs-volume-plugin"
rm -r "${BUILDDIR}"
21 changes: 0 additions & 21 deletions scripts/update-version

This file was deleted.

86 changes: 0 additions & 86 deletions scripts/update-version.sh

This file was deleted.

Loading

0 comments on commit 12cb750

Please sign in to comment.