-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.rb
46 lines (38 loc) · 1.06 KB
/
docker.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
require 'fileutils'
DOCKER_TAG=ENV.fetch('DOCKER_TAG') {"#{`git rev-parse --short HEAD`.strip}#{`git diff HEAD --quiet || echo -dirty`.strip}"}
DOCKER_REPO=ENV.fetch('DOCKER_REPO') {"gcr.io/imjacinta/jaci/curtincourses"}
DOCKER_IMG="#{DOCKER_REPO}:#{DOCKER_TAG}"
def copy_deps
FileUtils.mkdir_p 'build/depslayer'
Dir.glob(['**/Gemfile', '**/Gemfile.lock', '**/*.gemspec']).each do |file|
next if file.include?('build/depslayer')
dest = "build/depslayer/#{file}"
FileUtils.mkdir_p(File.dirname(dest))
if !File.exist?(dest) || File.read(file) != File.read(dest)
puts "Update: #{file} -> #{dest}"
FileUtils.cp(file, dest)
end
end
end
def docker_build
copy_deps
system "docker build -t #{DOCKER_IMG} ."
end
def docker_push
docker_build
system "docker push #{DOCKER_IMG}"
end
if __FILE__ == $0
act = ARGV[0]
if act == 'build'
docker_build
elsif act == 'push'
docker_push
elsif act == 'get_tag'
puts DOCKER_TAG
elsif act == 'get_img'
puts DOCKER_IMG
elsif act == 'get_repo'
puts DOCKER_REPO
end
end