+++ /dev/null
-IMAGE_VERSION := 1.3.7
-
-SHELL := /bin/bash
-OS := $(shell uname | tr '[:upper:]' '[:lower:]')
-
-SQUASH ?= YES
-
-DOCKER_SQUASH_URL := https://github.com/jwilder/docker-squash/releases/download/v0.2.0/docker-squash-${OS}-amd64-v0.2.0.tar.gz
-
-
-
-# omitting discourse_fast_switch from 'all' as it seems obsolete.
-all: base discourse discourse_dev discourse_test discourse_bench
-.PHONY: all base discourse discourse_dev discourse_test discourse_bench discourse_fast_switch
-
-base: base-deps
-# discourse: discourse-deps
-discourse_dev: discourse_dev-deps
-# discourse_test: discourse_test-deps
-# discourse_bench: discourse_bench-deps
-# discourse_fast_switch: discourse_fast_switch-deps
-
-base:
- @IMAGE_DIR=$@ IS_BASE=YES ${MAKE} build-image
-
-discourse discourse_dev discourse_test discourse_bench discourse_fast_switch:
- @IMAGE_DIR=$@ ${MAKE} build-image
-
-
-base-deps: base/phantomjs
-.PHONY: base-deps
-
-base/phantomjs:
- @echo "Fetching phantomjs..."
- cd base && ./download_phantomjs
-
-discourse_dev-deps:
- @echo "Copying postgres and redis templates..."
- sed -e 's/\(db_name: discourse\)/\1_development/' ../templates/postgres.template.yml > discourse_dev/postgres.template.yml
- cp ../templates/redis.template.yml discourse_dev/redis.template.yml
-.PHONY: discourse_dev-deps
-
-# If you don't want to docker-squash the image, prefix your command line with
-# SQUASH=NO, like:
-# SQUASH=NO make discourse_dev
-build-image: docker-squash update-dockerfile
- @echo "----- building image: discourse/${IMAGE_DIR}:${IMAGE_VERSION} -----"
-ifeq (${SQUASH}, YES)
- docker build ${IMAGE_DIR} | tee .build.out
- tail -1 .build.out | awk '/^Successfully built / {print $$3}' > .build.hash
- @echo "squashing $$(cat .build.hash)..."
- docker save -o img.tar $$(cat .build.hash)
- sudo ./docker-squash -verbose -i img.tar -o squash.tar $(if $(IS_BASE),-from root)
- docker load -i squash.tar
- docker tag $$(cat .build.hash) discourse/${IMAGE_DIR}:${IMAGE_VERSION}
- rm -f squash.tar
- rm -f img.tar
- rm -f .build.hash
- rm -f .build.out
-else
- docker build -t discourse/${IMAGE_DIR}:${IMAGE_VERSION} ${IMAGE_DIR}
-endif
-.PHONY: build-image
-
-docker-squash:
- wget ${DOCKER_SQUASH_URL} --output-document=$@.tar.gz
- tar -xzvf $@.tar.gz
- rm -f $@.tar.gz
-
-# We want to ensure that the Dockerfiles all have an appropriate header
-# comment, and any FROM line refers to the version we're currently building.
-# Also, if there's a line that echoes into VERSION, replace the value with the
-# current version. (Dockerfiles support environment expansion, but not for
-# FROM or RUN statements.)
-update-dockerfile:
- @echo "----- updating ${IMAGE_DIR}/Dockerfile for ${IMAGE_VERSION} -----"
- @sed -i '' -e 's/^\(# NAME:\).*$$/\1 discourse\/${IMAGE_DIR}/' ${IMAGE_DIR}/Dockerfile
- @sed -i '' -e 's/^\(# VERSION:\).*$$/\1 ${IMAGE_VERSION}/' ${IMAGE_DIR}/Dockerfile
- @sed -i '' -e 's/^\(FROM discourse\/[^:]*:\).*/\1${IMAGE_VERSION}/' ${IMAGE_DIR}/Dockerfile
- @sed -i '' -e 's/^\(RUN echo "\)[^"]*\(" > \/VERSION\)$$/\1${IMAGE_VERSION}\2/' ${IMAGE_DIR}/Dockerfile
-.PHONY: update-dockerfile
# simple build file to be used locally by Sam
#
require 'pty'
-
-$version = "1.3.7"
-
-$docker_squash = "https://github.com/goldmann/docker-squash/archive/master.zip"
-
-$base_image = "discourse/base:#{$version}"
-$image = "discourse/discourse:#{$version}"
-$test = "discourse/discourse_test:#{$version}"
-
-if ENV["USER"] != "root"
- STDERR.puts "Build script must be ran as root due to docker-squash"
- exit 1
-end
+require 'optparse'
def run(command)
lines = []
end
def ensure_docker_squash
- run ("pip install --user #{$docker_squash}")
+ docker_squash = "https://github.com/goldmann/docker-squash/archive/master.zip"
+ run ("pip install --user #{$docker_squash} --upgrade")
end
-ensure_docker_squash
-def build(path, tag, layers_to_keep = nil)
- lines = run("cd #{path} && docker build .")
+def build(image, version)
+ lines = run("cd #{image[:name]} && docker build --build-arg version=#{version} .")
img = lines[-1]["successfully built ".length..-1].strip
- layers_to_squash = run("docker history #{img} | wc -l").first.to_i - (1 + layers_to_keep) if layers_to_keep
- if layers_to_keep != nil
- puts "docker-squash -t #{tag} --verbose -f #{layers_to_squash} #{img}"
- run("docker-squash -t #{tag} --verbose -f #{layers_to_squash} #{img}")
+
+ if image[:squash]
+
+ layers_to_squash = run("docker history #{img} | wc -l").first.to_i - (1 + image[:layers_to_keep])
+
+ if layers_to_keep != nil
+ run("docker-squash -t #{image[:tag]} --verbose -f #{layers_to_squash} #{img}")
+ else
+ run("docker-squash -t #{image[:tag]} --verbose #{img}")
+ end
+
else
- puts "docker-squash -t #{tag} --verbose #{img}"
- run("docker-squash -t #{tag} --verbose #{img}")
+ run("docker tag #{img} #{image[:tag]}")
end
end
-run "(cd base && ./download_phantomjs)"
+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")
+end
-build("base",$base_image)
-build("discourse",$image,1)
-build("discourse_test",$test,2)
+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]
+ end
+ parser.on("-b", "--bump version",
+ "Bumps the version in the Dockerfiles specified by --image") do |v|
+ options[:version] = [v]
+ end
+end.parse!
+
+DEFAULT_IMAGES = %i[base discourse discourse_test discourse_dev discourse_bench]
+
+todo = options[:image] || DEFAULT_IMAGES
+version = options[:version] || '1.3.7'
+
+if ENV["USER"] != "root"
+ STDERR.puts "Build script must be ran as root due to docker-squash"
+ exit 1
+end
+
+ensure_docker_squash
+
+images = {
+ base: { name: 'base', tag: "discourse/base:#{version}", squash: true },
+ discourse: { name: 'discourse', tag: "discourse/discourse:#{version}", squash: true, layers_to_keep: 1 },
+ discourse_test: { name: 'discourse_test', tag: "discourse/discourse_test:#{version}", squash: true, layers_to_keep: 2 },
+ discourse_dev: { name: 'discourse_dev', tag: "discourse/discourse_dev:#{version}", squash: false },
+ discourse_bench: { name: 'discourse_bench', tag: "discourse/discourse_bench:#{version}", squash: false }
+}
+
+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)
+end