Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Vagrant setup and fixed the Dockerfile so it actually works #222

Merged
merged 4 commits into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vagrant/
.ruby-version
Gemfile.lock
Gemfile.local
Expand Down
17 changes: 9 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this * here failed for me when I had a Gemfile + a Gemfile.lock
I don't know why there is a * wildcard here?

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}
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions vmpooler.yaml.dummy-example
Original file line number Diff line number Diff line change
@@ -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