Skip to content

Commit

Permalink
Add docker build support to omv.
Browse files Browse the repository at this point in the history
This is a first go at having nicely integrated docker build support in
oh-my-vagrant. Place all your docker projects in the docker/
subdirectory, and they'll get built on each machine you bring up.

We don't run them, because this is probably better left to a tool like
atomic or kubernetes.

We build on each machine, instead of selectively building certain apps
on certain machines. We should probably add the ability to filter app
names in the omv.yaml file to only include certain ones on certain machines.

This all integrates consistently with the earlier extern support.

Sadly, this patch is missing the associated DOCUMENTATION.md changes.
I'll try and make up for this by publishing a blog post and/or
screencast soon :)
  • Loading branch information
purpleidea committed Apr 1, 2015
1 parent f0aee26 commit 5787ad6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 34 deletions.
26 changes: 26 additions & 0 deletions examples/docker-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
:domain: example.com
:network: 192.168.123.0/24
:image: centos-7.0-docker
:boxurlprefix: ''
:sync: rsync
:folder: ''
:extern:
- type: git
system: docker
repository: https://github.com/purpleidea/docker-fakeapp1
directory: app1
:puppet: false
:classes: []
:docker: []
:ansible: []
:playbook: []
:cachier: false
:vms: []
:namespace: omv
:count: 1
:username: ''
:password: ''
:poolid: true
:repos: []
:reallyrm: false
23 changes: 0 additions & 23 deletions vagrant/Dockerfile

This file was deleted.

33 changes: 22 additions & 11 deletions vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,17 @@ if load_folder
# what to call it. Suggestions welcome! It's not really 'playbooks' or
# 'roles' really, so it's 'modules' until something better comes along
ansible_basedir = File.join(projectdir, folder, 'ansible/', 'modules/')
docker_basedir = File.join(projectdir, folder, 'docker/')
else
puppet_basedir = File.join(projectdir, 'puppet/', 'modules/')
ansible_basedir = File.join(projectdir, 'ansible/', 'modules/')
docker_basedir = File.join(projectdir, 'docker/')
end

native = [] # native files
native += `cd "#{puppet_basedir}" && git ls-files`.strip.split("\n")
native += `cd "#{ansible_basedir}" && git ls-files`.strip.split("\n")
native += `cd "#{docker_basedir}" && git ls-files`.strip.split("\n")

if extern.length > 0
extern.each do |i|
Expand All @@ -519,6 +522,8 @@ if extern.length > 0
basedir = puppet_basedir
elsif s == 'ansible'
basedir = ansible_basedir
elsif s == 'docker'
basedir = docker_basedir
else
$stderr.puts "Can't process extern system: '#{s}'."
next
Expand Down Expand Up @@ -569,7 +574,7 @@ if extern.length > 0
end

# clean up any directories or files that shouldn't be present
(Dir.glob(puppet_basedir+'*')+Dir.glob(ansible_basedir+'*')).uniq.each do |i|
(Dir.glob(puppet_basedir+'*')+Dir.glob(ansible_basedir+'*')+Dir.glob(docker_basedir+'*')).uniq.each do |i|
b = File.basename(i)
if not native.include?(b)
if really_use_rm
Expand Down Expand Up @@ -828,19 +833,25 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
vm.vm.provision :docker, images: vm_docker.map { |y| y.fetch(:name, nil)}.compact
end

if vm_docker.is_a?(Array)
vm_docker.each do |y|
# docker build
if vm_docker # for any value that is not false
Dir.glob(docker_basedir+'*').each do |dd|
if not File.directory?(dd)
next # invalid, skip
end
# full Dockerfile path
df = File.join(dd, 'Dockerfile')
if not(File.exists?(df)) or File.directory?(df)
next # invalid, skip
end
# app directory name containing Dockerfile
b = File.basename(dd)
vm.vm.provision :docker do |d|
# XXX y is now a hash to be used here...
# FIXME: this base dir shouldn't be /vagrant when using atomic hosts...
d.build_image "/vagrant/docker/#{b}", args: "-t #{b}"
#d.run "#{b}" # use kube instead
end
end

elsif vm_docker
vm.vm.provision :docker do |d|
# XXX
#d.build_image '/vagrant/app' # XXX: add a synced folder...
#d.run 'foo' XXX
end
end

#
Expand Down
2 changes: 2 additions & 0 deletions vagrant/docker/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Put your Docker app's in here! :)

0 comments on commit 5787ad6

Please sign in to comment.