-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0518b0b
Showing
22 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Gemfile.lock | ||
coverage | ||
.ruby-version | ||
*.sublime-* | ||
*.gem | ||
pkg | ||
.vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
source "https://rubygems.org" | ||
gemspec | ||
|
||
group :development do | ||
gem "vagrant", git: "https://github.com/mitchellh/vagrant.git", tag: "v1.7.2" | ||
end | ||
|
||
group :plugins do | ||
gem "vagrant-docker-compose", path: "." | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Copyright (c) 2015, Leigh McCulloch | ||
|
||
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. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Vagrant Provisioner: Docker Compose | ||
|
||
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/). | ||
|
||
## Install | ||
|
||
```bash | ||
vagrant plugin install vagrant-docker-compose | ||
``` | ||
|
||
## Usage | ||
|
||
### To install docker and docker-compose | ||
|
||
```ruby | ||
Vagrant.configure("2") do |config| | ||
config.vm.box = "ubuntu/trusty64" | ||
|
||
config.vm.provision :docker | ||
config.vm.provision :docker_compose | ||
end | ||
``` | ||
|
||
### To install and run docker-compose on `vagrant up` | ||
|
||
```ruby | ||
Vagrant.configure("2") do |config| | ||
config.vm.box = "ubuntu/trusty64" | ||
|
||
config.vm.provision :docker | ||
config.vm.provision :docker_compose, yml: "/vagrant/docker-compose.yml", run: "always" | ||
end | ||
``` | ||
|
||
Equivalent to running: | ||
|
||
```bash | ||
docker-compose -f [yml] up | ||
``` | ||
|
||
### To install, rebuild and run docker-compose on `vagrant up` | ||
|
||
```ruby | ||
Vagrant.configure("2") do |config| | ||
config.vm.box = "ubuntu/trusty64" | ||
|
||
config.vm.provision :docker | ||
config.vm.provision :docker_compose, yml: "/vagrant/docker-compose.yml", rebuild: true, run: "always" | ||
end | ||
``` | ||
|
||
Equivalent to running: | ||
|
||
```bash | ||
docker-compose -f [yml] rm | ||
docker-compose -f [yml] build | ||
docker-compose -f [yml] up | ||
``` | ||
|
||
## Example | ||
|
||
See `example` in the repository for a full working example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require "rubygems" | ||
require "bundler/setup" | ||
Bundler::GemHelper.install_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
Vagrant.configure("2") do |config| | ||
config.vm.box = "ubuntu/trusty64" | ||
|
||
config.vm.network(:forwarded_port, guest: 8080, host: 8080) | ||
|
||
config.vm.provision :docker | ||
config.vm.provision :docker_compose, yml: "/vagrant/docker-compose.yml", rebuild: true, run: "always" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM ubuntu:14.04 | ||
WORKDIR /app | ||
CMD while true ; do nc -l 8080 < /app/index.html ; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<title>An App</title> | ||
</head> | ||
<body> | ||
<h1>An App</h1> | ||
<p>An app that serves static.</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
while true ; do nc -l 8080 < /app/index.html ; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
app: | ||
build: ./app | ||
links: | ||
- redis | ||
ports: | ||
- "8080:8080" | ||
volumes: | ||
- ./app/:/app/ | ||
redis: | ||
image: redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require "pathname" | ||
|
||
require "vagrant-docker-compose/plugin" | ||
|
||
module VagrantPlugins | ||
module DockerComposeProvisioner | ||
def self.source_root | ||
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__)) | ||
end | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
lib/vagrant-docker-compose/cap/linux/docker_compose_install.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module VagrantPlugins | ||
module DockerComposeProvisioner | ||
module Cap | ||
module Linux | ||
module DockerComposeInstall | ||
def self.docker_compose_install(machine) | ||
machine.communicate.tap do |comm| | ||
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 | ||
chmod +x /usr/local/bin/docker-compose") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
lib/vagrant-docker-compose/cap/linux/docker_compose_installed.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module VagrantPlugins | ||
module DockerComposeProvisioner | ||
module Cap | ||
module Linux | ||
module DockerComposeInstalled | ||
def self.docker_compose_installed(machine) | ||
paths = [ | ||
"/usr/local/bin/docker-compose" | ||
] | ||
|
||
paths.all? do |p| | ||
machine.communicate.test("test -f #{p}", sudo: true) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module VagrantPlugins | ||
module DockerComposeProvisioner | ||
class Config < Vagrant.plugin("2", :config) | ||
attr_accessor :yml, :rebuild | ||
|
||
def yml=(yml) | ||
raise DockerComposeError, :yml_must_be_absolute if !Pathname.new(yml).absolute? | ||
@yml = yml | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require "pathname" | ||
|
||
module VagrantPlugins | ||
module DockerComposeProvisioner | ||
class DockerCompose | ||
def initialize(machine, config) | ||
@machine = machine | ||
@config = config | ||
end | ||
|
||
def build | ||
@machine.ui.detail(I18n.t(:docker_compose_build)) | ||
@machine.communicate.tap do |comm| | ||
comm.sudo("docker-compose -f \"#{@config.yml}\" build") do |type, data| | ||
handle_comm(type, data) | ||
end | ||
end | ||
end | ||
|
||
def rm | ||
@machine.ui.detail(I18n.t(:docker_compose_rm)) | ||
@machine.communicate.tap do |comm| | ||
comm.sudo("docker-compose -f \"#{@config.yml}\" rm --force") do |type, data| | ||
handle_comm(type, data) | ||
end | ||
end | ||
end | ||
|
||
def up | ||
@machine.ui.detail(I18n.t(:docker_compose_up)) | ||
@machine.communicate.tap do |comm| | ||
comm.sudo("docker-compose -f \"#{@config.yml}\" up -d") do |type, data| | ||
handle_comm(type, data) | ||
end | ||
end | ||
end | ||
|
||
protected | ||
|
||
def handle_comm(type, data) | ||
data.chomp! | ||
return if data.empty? | ||
case type | ||
when :stdout; @machine.ui.detail(data) | ||
when :stderr; @machine.ui.error(data) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module VagrantPlugins | ||
module DockerComposeProvisioner | ||
class DockerComposeError < Vagrant::Errors::VagrantError | ||
error_namespace("errors") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module VagrantPlugins | ||
module DockerComposeProvisioner | ||
class Installer | ||
def initialize(machine) | ||
@machine = machine | ||
end | ||
|
||
def ensure_installed | ||
@machine.ui.detail(I18n.t(:checking_installation)) | ||
|
||
if !@machine.guest.capability(:docker_compose_installed) | ||
@machine.ui.detail(I18n.t(:installing)) | ||
@machine.guest.capability(:docker_compose_install) | ||
|
||
if !@machine.guest.capability(:docker_compose_installed) | ||
raise DockerComposeError, :install_failed | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
en: | ||
errors: | ||
yml_must_be_absolute: Docker Compose YML path must be absolute! | ||
not_supported_on_guest: Not supported on the guest operating system | ||
checking_installation: Checking for Docker Compose installation... | ||
installing: Installing Docker Compose | ||
docker_compose_up: Running docker-compose up... | ||
docker_compose_rm: Running docker-compose rm... | ||
docker_compose_build: Running docker-compose build... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module VagrantPlugins | ||
module DockerComposeProvisioner | ||
class Plugin < Vagrant.plugin("2") | ||
name "docker-compose-provisioner" | ||
description <<-DESC | ||
Provides support for provisioning your virtual machines with Docker-Compose. | ||
DESC | ||
|
||
I18n.load_path << File.expand_path("../locales/en.yml", __FILE__) | ||
I18n.reload! | ||
|
||
config(:docker_compose, :provisioner) do | ||
require_relative "config" | ||
Config | ||
end | ||
|
||
guest_capability("linux", "docker_compose_installed") do | ||
require_relative "cap/linux/docker_compose_installed" | ||
Cap::Linux::DockerComposeInstalled | ||
end | ||
|
||
guest_capability("linux", "docker_compose_install") do | ||
require_relative "cap/linux/docker_compose_install" | ||
Cap::Linux::DockerComposeInstall | ||
end | ||
|
||
provisioner(:docker_compose) do | ||
require_relative "provisioner" | ||
Provisioner | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require_relative "errors/docker_compose_error" | ||
require_relative "installer" | ||
require_relative "docker_compose" | ||
|
||
module VagrantPlugins | ||
module DockerComposeProvisioner | ||
class Provisioner < Vagrant.plugin("2", :provisioner) | ||
def initialize(machine, config, installer = nil, docker_compose = nil) | ||
super(machine, config) | ||
|
||
@installer = installer || Installer.new(@machine) | ||
@docker_compose = docker_compose || DockerCompose.new(@machine, @config) | ||
end | ||
|
||
def provision | ||
@installer.ensure_installed | ||
|
||
return unless @config.yml | ||
|
||
if @config.rebuild | ||
@docker_compose.rm | ||
@docker_compose.build | ||
end | ||
|
||
@docker_compose.up | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module VagrantPlugins | ||
module DockerComposeProvisioner | ||
VERSION = "0.0.1" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
lib = File.expand_path("../lib", __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
|
||
require "vagrant-docker-compose/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "vagrant-docker-compose" | ||
s.version = VagrantPlugins::DockerComposeProvisioner::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["Leigh McCulloch"] | ||
s.homepage = "https://github.com/leighmcculloch/vagrant-docker-compose" | ||
s.summary = %q{A Vagrant provisioner for docker compose.} | ||
s.description = %q{A Vagrant provisioner for docker compose.} | ||
|
||
s.files = `git ls-files -z`.split("\0") | ||
s.require_path = "lib" | ||
end |
0518b0b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leighmcculloch this is exactly what I was looking for and it works great. Thanks for the good job! 👍
0518b0b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries @leafac 😄