-
Notifications
You must be signed in to change notification settings - Fork 2
/
test
executable file
·59 lines (49 loc) · 1.34 KB
/
test
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
#!/usr/bin/env ruby
require 'set'
@changes = `git show --pretty="format:" --name-only`.each_line.map {|line| line.delete!("\n") }
@rebuild = Set.new
def get_context(path)
context = path.split('/').take(3)
name = context.last.split('-').first
version = context.last.split('-').last
context_path = context.join('/')
if File.exist?("#{context_path}/.requires")
File.open("#{context_path}/.requires").each_line do |line|
next if line == ""
get_context(line)
end
end
if @changes.any? { |c| c.include?(path) }
docker_build(name, version, context_path)
else
docker_pull(name, version)
end
end
def docker_build(name, version, context_path)
if name == version
@rebuild << "docker build --rm -t bugagazavr/#{name} #{context_path}"
else
@rebuild << "docker build --rm -t bugagazavr/#{name}:#{version} #{context_path}"
end
end
def docker_pull(name, version)
if name == version
@rebuild << "docker pull bugagazavr/#{name}"
else
@rebuild << "docker pull bugagazavr/#{name}:#{version}"
end
end
@changes.each do |line|
context = line.split('/').first
case context
when 'services', 'langs'
get_context(line)
when 'base', 'circle.yml'
@rebuild == Set.new(["docker build --rm -t bugagazavr/base base", @rebuild]).flatten
end
end
require 'pp'
pp @rebuild
@rebuild.each do |cmd|
system cmd
end