aws / amazon-ecs-agent

Amazon Elastic Container Service Agent
http://aws.amazon.com/ecs/
Apache License 2.0
2.08k stars 616 forks source link

Derive version in agent, ecs-init, and .rpm/.deb packages from the toplevel VERSION file #4423

Closed tinnywang closed 2 weeks ago

tinnywang commented 3 weeks ago

Summary

When releasing a new version of Agent, we need to manually update version in several places before running version-gen.go:

  1. in the Agent version file VERSION
  2. in the ecs-init version file ECSVERSION
  3. in ecs-init/config/common.go
  4. in the amazon-linux-ami-integrated spec file
  5. in the generic-rpm-integrated spec file

This PR consolidates the Agent and ecs-init VERSION files into a single source of truth from which we derive version in go code and RPM spec files. With these changes, we need only update the toplevel VERSION file before running version-gen.go.

Implementation details

Consolidate Agent and ecs-init VERSION files

We only need a single VERSION file because Agent and ecs-init always release together with the same version, so keep VERSION, remove ECSVERSION, and replace any references to ECSVERSION with VERSION.

Consolidate scripts for generating version.go

We have 3 different scripts for generating version.go files in Agent and ecs-init.

  1. version-gen.go only generates agent/version/version.go. We commit changes to this file.
  2. update-version.sh generates agent/version/version.go and ecs-init/version/version.go. We don't commit changes to either file, which is why the info in ecs-init's version.go is so out-of-date.
  3. update-version doesn't appear to be used.

Update version-gen.go to generate version.go files in both the agent/version and ecs-init/version packages. Replace references to update-version.sh with version-gen.go. Finally, update config.DefaultAgentVersion https://github.com/aws/amazon-ecs-agent/blob/ea4ffcdd5a69b36c5a7216938949fae0b26d2b0f/ecs-init/config/common.go#L48 to use version.Version

var DefaultAgentVersion = "v" + version.Version

Derive RPM spec file version from VERSION

In our Makefile, update rpmbuild commands to define a %version macro. The %version macro will evaluate to the value in our VERSION file.

VERSION=$(shell cat VERSION)
...
rpmbuild --define "%version ${VERSION}" --define "%_topdir $(PWD)" -bb ecs-agent.spec

In the amazon-linux-ami-integrated spec and the generic-rpm-integrated spec, replace the hard-coded version string with %{version}.

Other notable changes

Testing

Built and installed .rpm/.deb packages on the appropriate platforms.

make amazon-linux-rpm-integrated
make generic-rpm-integrated
make generic-deb-integrated

Verified that the ecs-init version info was correct with

sudo /usr/libexec/amazon-ecs-init version

Changed the semver in the toplevel VERSION file and then rebuilt and reinstalled ecs-init. Verified that the newly installed ecs-init version info had the new semver.

Description for the changelog

Derive version in agent, ecs-init, and .rpm/.deb packages from the toplevel VERSION file.

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.