Use supervisord to start postgres + apache2 when the api
authorTim Pierce <twp@clinicalfuture.com>
Mon, 11 Nov 2013 17:32:45 +0000 (12:32 -0500)
committerTim Pierce <twp@clinicalfuture.com>
Mon, 11 Nov 2013 17:32:45 +0000 (12:32 -0500)
container is launched.

Move generated files to an api/generated directory for
easier ignoring.

.gitignore
docker/api/Dockerfile
docker/base/Dockerfile
docker/build.sh
docker/config.rb

index 2f836aacf266b3e7fc17ec2d8a99aa68c904c1b9..5d5cf5ed4ff607cbe0389ffb836eea8fec60edf5 100644 (file)
@@ -1,2 +1,3 @@
 *~
 *.pyc
+docker/api/generated/*
\ No newline at end of file
index 19c76a410bda45fe594e46eeb88b9697023dec57..68c20ec7555f1bbf95065e304eb4c330f2dbb0d5 100644 (file)
@@ -5,33 +5,41 @@ MAINTAINER Tim Pierce <twp@clinicalfuture.com>
 
 # Install postgres and apache
 RUN apt-get -q -y install procps postgresql postgresql-server-dev-9.1 apache2 \
-    libcurl4-openssl-dev apache2-threaded-dev libapr1-dev libaprutil1-dev
-
-# Configure databases and users.
-ADD config_databases.sh /tmp/
-RUN sh /tmp/config_databases.sh
-RUN rm /tmp/config_databases.sh
+    libcurl4-openssl-dev apache2-threaded-dev libapr1-dev libaprutil1-dev \
+    supervisor
 
 # Install gems needed for API server
 RUN bundle install --gemfile=/usr/src/arvados/services/api/Gemfile
 
+# Install generated config files
+ADD generated/database.yml /usr/src/arvados/services/api/config/database.yml
+ADD generated/secret_token.rb /usr/src/arvados/services/api/config/initializers/secret_token.rb
+ADD generated/omniauth.rb /usr/src/arvados/services/api/config/initializers/omniauth.rb
+ADD generated/production.rb /usr/src/arvados/services/api/config/environments/production.rb
+
+# Configure databases and users.
+ADD generated/config_databases.sh /tmp/config_databases.sh
+RUN sh /tmp/config_databases.sh ; \
+    rm /tmp/config_databases.sh
+
 # Set up the Rails database. This has to be done in a script so that
 # postgres can run in the background while running rake db:setup.
 ENV RAILS_ENV production
-ADD database.yml /usr/src/arvados/services/api/config/database.yml
 ADD config_rake.sh /tmp/config_rake.sh
-RUN sh /tmp/config_rake.sh
+RUN sh /tmp/config_rake.sh ; \
+    rm /tmp/config_rake.sh
 
-ADD secret_token.rb /usr/src/arvados/services/api/config/initializers/secret_token.rb
-ADD omniauth.rb /usr/src/arvados/services/api/config/initializers/omniauth.rb
-ADD production.rb /usr/src/arvados/services/api/config/environments/production.rb
-
-# Configure Apache.
+# Configure Apache and Passenger.
 ADD apache2_vhost /etc/apache2/sites-available/arvados
-RUN a2dissite default
-RUN a2ensite arvados
-
-# Configure Passenger.
-RUN passenger-install-apache2-module --auto
-RUN a2enmod rewrite
 ADD passenger.conf /etc/apache2/conf.d/passenger
+RUN a2dissite default ; \
+    a2ensite arvados ; \
+    a2enmod rewrite ; \
+    passenger-install-apache2-module --auto
+
+# Supervisor.
+ADD supervisor.conf /etc/supervisor/conf.d/arvados.conf
+ADD apache2_foreground.sh /etc/apache2/foreground.sh
+
+# Start the supervisor.
+CMD ["/usr/bin/supervisord", "-n"]
index b864e2863637747e380ed371c97451472f21be3d..c325484a02afe7854bb8a02a24e969d637ad3a6d 100644 (file)
@@ -4,30 +4,19 @@
 FROM arvados/debian:wheezy
 MAINTAINER Tim Pierce <twp@clinicalfuture.com>
 
-# TODO(twp): parameterize variables via autoconf or similar.
-ENV RUBY_VERSION_NUM   2.0.0
-
 # Install prerequisite packages for Arvados
-RUN apt-get update
-RUN apt-get -q -y install -q -y apt-utils
-RUN apt-get -q -y install git curl
-RUN curl -L https://get.rvm.io | bash -s stable --ruby=${RUBY_VERSION_NUM}
+#   * git, curl, rvm
+#   * Arvados source code
+#
+RUN apt-get update && \
+    apt-get -q -y install -q -y apt-utils && \
+    apt-get -q -y install git curl && \
+    git clone git://github.com/clinicalfuture/arvados.git /usr/src/arvados && \
+    curl -L https://get.rvm.io | bash -s stable --ruby=2.0.0
 
 # Set up RVM environment. These are just the env variables created by
 # /usr/local/rvm/scripts/rvm, which can't be run from a non-login shell.
 # TODO(twp): figure out a less awful solution.
-ENV RUBY_VERSION ruby-2.0.0-p247
-ENV MY_RUBY_HOME /usr/local/rvm/rubies/ruby-2.0.0-p247
 ENV GEM_HOME /usr/local/rvm/gems/ruby-2.0.0-p247
 ENV GEM_PATH /usr/local/rvm/gems/ruby-2.0.0-p247:/usr/local/rvm/gems/ruby-2.0.0-p247@global
-ENV IRBRC /usr/local/rvm/rubies/ruby-2.0.0-p247/.irbrc
-ENV rvm_path /usr/local/rvm
-ENV rvm_prefix /usr/local
-ENV rvm_env_string ruby-2.0.0-p247
-ENV rvm_version 1.23.13 (stable)
-ENV rvm_ruby_string ruby-2.0.0-p247
 ENV PATH /usr/local/rvm/gems/ruby-2.0.0-p247/bin:/usr/local/rvm/gems/ruby-2.0.0-p247@global/bin:/usr/local/rvm/rubies/ruby-2.0.0-p247/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
-
-# Download Arvados source.
-RUN git clone git://github.com/clinicalfuture/arvados.git /usr/src/arvados
-
index 6edebb9d7a6a4ec6e9a3e557b1e1947e699a991d..5790662b570799d5bd9999dfa5d128dc8a8810cf 100755 (executable)
@@ -5,5 +5,5 @@
   ./mkimage-debootstrap.sh arvados/debian wheezy http://debian.lcs.mit.edu/debian/
 
 # build the Docker images
-docker build -rm -t arvados/base base
-docker build -rm -t arvados/api api
+docker build -t arvados/base base
+docker build -t arvados/api api
index 49004dad825b4f8c915e4374de4e704b18e98349..05b95d5125a48a74d0fb350cf983dffaf2438865 100755 (executable)
@@ -30,9 +30,16 @@ end
 # For each *.in file in the docker directories, substitute any
 # @@variables@@ found in the file with the appropriate config
 # variable.
+# 
+# TODO(twp): add the *.in files directory to the source tree, and
+# when expanding them, add them to the "generated" directory with
+# the same tree structure as in the original source. Then all
+# the files can be added to the docker container with a single ADD.
 
 Dir.glob('*/*.in') do |template_file|
-  output_path = template_file.sub(/\.in$/, '')
+  generated_dir = File.join(File.dirname(template_file), 'generated')
+  Dir.mkdir(generated_dir) unless Dir.exists? generated_dir
+  output_path = File.join(generated_dir, File.basename(template_file, '.in'))
   output = File.open(output_path, "w")
   File.open(template_file) do |input|
     input.each_line do |line|