From 674468764ece1590e29794296f0c282ca22f4099 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Tue, 31 Jan 2017 13:21:00 -0200 Subject: [PATCH] Move everything to a complete base image --- image/auto_build.rb | 60 +++++++++++++++++++++++++++++++++ image/base/Dockerfile | 16 ++++++++- image/discourse/Dockerfile | 18 ---------- image/discourse_dev/Dockerfile | 10 +++--- image/discourse_test/Dockerfile | 4 +-- 5 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 image/auto_build.rb delete mode 100644 image/discourse/Dockerfile diff --git a/image/auto_build.rb b/image/auto_build.rb new file mode 100644 index 0000000..c7d0d68 --- /dev/null +++ b/image/auto_build.rb @@ -0,0 +1,60 @@ +# simple build file to be used locally by Sam +# +require 'pty' +require 'optparse' + +def run(command) + lines = [] + PTY.spawn(command) do |stdin, stdout, pid| + begin + stdin.each do |line| + lines << line + puts line + end + rescue Errno::EIO + # we are done + end + end + + lines +end + +def build(image) + sucess = false + lines = run("cd #{image[:name]} && docker build . --tag #{image[:tag]} #{image[:squash] ? '--squash' : ''}") + sucess = true if lines[-1] =~ 'successfully built' +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.to_sym] + end +end.parse! + +DEFAULT_IMAGES = [:base, :discourse, :discourse_test, :discourse_dev, :discourse_bench] + +todo = options[:image] || DEFAULT_IMAGES +version = 'release' + +images = { + base: { name: 'base', tag: "discourse/base:#{version}", squash: true }, + discourse_test: { name: 'discourse_test', tag: "discourse/discourse_test:#{version}", squash: false}, + discourse_dev: { name: 'discourse_dev', tag: "discourse/discourse_dev:#{version}", squash: false } +} + +todo.each do |image| + puts images[image] + bump(images[image][:name], options[:version]) if options[:version] + + dev_deps() if image == :discourse_dev + run "(cd base && ./download_phantomjs)" if image == :base + + build(images[image]) +end diff --git a/image/base/Dockerfile b/image/base/Dockerfile index a8d9fe7..74d1614 100644 --- a/image/base/Dockerfile +++ b/image/base/Dockerfile @@ -1,5 +1,5 @@ # NAME: discourse/base -# VERSION: 1.3.10 +# VERSION: build FROM ubuntu:16.04 ENV PG_MAJOR 9.5 @@ -128,3 +128,17 @@ ADD boot /sbin/boot ADD cron /etc/service/cron/run ADD rsyslog /etc/service/rsyslog/run ADD cron.d_anacron /etc/cron.d/anacron + + +# Discourse specific bits +RUN useradd discourse -s /bin/bash -m -U &&\ + mkdir -p /var/www &&\ + cd /var/www &&\ + git clone https://github.com/discourse/discourse.git &&\ + cd discourse &&\ + git remote set-branches --add origin tests-passed &&\ + chown -R discourse:discourse /var/www/discourse &&\ + cd /var/www/discourse &&\ + sudo -u discourse bundle install --deployment \ + --without test --without development &&\ + find /var/www/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} + diff --git a/image/discourse/Dockerfile b/image/discourse/Dockerfile deleted file mode 100644 index 898b6a9..0000000 --- a/image/discourse/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -# NAME: discourse/discourse -# VERSION: 1.3.10 -FROM discourse/base:1.3.10 - -MAINTAINER Sam Saffron "https://twitter.com/samsaffron" - -# Discourse specific bits -RUN useradd discourse -s /bin/bash -m -U &&\ - mkdir -p /var/www &&\ - cd /var/www &&\ - git clone https://github.com/discourse/discourse.git &&\ - cd discourse &&\ - git remote set-branches --add origin tests-passed &&\ - chown -R discourse:discourse /var/www/discourse &&\ - cd /var/www/discourse &&\ - sudo -u discourse bundle install --deployment \ - --without test --without development &&\ - find /var/www/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} + diff --git a/image/discourse_dev/Dockerfile b/image/discourse_dev/Dockerfile index 99d2122..d9a1184 100644 --- a/image/discourse_dev/Dockerfile +++ b/image/discourse_dev/Dockerfile @@ -1,6 +1,6 @@ # NAME: discourse/discourse_dev -# VERSION: 1.3.10 -FROM discourse/base:1.3.10 +# VERSION: build +FROM discourse/base:release MAINTAINER Sam Saffron "https://twitter.com/samsaffron" @@ -8,10 +8,8 @@ MAINTAINER Sam Saffron "https://twitter.com/samsaffron" RUN apt-get update && apt-get install -y libsqlite3-dev \ && gem install mailcatcher && rm -rf /var/lib/apt/lists/* -# Create discourse user and /var/www location for both -# discourse and dev images. -RUN useradd discourse -s /bin/bash -m -U &&\ - mkdir -p /var/www +# Remove the code added on base image +RUN rm -rf /var/www/* # Give discourse user no-passwd sudo permissions (for bundle install) ADD sudoers.discourse /etc/sudoers.d/discourse diff --git a/image/discourse_test/Dockerfile b/image/discourse_test/Dockerfile index e709573..1792736 100644 --- a/image/discourse_test/Dockerfile +++ b/image/discourse_test/Dockerfile @@ -1,6 +1,6 @@ # NAME: discourse/discourse_test -# VERSION: 1.3.10 -FROM discourse/discourse:1.3.10 +# VERSION: build +FROM discourse/base:release MAINTAINER Sam Saffron "https://twitter.com/samsaffron" -- 2.25.1