5e1e2d65e5c2980f0f14a6c509deb53889f35d02
[discourse_docker.git] / image / auto_build.rb
1 # simple build file to be used locally by Sam
2 #
3 require 'pty'
4 require 'optparse'
5
6 TODO = [:base, :discourse_test, :discourse_dev]
7 VERSION = "2.0.#{Time.now.strftime('%Y%m%d')}"
8
9 images = {
10 base: { name: 'base', tag: "discourse/base:", squash: true },
11 discourse_test: { name: 'discourse_test', tag: "discourse/discourse_test:", squash: false},
12 discourse_dev: { name: 'discourse_dev', tag: "discourse/discourse_dev:", squash: false }
13 }
14
15 def run(command)
16 lines = []
17 PTY.spawn(command) do |stdin, stdout, pid|
18 begin
19 stdin.each do |line|
20 lines << line
21 puts line
22 end
23 rescue Errno::EIO
24 # we are done
25 end
26 end
27
28 lines
29 end
30
31 def build(image)
32 lines = run("cd #{image[:name]} && docker build . --no-cache --tag #{image[:tag] + VERSION} #{image[:squash] ? '#--squash' : ''}")
33 raise "Error building the image for #{image[:name]}: #{lines[-1]}" if lines[-1] =~ /successfully built/
34 run("docker tag #{image[:tag] + VERSION} #{image[:tag]}release")
35 end
36
37 def dev_deps()
38 run("sed -e 's/\(db_name: discourse\)/\1_development/' ../templates/postgres.template.yml > discourse_dev/postgres.template.yml")
39 run("cp ../templates/redis.template.yml discourse_dev/redis.template.yml")
40 end
41
42 TODO.each do |image|
43 puts images[image]
44
45 dev_deps() if image == :discourse_dev
46 run "(cd base && ./download_phantomjs)" if image == :base
47
48 build(images[image])
49 end