class Kapnismology::ApplicationInformation
This class provides information about the running environment the smoketest is being executed under.
Constants
- ECS_CONTAINER_METADATA_FILE
- GIT_COMMAND
- INFO_UNKNOWN
- KUBERNETES_ANNOTATIONS_FILE
Public Instance Methods
codebase_revision()
click to toggle source
# File lib/kapnismology/application_information.rb, line 15 def codebase_revision @codebase_revision ||= begin latest_commit_info[0...7] rescue Errno::ENOENT, StandardError INFO_UNKNOWN end end
Private Instance Methods
latest_commit_info()
click to toggle source
# File lib/kapnismology/application_information.rb, line 25 def latest_commit_info latest_sha_from_ecs_metadata || latest_sha_from_k8s_annotations || latest_sha_from_git || INFO_UNKNOWN end
latest_sha_from_ecs_metadata()
click to toggle source
This assumes the ImageName features the git sha as the last part of a string delimited by dots. See spec/support/ecs_metadata.json as well as docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html
# File lib/kapnismology/application_information.rb, line 37 def latest_sha_from_ecs_metadata return nil if ECS_CONTAINER_METADATA_FILE.nil? return nil unless !ECS_CONTAINER_METADATA_FILE.strip.empty? && File.readable?(ECS_CONTAINER_METADATA_FILE) begin JSON.parse(File.read(ECS_CONTAINER_METADATA_FILE))["ImageName"].split(".").last rescue JSON::ParserError nil end end
latest_sha_from_git()
click to toggle source
# File lib/kapnismology/application_information.rb, line 29 def latest_sha_from_git result = `#{GIT_COMMAND}` $?.success? ? result : nil end
latest_sha_from_k8s_annotations()
click to toggle source
# File lib/kapnismology/application_information.rb, line 48 def latest_sha_from_k8s_annotations return nil unless File.readable?(KUBERNETES_ANNOTATIONS_FILE) File.read(KUBERNETES_ANNOTATIONS_FILE).scan(/gitSha="(.+)"$/).last&.first end