vagrant-docker-compose 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf8ba0c93bda9be46839f18d7cf5924d2577e395
4
+ data.tar.gz: 8401fba5f9a5ac7610bb2113813d707d06e61439
5
+ SHA512:
6
+ metadata.gz: 2b9af03300b64975dac1c44d987015ee609a37d88fc8b4f81cf941fa84f23c8fb07985980fd72b782a1116849631926ee89695154996f4490059d629817d71d3
7
+ data.tar.gz: d35123277d106baa4baa87123c8113351ec421602b40326ae08a2105edfd6ec25c194a328bfd0da1caeff42930b9b52b98179a50d9c46fd558ed90f7783991a3
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ Gemfile.lock
2
+ coverage
3
+ .ruby-version
4
+ *.sublime-*
5
+ *.gem
6
+ pkg
7
+ .vagrant
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ group :development do
5
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git", tag: "v1.7.2"
6
+ end
7
+
8
+ group :plugins do
9
+ gem "vagrant-docker-compose", path: "."
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ Copyright (c) 2015, Leigh McCulloch
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
+
5
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Vagrant Provisioner: Docker Compose
2
+
3
+ A Vagrant provisioner for [Docker Compose](https://docs.docker.com/compose/). Installs Docker Compose and can also bring up the containers defined by a [docker-compose.yml](https://docs.docker.com/compose/yml/).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ vagrant plugin install vagrant-docker-compose
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### To install docker and docker-compose
14
+
15
+ ```ruby
16
+ Vagrant.configure("2") do |config|
17
+ config.vm.box = "ubuntu/trusty64"
18
+
19
+ config.vm.provision :docker
20
+ config.vm.provision :docker_compose
21
+ end
22
+ ```
23
+
24
+ ### To install and run docker-compose on `vagrant up`
25
+
26
+ ```ruby
27
+ Vagrant.configure("2") do |config|
28
+ config.vm.box = "ubuntu/trusty64"
29
+
30
+ config.vm.provision :docker
31
+ config.vm.provision :docker_compose, yml: "/vagrant/docker-compose.yml", run: "always"
32
+ end
33
+ ```
34
+
35
+ Equivalent to running:
36
+
37
+ ```bash
38
+ docker-compose -f [yml] up
39
+ ```
40
+
41
+ ### To install, rebuild and run docker-compose on `vagrant up`
42
+
43
+ ```ruby
44
+ Vagrant.configure("2") do |config|
45
+ config.vm.box = "ubuntu/trusty64"
46
+
47
+ config.vm.provision :docker
48
+ config.vm.provision :docker_compose, yml: "/vagrant/docker-compose.yml", rebuild: true, run: "always"
49
+ end
50
+ ```
51
+
52
+ Equivalent to running:
53
+
54
+ ```bash
55
+ docker-compose -f [yml] rm
56
+ docker-compose -f [yml] build
57
+ docker-compose -f [yml] up
58
+ ```
59
+
60
+ ## Example
61
+
62
+ See `example` in the repository for a full working example.
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "ubuntu/trusty64"
6
+
7
+ config.vm.network(:forwarded_port, guest: 8080, host: 8080)
8
+
9
+ config.vm.provision :docker
10
+ config.vm.provision :docker_compose, yml: "/vagrant/docker-compose.yml", rebuild: true, run: "always"
11
+ end
@@ -0,0 +1,3 @@
1
+ FROM ubuntu:14.04
2
+ WORKDIR /app
3
+ CMD while true ; do nc -l 8080 < /app/index.html ; done
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <title>An App</title>
4
+ </head>
5
+ <body>
6
+ <h1>An App</h1>
7
+ <p>An app that serves static.</p>
8
+ </body>
9
+ </html>
@@ -0,0 +1 @@
1
+ while true ; do nc -l 8080 < /app/index.html ; done
@@ -0,0 +1,10 @@
1
+ app:
2
+ build: ./app
3
+ links:
4
+ - redis
5
+ ports:
6
+ - "8080:8080"
7
+ volumes:
8
+ - ./app/:/app/
9
+ redis:
10
+ image: redis
@@ -0,0 +1,11 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-docker-compose/plugin"
4
+
5
+ module VagrantPlugins
6
+ module DockerComposeProvisioner
7
+ def self.source_root
8
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module DockerComposeProvisioner
3
+ module Cap
4
+ module Linux
5
+ module DockerComposeInstall
6
+ def self.docker_compose_install(machine)
7
+ machine.communicate.tap do |comm|
8
+ comm.sudo("curl -L https://github.com/docker/compose/releases/download/1.2.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
9
+ chmod +x /usr/local/bin/docker-compose")
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module DockerComposeProvisioner
3
+ module Cap
4
+ module Linux
5
+ module DockerComposeInstalled
6
+ def self.docker_compose_installed(machine)
7
+ paths = [
8
+ "/usr/local/bin/docker-compose"
9
+ ]
10
+
11
+ paths.all? do |p|
12
+ machine.communicate.test("test -f #{p}", sudo: true)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ module VagrantPlugins
2
+ module DockerComposeProvisioner
3
+ class Config < Vagrant.plugin("2", :config)
4
+ attr_accessor :yml, :rebuild
5
+
6
+ def yml=(yml)
7
+ raise DockerComposeError, :yml_must_be_absolute if !Pathname.new(yml).absolute?
8
+ @yml = yml
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,50 @@
1
+ require "pathname"
2
+
3
+ module VagrantPlugins
4
+ module DockerComposeProvisioner
5
+ class DockerCompose
6
+ def initialize(machine, config)
7
+ @machine = machine
8
+ @config = config
9
+ end
10
+
11
+ def build
12
+ @machine.ui.detail(I18n.t(:docker_compose_build))
13
+ @machine.communicate.tap do |comm|
14
+ comm.sudo("docker-compose -f \"#{@config.yml}\" build") do |type, data|
15
+ handle_comm(type, data)
16
+ end
17
+ end
18
+ end
19
+
20
+ def rm
21
+ @machine.ui.detail(I18n.t(:docker_compose_rm))
22
+ @machine.communicate.tap do |comm|
23
+ comm.sudo("docker-compose -f \"#{@config.yml}\" rm --force") do |type, data|
24
+ handle_comm(type, data)
25
+ end
26
+ end
27
+ end
28
+
29
+ def up
30
+ @machine.ui.detail(I18n.t(:docker_compose_up))
31
+ @machine.communicate.tap do |comm|
32
+ comm.sudo("docker-compose -f \"#{@config.yml}\" up -d") do |type, data|
33
+ handle_comm(type, data)
34
+ end
35
+ end
36
+ end
37
+
38
+ protected
39
+
40
+ def handle_comm(type, data)
41
+ data.chomp!
42
+ return if data.empty?
43
+ case type
44
+ when :stdout; @machine.ui.detail(data)
45
+ when :stderr; @machine.ui.error(data)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ module VagrantPlugins
2
+ module DockerComposeProvisioner
3
+ class DockerComposeError < Vagrant::Errors::VagrantError
4
+ error_namespace("errors")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ module VagrantPlugins
2
+ module DockerComposeProvisioner
3
+ class Installer
4
+ def initialize(machine)
5
+ @machine = machine
6
+ end
7
+
8
+ def ensure_installed
9
+ @machine.ui.detail(I18n.t(:checking_installation))
10
+
11
+ if !@machine.guest.capability(:docker_compose_installed)
12
+ @machine.ui.detail(I18n.t(:installing))
13
+ @machine.guest.capability(:docker_compose_install)
14
+
15
+ if !@machine.guest.capability(:docker_compose_installed)
16
+ raise DockerComposeError, :install_failed
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ en:
2
+ errors:
3
+ yml_must_be_absolute: Docker Compose YML path must be absolute!
4
+ not_supported_on_guest: Not supported on the guest operating system
5
+ checking_installation: Checking for Docker Compose installation...
6
+ installing: Installing Docker Compose
7
+ docker_compose_up: Running docker-compose up...
8
+ docker_compose_rm: Running docker-compose rm...
9
+ docker_compose_build: Running docker-compose build...
@@ -0,0 +1,33 @@
1
+ module VagrantPlugins
2
+ module DockerComposeProvisioner
3
+ class Plugin < Vagrant.plugin("2")
4
+ name "docker-compose-provisioner"
5
+ description <<-DESC
6
+ Provides support for provisioning your virtual machines with Docker-Compose.
7
+ DESC
8
+
9
+ I18n.load_path << File.expand_path("../locales/en.yml", __FILE__)
10
+ I18n.reload!
11
+
12
+ config(:docker_compose, :provisioner) do
13
+ require_relative "config"
14
+ Config
15
+ end
16
+
17
+ guest_capability("linux", "docker_compose_installed") do
18
+ require_relative "cap/linux/docker_compose_installed"
19
+ Cap::Linux::DockerComposeInstalled
20
+ end
21
+
22
+ guest_capability("linux", "docker_compose_install") do
23
+ require_relative "cap/linux/docker_compose_install"
24
+ Cap::Linux::DockerComposeInstall
25
+ end
26
+
27
+ provisioner(:docker_compose) do
28
+ require_relative "provisioner"
29
+ Provisioner
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ require_relative "errors/docker_compose_error"
2
+ require_relative "installer"
3
+ require_relative "docker_compose"
4
+
5
+ module VagrantPlugins
6
+ module DockerComposeProvisioner
7
+ class Provisioner < Vagrant.plugin("2", :provisioner)
8
+ def initialize(machine, config, installer = nil, docker_compose = nil)
9
+ super(machine, config)
10
+
11
+ @installer = installer || Installer.new(@machine)
12
+ @docker_compose = docker_compose || DockerCompose.new(@machine, @config)
13
+ end
14
+
15
+ def provision
16
+ @installer.ensure_installed
17
+
18
+ return unless @config.yml
19
+
20
+ if @config.rebuild
21
+ @docker_compose.rm
22
+ @docker_compose.build
23
+ end
24
+
25
+ @docker_compose.up
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module DockerComposeProvisioner
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require "vagrant-docker-compose/version"
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = "vagrant-docker-compose"
10
+ s.version = VagrantPlugins::DockerComposeProvisioner::VERSION
11
+ s.platform = Gem::Platform::RUBY
12
+ s.authors = ["Leigh McCulloch"]
13
+ s.homepage = "https://github.com/leighmcculloch/vagrant-docker-compose"
14
+ s.summary = %q{A Vagrant provisioner for docker compose.}
15
+ s.description = %q{A Vagrant provisioner for docker compose.}
16
+
17
+ s.files = `git ls-files -z`.split("\0")
18
+ s.require_path = "lib"
19
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-docker-compose
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Leigh McCulloch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Vagrant provisioner for docker compose.
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".gitignore"
20
+ - Gemfile
21
+ - LICENSE
22
+ - README.md
23
+ - Rakefile
24
+ - example/Vagrantfile
25
+ - example/app/Dockerfile
26
+ - example/app/index.html
27
+ - example/app/init.sh
28
+ - example/docker-compose.yml
29
+ - lib/vagrant-docker-compose.rb
30
+ - lib/vagrant-docker-compose/cap/linux/docker_compose_install.rb
31
+ - lib/vagrant-docker-compose/cap/linux/docker_compose_installed.rb
32
+ - lib/vagrant-docker-compose/config.rb
33
+ - lib/vagrant-docker-compose/docker_compose.rb
34
+ - lib/vagrant-docker-compose/errors/docker_compose_error.rb
35
+ - lib/vagrant-docker-compose/installer.rb
36
+ - lib/vagrant-docker-compose/locales/en.yml
37
+ - lib/vagrant-docker-compose/plugin.rb
38
+ - lib/vagrant-docker-compose/provisioner.rb
39
+ - lib/vagrant-docker-compose/version.rb
40
+ - vagrant-docker-compose.gemspec
41
+ homepage: https://github.com/leighmcculloch/vagrant-docker-compose
42
+ licenses: []
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.4.3
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: A Vagrant provisioner for docker compose.
64
+ test_files: []