-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.rb
executable file
·57 lines (48 loc) · 1.31 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
47
48
49
50
51
52
53
54
55
56
57
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') {"australia-southeast1-docker.pkg.dev/imjacinta/jaci/imjacinta"}
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
unless system "docker build -t #{DOCKER_IMG} ."
raise "Error!"
end
end
def docker_push
docker_build
unless system "docker push #{DOCKER_IMG}"
raise "Error!"
end
end
def docker_up_dev
copy_deps
system "docker-compose up --build"
end
if __FILE__ == $0
act = ARGV[0]
if act == 'build'
docker_build
elsif act == 'push'
docker_push
elsif act == 'up'
docker_up_dev
elsif act == 'get_tag'
puts DOCKER_TAG
elsif act == 'get_img'
puts DOCKER_IMG
elsif act == 'get_repo'
puts DOCKER_REPO
end
end