Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Nov 8, 2024

Conversation

tinnywang
Copy link
Contributor

@tinnywang tinnywang commented Nov 8, 2024

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

DefaultAgentVersion = "v1.88.0"

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

  • The original version-gen.go was in agent/version/gen. It is now in the toplevel scripts directory since it is used by both agent and ecs-init. It should be run from the root of the repo, e.g. go run scripts/version-gen.go.
  • Makefile targets for building .rpm/.deb package each individually ran ./scripts/update-version.sh to regenerate the ecs-init version file. I have moved this call into scripts/gobuild.sh since the .rpm/.deb package builders all eventually call gobuild.sh. gobuild.sh also uses version-gen.go instead of update-version.sh.
  • scripts/gobuild.sh set linker flags to override ecs-init version variables. This is how we've been able to release correctly versioned ecs-inits without committing changes to ecs-init's version.go. Setting linker flags isn't necessary anymore because we
    • regenerate version.go (when the script runs version-gen.go, as mentioned in the previous bullet point)
    • commit changes to version.go (the releaser will do this when creating the release PR)
      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}"

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.

@tinnywang tinnywang changed the title Consolidate version files Simplify the process of updating version Nov 8, 2024
@tinnywang tinnywang changed the title Simplify the process of updating version Derive version in agent, ecs-init, and .rpm/.deb packages from the toplevel VERSION file Nov 8, 2024
@tinnywang tinnywang force-pushed the consolidate-version branch from 55d7de8 to 74874b7 Compare November 8, 2024 18:32
@tinnywang tinnywang marked this pull request as ready for review November 8, 2024 21:45
@tinnywang tinnywang requested a review from a team as a code owner November 8, 2024 21:45
Copy link
Contributor

@amogh09 amogh09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful 🎉

@tinnywang tinnywang merged commit 12cb750 into aws:dev Nov 8, 2024
40 checks passed
@tinnywang tinnywang deleted the consolidate-version branch November 8, 2024 23:07
@prateekchaudhry prateekchaudhry mentioned this pull request Nov 15, 2024
prateekchaudhry added a commit to prateekchaudhry/amazon-ecs-agent that referenced this pull request Nov 18, 2024
prateekchaudhry added a commit to prateekchaudhry/amazon-ecs-agent that referenced this pull request Nov 18, 2024
…m the toplevel VERSION file aws#4423"; Update agent to 1.89.0
prateekchaudhry added a commit to prateekchaudhry/amazon-ecs-agent that referenced this pull request Nov 18, 2024
…m the toplevel VERSION file aws#4423"; Update agent to 1.89.0
prateekchaudhry added a commit that referenced this pull request Nov 19, 2024
…m the toplevel VERSION file #4423"; Update agent to 1.89.0
JoseVillalta pushed a commit to JoseVillalta/amazon-ecs-agent that referenced this pull request Nov 21, 2024
JoseVillalta pushed a commit to JoseVillalta/amazon-ecs-agent that referenced this pull request Nov 21, 2024
…m the toplevel VERSION file aws#4423"; Update agent to 1.89.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants