forked from RubyData/docker-stacks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
91 lines (76 loc) · 2.11 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
OWNER = 'b08x'.freeze
ALL_IMAGES = %w[
minimal
llamaindex
nlp
full
].each(&:freeze).freeze
BASE_IMAGES = ALL_IMAGES.map do |name|
base_image_name, base_image_tag = nil
IO.foreach("#{name}/Dockerfile") do |line|
break if base_image_name && base_image_tag
case line
when /BASE_IMAGE_TAG=(\h+)/
base_image_tag = Regexp.last_match(1)
when /BASE_IMAGE_TAG=latest/
base_image_tag = 'latest'
when /\AFROM\s+([^:]+)/
base_image_name = Regexp.last_match(1)
end
end
[
name,
[base_image_name, base_image_tag].join(':')
]
end.to_h
DOCKER_FLAGS = ENV['DOCKER_FLAGS']
TAG_LENGTH = 12
def git_revision
`git rev-parse HEAD`.chomp
end
def tag_from_commit_sha1
git_revision[...TAG_LENGTH]
end
ALL_IMAGES.each do |image|
revision_tag = tag_from_commit_sha1
desc "Pull the base image for #{OWNER}/#{image} image"
task "pull/base_image/#{image}" do
base_image = BASE_IMAGES[image]
sh "docker pull #{base_image}"
end
desc "Build #{OWNER}/#{image} image"
task "build/#{image}" => "pull/base_image/#{image}" do
sh "docker build -f #{image}/Dockerfile #{DOCKER_FLAGS} --rm --force-rm -t #{OWNER}/notebook-#{image}:latest ."
end
desc "Make #{OWNER}/#{image} image"
task "make/#{image}" do
sh "docker build -f #{image}/Dockerfile #{DOCKER_FLAGS} --rm --force-rm -t #{OWNER}/notebook-#{image}:latest ."
end
desc "Tag #{OWNER}/#{image} image"
task "tag/#{image}" => "build/#{image}" do
sh "docker tag #{OWNER}/notebook-#{image}:latest #{OWNER}/notebook-#{image}:#{revision_tag}"
end
desc "Push #{OWNER}/#{image} image"
task "push/#{image}" => "tag/#{image}" do
sh "docker push #{OWNER}/notebook-#{image}:latest"
sh "docker push #{OWNER}/notebook-#{image}:#{revision_tag}"
end
end
desc 'Build all images'
task 'build-all' do
ALL_IMAGES.each do |image|
Rake::Task["build/#{image}"].invoke
end
end
desc 'Tag all images'
task 'tag-all' do
ALL_IMAGES.each do |image|
Rake::Task["tag/#{image}"].invoke
end
end
desc 'Push all images'
task 'push-all' do
ALL_IMAGES.each do |image|
Rake::Task["push/#{image}"].invoke
end
end