-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.rb
60 lines (46 loc) · 992 Bytes
/
registry.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
services = %w[
jarvis_jarvis
jarvis_rabbitmq
]
def now
@now ||= Time.now
end
def actual_dir
File.basename(Dir.getwd)
end
def git_project_prefix
"#{actual_dir}_"
end
def dockerhub_repository
"magrathealabs/jarvis"
end
def remove_prefix(service)
service.gsub(git_project_prefix, '')
end
def dated
[branch, now.year, now.month, now.day, now.hour, now.min].join('.')
end
def travis_pr?
ENV['TRAVIS_PULL_REQUEST'] != 'false'
end
def pr_name
ENV['TRAVIS_PULL_REQUEST_BRANCH'] || 'unstable'
end
def branch_name
ENV['TRAVIS_BRANCH'] || 'unstable'
end
def branch
return pr_name if travis_pr?
branch_name
end
def tag(service)
"#{remove_prefix(service)}-#{dated}".
gsub('-', '.').
gsub('/', '.').
gsub('_', '.').
gsub(' ', '.')
end
services.each do |service|
system "docker tag #{service} #{dockerhub_repository}:#{tag(service)}"
system "docker push #{dockerhub_repository}:#{tag(service)}"
end