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 ("apt install python-pip")
25 run ("pip install '#{docker_squash}' --upgrade")
30 lines
= run("cd #{image[:name]} && docker build .")
31 img
= lines
[-1]["successfully built ".length
..-1].strip
35 if image
[:layers_to_keep] == nil
36 run("docker-squash -t #{image[:tag]} --cleanup --verbose #{img}")
38 layers_to_squash
= run("docker history #{img} | wc -l").first
.to_i
- (1 + image
[:layers_to_keep])
39 run("docker-squash -t #{image[:tag]} --cleanup --verbose -f #{layers_to_squash} #{img}")
42 run("docker rmi #{img}")
45 run("docker tag #{img} #{image[:tag]}")
49 def bump(image
, image_version
)
50 run("echo #{image_version} > base/VERSION") if image
== 'base'
51 run("sed -i '' -e 's/^\(# NAME:\).*$$/\1 discourse\/#{image}/' #{image}/Dockerfile")
52 run("sed -i '' -e 's/^\(# VERSION:\).*$$/\1 #{image_version}/' #{image}/Dockerfile")
53 run("sed -i '' -e 's/^\(FROM discourse\/[^:]*:\).*/\1#{image_version}/' #{image}/Dockerfile")
57 run("sed -e 's/\(db_name: discourse\)/\1_development/' ../templates/postgres.template.yml > discourse_dev/postgres.template.yml")
58 run("cp ../templates/redis.template.yml discourse_dev/redis.template.yml")
62 OptionParser
.new
do |parser
|
63 parser
.on("-i", "--image image",
64 "Build the image. No parameter means [base discourse discourse_test].") do |i
|
65 options
[:image] = [i
.to_sym
]
67 parser
.on("-b", "--bump version",
68 "Bumps the version in the Dockerfiles specified by --image") do |v
|
69 options
[:version] = [v
]
73 DEFAULT_IMAGES
= %i
[base discourse discourse_test discourse_dev discourse_bench
]
75 todo
= options
[:image] || DEFAULT_IMAGES
76 version = options
[:version] || '1.3.10'
78 if ENV["USER"] != "root"
79 STDERR.puts
"Build script must be ran as root due to docker-squash"
86 base
: { name
: 'base', tag
: "discourse/base:#{version}", squash
: true },
87 discourse
: { name
: 'discourse', tag
: "discourse/discourse:#{version}", squash
: true, layers_to_keep
: 1 },
88 discourse_test
: { name
: 'discourse_test', tag
: "discourse/discourse_test:#{version}", squash
: true, layers_to_keep
: 2 },
89 discourse_dev
: { name
: 'discourse_dev', tag
: "discourse/discourse_dev:#{version}", squash
: false },
90 discourse_bench
: { name
: 'discourse_bench', tag
: "discourse/discourse_bench:#{version}", squash
: false }
95 bump(images
[image
][:name], options
[:version]) if options
[:version]
97 dev_deps() if image
== :discourse_dev
98 run
"(cd base && ./download_phantomjs)" if image
== :base