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