forked from parabuzzle/craneoperator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
56 lines (46 loc) · 1.54 KB
/
Rakefile
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
require 'rake'
require 'httparty'
def version
File.readlines('./VERSION').first.strip
end
def latest_hub_version
taginfo = JSON.parse(HTTParty.get("https://hub.docker.com/v2/repositories/parabuzzle/craneoperator/tags/").body)['results']
tags = []
taginfo.each do |tag|
tags << tag['name']
end
(tags - ['latest']).sort.last
end
def next_version
@next_version ||= get_next_version
end
task :tag do
sh "docker tag -f parabuzzle/craneoperator:latest parabuzzle/craneoperator:#{next_version}"
sh "docker tag -f parabuzzle/craneoperator:latest parabuzzle/docker-registry-ui:latest"
sh "docker tag -f parabuzzle/craneoperator:latest parabuzzle/docker-registry-ui:#{next_version}"
end
desc "Push to Dockerhub"
task :push => :tag do
sh "docker push parabuzzle/craneoperator:#{next_version}"
sh "docker push parabuzzle/craneoperator:latest"
sh "docker push parabuzzle/docker-registry-ui:#{next_version}"
sh "docker push parabuzzle/docker-registry-ui:latest"
end
desc "Build Container"
task :build do
sh "docker build -t parabuzzle/craneoperator:latest ."
end
task :default => [:build]
private
def get_next_version
base = version
taginfo = JSON.parse(HTTParty.get("https://hub.docker.com/v2/repositories/parabuzzle/craneoperator/tags/").body)['results']
tags = []
taginfo.each do |tag|
tags << tag['name']
end
current_base = tags.grep(/#{base}/)
return "#{base}.0" if current_base.empty?
build = current_base.sort.last.split('.').last.to_i + 1
return "#{base}.#{build}"
end