From ad5b2d96703b7d8b32f551d537647e15b6c1c8be Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Thu, 20 Oct 2016 23:32:01 -0200 Subject: [PATCH] build.rb improvements --- image/base/Dockerfile | 2 +- image/base/VERSION | 1 + image/build.rb | 36 +++++++++++++++++++++++------------- 3 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 image/base/VERSION diff --git a/image/base/Dockerfile b/image/base/Dockerfile index 3a4e0c8..6158e83 100644 --- a/image/base/Dockerfile +++ b/image/base/Dockerfile @@ -7,7 +7,7 @@ ENV PG_VERSION 9.5.4-1.pgdg16.04+2 MAINTAINER Sam Saffron "https://twitter.com/samsaffron" -RUN echo "${version}" > /VERSION +ADD VERSION /VERSION RUN apt-get update && apt-get install -y lsb-release sudo curl RUN echo "debconf debconf/frontend select Teletype" | debconf-set-selections diff --git a/image/base/VERSION b/image/base/VERSION new file mode 100644 index 0000000..8ed486a --- /dev/null +++ b/image/base/VERSION @@ -0,0 +1 @@ +1.3.7 \ No newline at end of file diff --git a/image/build.rb b/image/build.rb index 2860293..fcbed10 100644 --- a/image/build.rb +++ b/image/build.rb @@ -25,36 +25,43 @@ def ensure_docker_squash end -def build(image, version) - lines = run("cd #{image[:name]} && docker build --build-arg version=#{version} .") +def build(image) + lines = run("cd #{image[:name]} && docker build .") img = lines[-1]["successfully built ".length..-1].strip if image[:squash] - layers_to_squash = run("docker history #{img} | wc -l").first.to_i - (1 + image[:layers_to_keep]) if image[:layers_to_keep] != nil - - if layers_to_keep != nil - run("docker-squash -t #{image[:tag]} --verbose -f #{layers_to_squash} #{img}") + if image[:layers_to_keep] == nil + run("docker-squash -t #{image[:tag]} --cleanup --verbose #{img}") else - run("docker-squash -t #{image[:tag]} --verbose #{img}") + layers_to_squash = run("docker history #{img} | wc -l").first.to_i - (1 + image[:layers_to_keep]) + run("docker-squash -t #{image[:tag]} --cleanup --verbose -f #{layers_to_squash} #{img}") end + run("docker rmi #{img}") + else run("docker tag #{img} #{image[:tag]}") end end def bump(image, image_version) - run("sed -i '' -e 's/^\(# NAME:\).*$$/\1 discourse\/#{image_dir}/' #{image_dir}/Dockerfile") - run("sed -i '' -e 's/^\(# VERSION:\).*$$/\1 #{image_version}/' #{image_dir}/Dockerfile") - run("sed -i '' -e 's/^\(FROM discourse\/[^:]*:\).*/\1#{image_version}/' #{image_dir}/Dockerfile") + run("echo #{image_version} > base/VERSION") if image == 'base' + run("sed -i '' -e 's/^\(# NAME:\).*$$/\1 discourse\/#{image}/' #{image}/Dockerfile") + run("sed -i '' -e 's/^\(# VERSION:\).*$$/\1 #{image_version}/' #{image}/Dockerfile") + run("sed -i '' -e 's/^\(FROM discourse\/[^:]*:\).*/\1#{image_version}/' #{image}/Dockerfile") +end + +def dev_deps() + run("sed -e 's/\(db_name: discourse\)/\1_development/' ../templates/postgres.template.yml > discourse_dev/postgres.template.yml") + run("cp ../templates/redis.template.yml discourse_dev/redis.template.yml") end options = {} OptionParser.new do |parser| parser.on("-i", "--image image", "Build the image. No parameter means [base discourse discourse_test].") do |i| - options[:image] = [i] + options[:image] = [i.to_sym] end parser.on("-b", "--bump version", "Bumps the version in the Dockerfiles specified by --image") do |v| @@ -85,6 +92,9 @@ images = { todo.each do |image| puts images[image] bump(images[image][:name], options[:version]) if options[:version] - run "(cd base && ./download_phantomjs)" if image == 'base' - build(images[image], version) + + dev_deps() if image == 'discourse_dev' + run "(cd base && ./download_phantomjs)" if image == 'base' + + build(images[image]) end -- 2.25.1