Repository navigation
Expand file tree
/
Copy pathRakefile
More file actions
60 lines (51 loc) · 1.51 KB
/
Copy pathRakefile
File metadata and controls
60 lines (51 loc) · 1.51 KB
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
require 'rake'
require 'httparty'
def version
File.readlines('./VERSION').first.strip
end
def container_name
#File.basename(Dir.getwd)
'nginx'
end
def username
'parabuzzle'
end
def latest_hub_version
taginfo = JSON.parse(HTTParty.get("https://hub.docker.com/v2/repositories/#{username}/#{container_name}/tags/").body)['results']
tags = []
taginfo.each do |tag|
tags << tag['name']
end
(tags - ['latest']).sort.last
end
def next_version
base = version
taginfo = JSON.parse(HTTParty.get("https://hub.docker.com/v2/repositories/#{username}/#{container_name}/tags/").body)['results']
return "#{base}.0" if taginfo.nil?
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 { |x,y|
a = x.split('.')[base.split('.').count].to_i
b = y.split('.')[base.split('.').count].to_i
a <=> b
}.last.split('.').last.to_i + 1
return "#{base}.#{build}"
end
desc "tags latest as next_version"
task :tag do
sh "docker tag -f #{username}/#{container_name}:latest #{username}/#{container_name}:#{next_version}"
end
desc "pushes the next_version and latest to docker hub"
task :push => :tag do
sh "docker push #{username}/#{container_name}:#{next_version}"
sh "docker push #{username}/#{container_name}:latest"
end
desc "builds as latest"
task :build do
sh "docker build -t #{username}/#{container_name}:latest ."
end
task :default => [:build, :push]