From c5aedc12cb907198ab70226ce94e1271eedb92a8 Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Sat, 19 Nov 2016 09:54:42 -0800 Subject: [PATCH 1/5] Add an all-in-one Dockerfile Built off the [jruby](https://hub.docker.com/_/jruby/) `Dockerfile`, it installs gem requirements via `bundler`, installs and runs a `redis-server`, imports the current working directory, starts `vmpooler`, and tails the logfile. Creating a `vmpooler.yaml` configuration file in the current working directory and running the following provides a development environment: ``` docker build -t vmpooler . && docker run -p 80:4567 -it vmpooler ``` --- Dockerfile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3cad897 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM jruby:1.7-jdk + +RUN mkdir -p /var/lib/vmpooler +WORKDIR /var/lib/vmpooler + +ADD Gemfile /var/lib/vmpooler +ADD Gemfile.lock /var/lib/vmpooler +RUN bundle install --system + +RUN ln -s /opt/jruby/bin/jruby /usr/bin/jruby + +RUN echo "deb http://httpredir.debian.org/debian jessie main" >/etc/apt/sources.list.d/jessie-main.list +RUN apt-get update +RUN apt-get install -y redis-server + +COPY . /var/lib/vmpooler + +ENTRYPOINT \ + /etc/init.d/redis-server start \ + && /var/lib/vmpooler/scripts/vmpooler_init.sh start \ + && while [ ! -f /var/log/vmpooler.log ]; do sleep 1; done ; \ + tail -f /var/log/vmpooler.log From efe21b27cdfda27f9edb5a839bb1a6b65e1dcfec Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Tue, 20 Dec 2016 10:41:45 -0800 Subject: [PATCH 2/5] Allow configuration to be defined in an ENV var If `ENV['VMPOOLER_CONFIG']` is defined, it is read in as a YAML configuration. This allows vmpooler to run in a docker daemon via `docker run -e VMPOOLER_CONFIG -p 80:4567 -it vmpooler` rather than embedding a YAML file within the container. --- lib/vmpooler.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/vmpooler.rb b/lib/vmpooler.rb index 0e5707c..844aa6e 100644 --- a/lib/vmpooler.rb +++ b/lib/vmpooler.rb @@ -21,11 +21,18 @@ module Vmpooler end def self.config(filepath='vmpooler.yaml') - # Load the configuration file - config_file = File.expand_path(filepath) - parsed_config = YAML.load_file(config_file) + parsed_config = {} - # Set some defaults + if ENV['VMPOOLER_CONFIG'] + # Load configuration from ENV + parsed_config = YAML.load(ENV['VMPOOLER_CONFIG']) + else + # Load the configuration file from disk + config_file = File.expand_path(filepath) + parsed_config = YAML.load_file(config_file) + end + + # Set some configuration defaults parsed_config[:redis] ||= {} parsed_config[:redis]['server'] ||= 'localhost' parsed_config[:redis]['data_ttl'] ||= 168 From 833e34ce37cdc5cf961e3e3aabd197c88a3963f4 Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Tue, 20 Dec 2016 10:45:28 -0800 Subject: [PATCH 3/5] Update Dockerfile to move Gemflie* ...instead of Gemfile and Gemfile.lock (if it exists) individually --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3cad897..d9ba426 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,7 @@ FROM jruby:1.7-jdk RUN mkdir -p /var/lib/vmpooler WORKDIR /var/lib/vmpooler -ADD Gemfile /var/lib/vmpooler -ADD Gemfile.lock /var/lib/vmpooler +ADD Gemfile* /var/lib/vmpooler RUN bundle install --system RUN ln -s /opt/jruby/bin/jruby /usr/bin/jruby From d85f84011f51f595641a13d15a03c9286c814ef6 Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Tue, 20 Dec 2016 10:54:09 -0800 Subject: [PATCH 4/5] Add instructions for running in a Docker container --- Dockerfile | 10 ++++++++++ README.md | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/Dockerfile b/Dockerfile index d9ba426..e0a679b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,13 @@ +# Run vmpooler in a Docker container! Configuration can either be embedded +# and built within the current working directory, or stored in a +# VMPOOLER_CONFIG environment value and passed to the Docker daemon. +# +# BUILD: +# docker build -t vmpooler . +# +# RUN: +# docker run -e VMPOOLER_CONFIG -p 80:4567 -it vmpooler + FROM jruby:1.7-jdk RUN mkdir -p /var/lib/vmpooler diff --git a/README.md b/README.md index 50a8d6e..84fa2fe 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,14 @@ The following YAML configuration sets up two pools, `debian-7-i386` and `debian- See the provided YAML configuration example, [vmpooler.yaml.example](vmpooler.yaml.example), for additional configuration options and parameters. +### Running via Docker + +A [Dockerfile](Dockerfile) is included in this repository to allow running vmpooler inside a Docker container. A `vmpooler.yaml` configuration file can be embedded in the current working directory, or specified inline in a `VMPOOLER_CONFIG` environment variable. To build and run: + +``` +docker build -t vmpooler . && docker run -e VMPOOLER_CONFIG -p 80:4567 -it vmpooler +``` + ### Template set-up Template set-up is left as an exercise to the reader. Somehow, either via PXE, embedded bootstrap scripts, or some other method -- clones of VM templates need to be able to set their hostname, register themselves in your DNS, and be resolvable by the vmpooler application after completing the clone task and booting up. From 8105503b99c4d84d82685fce1225c6124381b19c Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Tue, 20 Dec 2016 10:55:12 -0800 Subject: [PATCH 5/5] Remove outdated line about template configuration --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 84fa2fe..40e29ef 100644 --- a/README.md +++ b/README.md @@ -65,11 +65,6 @@ A [Dockerfile](Dockerfile) is included in this repository to allow running vmpoo docker build -t vmpooler . && docker run -e VMPOOLER_CONFIG -p 80:4567 -it vmpooler ``` -### Template set-up - -Template set-up is left as an exercise to the reader. Somehow, either via PXE, embedded bootstrap scripts, or some other method -- clones of VM templates need to be able to set their hostname, register themselves in your DNS, and be resolvable by the vmpooler application after completing the clone task and booting up. - - ## API and Dashboard vmpooler provides an API and web front-end (dashboard) on port `:4567`. See the provided YAML configuration example, [vmpooler.yaml.example](vmpooler.yaml.example), to specify an alternative port to listen on.