Merge pull request #222 from puppetlabs/docker-in-vagrant

Added Vagrant setup and fixed the Dockerfile so it actually works
This commit is contained in:
Samuel 2017-06-20 14:45:16 +01:00 committed by GitHub
commit c0913ed7c7
5 changed files with 120 additions and 8 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.vagrant/
.ruby-version
Gemfile.lock
Gemfile.local

View file

@ -8,24 +8,25 @@
# RUN:
# docker run -e VMPOOLER_CONFIG -p 80:4567 -it vmpooler
FROM jruby:1.7-jdk
FROM jruby:9.1-jdk
RUN mkdir -p /var/lib/vmpooler && mkdir /var/log/vmpooler
RUN mkdir -p /var/lib/vmpooler
WORKDIR /var/lib/vmpooler
ADD Gemfile* /var/lib/vmpooler
ADD Gemfile* /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
RUN apt-get update && apt-get install -y redis-server && rm -rf /var/lib/apt/lists/*
COPY . /var/lib/vmpooler
ENTRYPOINT \
ENV VMPOOLER_LOG /var/log/vmpooler.log
CMD \
/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
&& while [ ! -f ${VMPOOLER_LOG} ]; do sleep 1; done ; \
tail -f ${VMPOOLER_LOG}

View file

@ -68,6 +68,49 @@ 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
```
### Running Docker inside Vagrant
A [Vagrantfile](Vagrantfile) is also included in this repository so that you dont have to run Docker on your local computer.
To use it run:
```
vagrant up
vagrant ssh
docker run -p 8080:4567 -v /vagrant/vmpooler.yaml.example:/var/lib/vmpooler/vmpooler.yaml -it --rm --name pooler vmpooler
```
To run vmpooler with the example dummy provider you can replace the above docker command with this:
```
docker run -e VMPOOLER_DEBUG=true -p 8080:4567 -v /vagrant/vmpooler.yaml.dummy-example:/var/lib/vmpooler/vmpooler.yaml -e VMPOOLER_LOG='/var/log/vmpooler/vmpooler.log' -it --rm --name pooler vmpooler
```
Either variation will allow you to access the dashboard from [localhost:8080](http://localhost:8080/).
### Running directly in Vagrant
You can also run vmpooler directly in the Vagrant box. To do so run this:
```
vagrant up
vagrant ssh
cd /vagrant
# Do this if using the dummy provider
export VMPOOLER_DEBUG=true
cp vmpooler.yaml.dummy-example vmpooler.yaml
# vmpooler needs a redis server.
sudo yum -y install redis
sudo systemctl start redis
gem install bundler
bundle install
bundle exec ruby vmpooler
```
When run this way you can access vmpooler from your local computer via [localhost:4567](http://localhost:4567/).
## 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.

19
Vagrantfile vendored Normal file
View file

@ -0,0 +1,19 @@
# vim: autoindent tabstop=2 shiftwidth=2 expandtab softtabstop=2 filetype=ruby
Vagrant.configure("2") do |config|
config.vm.box = "genebean/centos-7-rvm-221"
config.vm.network "forwarded_port", guest: 4567, host: 4567
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.provision "shell", inline: <<-SCRIPT
mkdir /var/log/vmpooler
chown vagrant:vagrant /var/log/vmpooler
yum -y install docker
groupadd docker
usermod -aG docker vagrant
systemctl enable docker
systemctl start docker
docker build -t vmpooler /vagrant
docker images
echo 'To use the container with the dummy provider do this after "vagrant ssh":'
echo "docker run -e VMPOOLER_DEBUG=true -p 8080:4567 -v /vagrant/vmpooler.yaml.dummy-example:/var/lib/vmpooler/vmpooler.yaml -e VMPOOLER_LOG='/var/log/vmpooler/vmpooler.log' -it --rm --name pooler vmpooler"
SCRIPT
end

View file

@ -0,0 +1,48 @@
---
:providers:
:dummy:
filename: '/tmp/dummy-backing.yaml'
:redis:
server: 'localhost'
:auth:
provider: 'dummy'
:tagfilter:
url: '(.*)\/'
:config:
site_name: 'vmpooler'
logfile: '/var/log/vmpooler/vmpooler.log'
task_limit: 10
timeout: 15
vm_checktime: 15
vm_lifetime: 12
vm_lifetime_auth: 24
allowed_tags:
- 'created_by'
- 'project'
domain: 'company.com'
prefix: 'poolvm-'
:pools:
- name: 'debian-7-i386'
alias: [ 'debian-7-32' ]
template: 'Templates/debian-7-i386'
folder: 'Pooled VMs/debian-7-i386'
datastore: 'vmstorage'
size: 5
timeout: 15
ready_ttl: 1440
provider: dummy
- name: 'debian-7-x86_64'
alias: [ 'debian-7-64', 'debian-7-amd64' ]
template: 'Templates/debian-7-x86_64'
folder: 'Pooled VMs/debian-7-x86_64'
datastore: 'vmstorage'
size: 5
timeout: 15
ready_ttl: 1440
provider: dummy