Highlight uncommitted changes in version

If there are uncommitted changes in the app repository when building,
then append `_uncommitted_<random>` to it to distinguish the image
from one built from a clean checkout.

Also change the version used when renaming a container on redeploy to
distinguish and explain the version suffixes.
This commit is contained in:
Donal McBreen
2023-05-11 16:14:41 +01:00
parent 15e8ac0ced
commit a5ef1f254f
9 changed files with 34 additions and 12 deletions

View File

@@ -50,7 +50,7 @@ class Mrsk::Configuration
end
def version
@declared_version.presence || ENV["VERSION"] || current_commit_hash
@declared_version.presence || ENV["VERSION"] || git_version
end
def abbreviated_version
@@ -233,10 +233,12 @@ class Mrsk::Configuration
raw_config.servers.is_a?(Array) ? [ "web" ] : raw_config.servers.keys.sort
end
def current_commit_hash
@current_commit_hash ||=
def git_version
@git_version ||=
if system("git rev-parse")
`git rev-parse HEAD`.strip
uncommitted_suffix = `git status --porcelain`.strip.present? ? "_uncommitted_#{SecureRandom.hex(8)}" : ""
"#{`git rev-parse HEAD`.strip}#{uncommitted_suffix}"
else
raise "Can't use commit hash as version, no git repository found in #{Dir.pwd}"
end