1 # simple build file to be used locally by Sam
8 PTY
.spawn(command
) do |stdin, stdout, pid
|
22 def ensure_docker_squash
23 docker_squash
= "https://github.com/goldmann/docker-squash/archive/master.zip"
24 run ("pip install --user #{$docker_squash} --upgrade")
29 lines
= run("cd #{image[:name]} && docker build .")
30 img
= lines
[-1]["successfully built ".length
..-1].strip
34 if image
[:layers_to_keep] == nil
35 run("docker-squash -t #{image[:tag]} --cleanup --verbose #{img}")
37 layers_to_squash
= run("docker history #{img} | wc -l").first
.to_i
- (1 + image
[:layers_to_keep])
38 run("docker-squash -t #{image[:tag]} --cleanup --verbose -f #{layers_to_squash} #{img}")
41 run("docker rmi #{img}")
44 run("docker tag #{img} #{image[:tag]}")
48 def bump(image
, image_version
)
49 run("echo #{image_version} > base/VERSION") if image
== 'base'
50 run("sed -i '' -e 's/^\(# NAME:\).*$$/\1 discourse\/#{image}/' #{image}/Dockerfile")
51 run("sed -i '' -e 's/^\(# VERSION:\).*$$/\1 #{image_version}/' #{image}/Dockerfile")
52 run("sed -i '' -e 's/^\(FROM discourse\/[^:]*:\).*/\1#{image_version}/' #{image}/Dockerfile")
56 run("sed -e 's/\(db_name: discourse\)/\1_development/' ../templates/postgres.template.yml > discourse_dev/postgres.template.yml")
57 run("cp ../templates/redis.template.yml discourse_dev/redis.template.yml")
61 OptionParser
.new
do |parser
|
62 parser
.on("-i", "--image image",
63 "Build the image. No parameter means [base discourse discourse_test].") do |i
|
64 options
[:image] = [i
.to_sym
]
66 parser
.on("-b", "--bump version",
67 "Bumps the version in the Dockerfiles specified by --image") do |v
|
68 options
[:version] = [v
]
72 DEFAULT_IMAGES
= %i
[base discourse discourse_test discourse_dev discourse_bench
]
74 todo
= options
[:image] || DEFAULT_IMAGES
75 version = options
[:version] || '1.3.7'
77 if ENV["USER"] != "root"
78 STDERR.puts
"Build script must be ran as root due to docker-squash"
85 base
: { name
: 'base', tag
: "discourse/base:#{version}", squash
: true },
86 discourse
: { name
: 'discourse', tag
: "discourse/discourse:#{version}", squash
: true, layers_to_keep
: 1 },
87 discourse_test
: { name
: 'discourse_test', tag
: "discourse/discourse_test:#{version}", squash
: true, layers_to_keep
: 2 },
88 discourse_dev
: { name
: 'discourse_dev', tag
: "discourse/discourse_dev:#{version}", squash
: false },
89 discourse_bench
: { name
: 'discourse_bench', tag
: "discourse/discourse_bench:#{version}", squash
: false }
94 bump(images
[image
][:name], options
[:version]) if options
[:version]
96 dev_deps() if image
== 'discourse_dev'
97 run
"(cd base && ./download_phantomjs)" if image
== 'base'