Commit | Line | Data |
---|---|---|
67446876 RSS |
1 | # simple build file to be used locally by Sam |
2 | # | |
3 | require 'pty' | |
4 | require 'optparse' | |
5 | ||
d288199f | 6 | images = { |
7e364d47 RSS |
7 | base: { name: 'base', tag: "discourse/base:build", squash: true }, |
8 | discourse_test: { name: 'discourse_test', tag: "discourse/discourse_test:build", squash: false}, | |
9 | discourse_dev: { name: 'discourse_dev', tag: "discourse/discourse_dev:build", squash: false } | |
d288199f RSS |
10 | } |
11 | ||
67446876 RSS |
12 | def run(command) |
13 | lines = [] | |
14 | PTY.spawn(command) do |stdin, stdout, pid| | |
15 | begin | |
16 | stdin.each do |line| | |
17 | lines << line | |
18 | puts line | |
19 | end | |
20 | rescue Errno::EIO | |
21 | # we are done | |
22 | end | |
23 | end | |
24 | ||
25 | lines | |
26 | end | |
27 | ||
28 | def build(image) | |
22baac23 | 29 | lines = run("cd #{image[:name]} && docker build . --no-cache --tag #{image[:tag]} #{image[:squash] ? '--squash' : ''}") |
d288199f | 30 | raise "Error building the image for #{image[:name]}: #{lines[-1]}" if lines[-1] =~ /successfully built/ |
67446876 RSS |
31 | end |
32 | ||
33 | def dev_deps() | |
34 | run("sed -e 's/\(db_name: discourse\)/\1_development/' ../templates/postgres.template.yml > discourse_dev/postgres.template.yml") | |
35 | run("cp ../templates/redis.template.yml discourse_dev/redis.template.yml") | |
36 | end | |
37 | ||
7e364d47 RSS |
38 | image = ARGV[0].intern |
39 | raise 'Image not found' unless images.include?(image) | |
67446876 | 40 | |
7e364d47 RSS |
41 | puts "Building #{images[image]}" |
42 | dev_deps() if image == :discourse_dev | |
43 | run "(cd base && ./download_phantomjs)" if image == :base | |
67446876 | 44 | |
7e364d47 | 45 | build(images[image]) |