Created
November 29, 2017 22:37
-
-
Save brandon-fryslie/7d4e156c8044bd7554ff301afa0a2f78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'json' | |
class String | |
def colorize(color_code) "\e[#{color_code}m#{self}\e[0m" end | |
def bold; colorize(1) end | |
def red; colorize(31) end | |
def green; colorize(32) end | |
def yellow; colorize(33) end | |
def cyan; colorize(36) end | |
end | |
mapping = { | |
'cba/opseng/ansible' => 'pt/opseng/ansible', | |
# 'cba/statsd' => 'pt/opseng/statsd', # not used w/ get-latest-tag.py | |
# 'cba/opseng/cba-tenant-service' => 'pt/opseng/admin-service', # not used w/ get-latest-tag.py | |
# 'cba/opseng/pingthru' => 'pt/opseng/pingthru', # not used w/ get-latest-tag.py | |
'worksheets-static' => 'pt/app/sheets-static', | |
'cba/sheets-web' => 'pt/app/sheets-web', | |
'cba/sheets-engine' => 'pt/app/sheets-engine', | |
'pt/workdrive-client' => 'pt/app/workdrive-client', | |
'pt/workdrive-server' => 'pt/app/workdrive-server', | |
'cba/docs-engine' => 'pt/app/docs-engine', | |
'cba/docs-web' => 'pt/app/docs-web', | |
'cba/talk-engine' => 'pt/app/talk-engine', | |
'cba/talk-web' => 'pt/app/talk-web', | |
'pt/worktalk-static' => 'pt/app/talk-static', | |
'cba/docs-engine' => 'pt/app/docs-engine', | |
'cba/docs-web' => 'pt/app/docs-web', | |
'pt/docs-client' => 'pt/app/docs-static', | |
} | |
ART_USER = 'brandon.fryslie' | |
AF_PASS = 'your-af.megaleo.com-api-key' | |
ART_PASS = 'your-artifactory.workday.com-api-key' | |
def queryForImage(image, useNew = false, debug = false) | |
ENV['ART_USER'] = 'brandon.fryslie' | |
ENV['ART_PASS'] = useNew ? ART_PASS : AF_PASS | |
# this command would need to change. | |
# you could change this to some shell command that would search and replace across the project, for example | |
cmd = "/Users/brandon.fryslie/code/ci-scripts/bin/get-latest-tag.py #{useNew ? '--use-new-artifactory' : ''} #{image} 2>&1" | |
if debug | |
puts "Running command: ART_USER=#{ENV['ART_USER']} ART_PASS=#{ENV['ART_PASS']} #{cmd}".yellow | |
end | |
res = `#{cmd}` | |
if debug | |
puts res.yellow | |
end | |
res.strip | |
end | |
def createNameStr(oldName, newName) | |
"#{oldName.cyan} #{'/'.yellow} #{newName.cyan}" | |
end | |
results = mapping.map do |oldName, newName| | |
puts "Verifying image: #{createNameStr(oldName, newName)}".yellow | |
oldRes = queryForImage(oldName, false, false) | |
newRes = queryForImage(newName, true, false) | |
{ :oldName => oldName, :newName => newName, :oldLatest => oldRes, :newLatest => newRes } | |
end | |
def verifyImage(imageResult) | |
puts "Comparing image: #{createNameStr(imageResult[:oldName], imageResult[:newName])}".yellow | |
if imageResult[:oldLatest] == 'No containers found for arguments passed' || imageResult[:newLatest] == 'No containers found for arguments passed' | |
puts "Error: No container found".red | |
elsif imageResult[:oldLatest] == imageResult[:newLatest] | |
puts "Same latest: #{imageResult[:oldLatest]}".green | |
else | |
puts "Latest Differs. Old Latest: '#{imageResult[:oldLatest]}' New Latest: '#{imageResult[:newLatest]}'".red | |
end | |
end | |
results.each do |imageResult| | |
verifyImage(imageResult) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script currently loops thru all the images, queries the latest version with get-latest-tag.py, then compares the results from megaleo & new artifactory. Modify to suit your needs