dockerize 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'simplecov' unless RUBY_PLATFORM == 'java'
6
+ require 'pry' unless RUBY_PLATFORM == 'java'
7
+ require 'tmpdir'
8
+ require 'colored'
9
+
10
+ def tmpdir(&block)
11
+ Dir.mktmpdir('dockerize-spec') do |tmp|
12
+ yield tmp
13
+ end
14
+ end
15
+
16
+ def run(cmd = [])
17
+ cmd = cmd.split(' ') if cmd.class == String
18
+ Dockerize::Cli.send(:args=, cmd)
19
+ Dockerize::Cli.send(:ensure_project_dir)
20
+ Dockerize::Config.parse(cmd)
21
+ Dockerize::Cli.send(:set_out_stream)
22
+ end
23
+
24
+ RSpec.configure do |config|
25
+ config.before(:each) do
26
+ $stdout.stub(:print)
27
+ $stdout.stub(:puts)
28
+ end
29
+ end
30
+
31
+ unless RUBY_PLATFORM == 'java'
32
+ {
33
+ output: $stdout.clone,
34
+ prompt_name: 'dockerize',
35
+ }.map do |k, v|
36
+ Pry.config.send(:"#{k}=", v)
37
+ end
38
+ end
39
+
40
+ def top
41
+ @top ||= File.expand_path('..', File.dirname(__FILE__))
42
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ <% self.filename = 'Dockerfile' -%>
2
+ <% self.executable = false -%>
3
+ # See http://docs.docker.io/en/latest/use/builder/ for more info
4
+ FROM <%= from %>
5
+ MAINTAINER <%= maintainer %>
6
+
7
+ RUN apt-get update -yq
8
+
9
+ ADD ./.run /docker/run
10
+
11
+ EXPOSE 80 443
12
+ VOLUME["/net", "/bridge"]
13
+
14
+ CMD["/docker/run/bridge"]
@@ -0,0 +1,63 @@
1
+ <% self.filename = 'Makefile.docker' -%>
2
+ <% self.executable = false -%>
3
+ DOCKER ?= sudo docker
4
+ REV ?= $(shell git describe --always)
5
+ BUILD_FLAGS ?= -no-cache=true -rm=true
6
+ PROJECT ?= $(shell basename $(PWD))
7
+ REGISTRY ?= <%= registry %>
8
+ LATEST ?= $(shell $(DOCKER) images | grep -v REPOSITORY | head -n 1 | grep -E '<none>|$(REGISTRY)\/$(PROJECT)' | awk '{print $$3}')
9
+
10
+ export DOCKER
11
+ export REV
12
+ export BUILD_FLAGS
13
+ export PROJECT
14
+ export REGISTRY
15
+ export LATEST
16
+
17
+ # This is a general Makefile, designed to be present at the top level of your
18
+ # project for general docker development. Be sure to use `docker login` on the
19
+ # vagrant vm before trying to push or pull any containers.
20
+
21
+ all:
22
+ @echo "Available targets:"
23
+ @echo " * clean - remove all local images (and tags) for $(PROJECT)"
24
+ @echo " * container - build a Docker container for $(PROJECT)"
25
+ @echo " * latest - builds and tags the latest container for $(PROJECT) as 'latest'"
26
+ @echo " * pull - pull down previous docker builds of $(REGISTRY)/$(PROJECT)"
27
+ @echo " * push - push $(REGISTRY)/$(PROJECT)"
28
+ @echo " * tag - tags the lastest image as 'latest'"
29
+
30
+ container: .latest_container Dockerfile
31
+
32
+ latest: build_and_tag
33
+
34
+ tag: delete_current_tag .latest_tagged
35
+
36
+ push: .latest_pushed
37
+
38
+ delete_current_tag:
39
+ rm -f .latest_tagged
40
+
41
+ clean:
42
+ rm -f .latest_container .latest_tagged .latest_pushed .container_output
43
+ export IMAGES="$(shell $(DOCKER) images | grep -E '<none>|$(REGISTRY)/$(PROJECTS)')" ; \
44
+ test -z "$$IMAGES" || echo "$$IMAGES" | awk '{ print $$3 }' | \
45
+ sort | uniq | xargs $(DOCKER) rmi
46
+
47
+ .latest_container: pull
48
+ rm -f $@
49
+ $(DOCKER) build -t $(REGISTRY)/$(PROJECT):$(REV) $(BUILD_FLAGS) . | tee .container_output
50
+ awk '/^Successfully built/ { print $$NF }' .container_output | tail -1 > $@
51
+
52
+ .latest_tagged:
53
+ ( test -z "$(LATEST)" && echo 'Nothing to tag!' ) || $(DOCKER) tag $(LATEST) $(REGISTRY)/$(PROJECT):latest && touch $@
54
+
55
+ build_and_tag: .latest_container tag
56
+
57
+ pull:
58
+ $(DOCKER) pull $(REGISTRY)/$(PROJECT) || true
59
+
60
+ .latest_pushed: .latest_tagged
61
+ $(DOCKER) push $(REGISTRY)/$(PROJECT)
62
+
63
+ .PHONY: container latest push clean build_and_tag tag delete_current_tag pull
@@ -0,0 +1,12 @@
1
+ <% self.filename = '.run/bridge' -%>
2
+ <% self.executable = true -%>
3
+ #!/usr/bin/env bash
4
+
5
+ # tar-gzips your run directory and places it in a mounted directory. This
6
+ # script is run within the container, meaning that the `run.tar.gz` file will
7
+ # be available from outside the container once the container has stopped. In
8
+ # order to ensure this, the `/bridge` directory in the container must be
9
+ # mounted on the host system using the `-v` option to `docker run`. An example
10
+ # can be found in the `dockerize-unpack` script mentioned in the README. That
11
+ # script is designed to be usable as-is.
12
+ tar -czf /bridge/run.tar.gz /docker/run
@@ -0,0 +1,13 @@
1
+ <% self.filename = '.run/Makefile.run' -%>
2
+ <% self.executable = false -%>
3
+ all: deploy
4
+
5
+ # The deploy task is the one that will be called automatically when this
6
+ # application is deployed (assuming you use the unpack script). Therefore,
7
+ # this should be your main task and should take care of calling any other tasks
8
+ # you need. This Makefile is designed to be used to place files on the host
9
+ # machine that will be used by your container or to run your container. Good
10
+ # examples include configuraiton files and Upstart conf files.
11
+ deploy:
12
+
13
+ .PHONY: all deploy
@@ -0,0 +1,19 @@
1
+ <% self.filename = '.vagrant-provision.sh' -%>
2
+ <% self.executable = true -%>
3
+ #!/usr/bin/env bash
4
+
5
+ # Installs some development essentials and docker. The `usermod` line
6
+ # will give the vagrant user access to the docker daemon, but be aware that
7
+ # if you start doing development as root and then switch to the vagrant user,
8
+ # you will have to change the permissions on the docker unix socket file.
9
+
10
+ export DEBIAN_FRONTEND=noninteractive
11
+
12
+ set -e
13
+ set -x
14
+
15
+ apt-get update -yq
16
+ apt-get install -yq git-all curl make \
17
+ binutils build-essential htop make tree
18
+ curl -sL https://get.docker.io/ | sh
19
+ usermod -a -G docker vagrant
@@ -0,0 +1,29 @@
1
+ <% self.filename = 'Vagrantfile' -%>
2
+ <% self.executable = false -%>
3
+ require 'fileutils'
4
+
5
+ # The vagrant-provision script allows docker development to be done as the
6
+ # vagrant user. However, it is probably easier to use root. If you wish to
7
+ # use the vagrant user, change the `config.vm.synced_folder` command
8
+ # accordingly.
9
+
10
+ ENV['VAGRANT_SHARED_WORKSPACE'] ||= "#{ENV['HOME']}/workspace"
11
+
12
+ Vagrant.configure('2') do |config|
13
+ config.vm.hostname = 'modcloth-ansible-proving-ground'
14
+ config.vm.box = 'precise64'
15
+ config.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box'
16
+
17
+ config.vm.network :private_network, ip: '33.33.33.10', auto_correct: true
18
+ config.vm.network :forwarded_port, host: 2203, guest: 22
19
+
20
+ config.ssh.forward_agent = true
21
+ config.ssh.port = 2203
22
+
23
+ config.vm.synced_folder ENV['VAGRANT_SHARED_WORKSPACE'], '/root',
24
+ create: true,
25
+ owner: 'root',
26
+ group: 'root'
27
+
28
+ config.vm.provision :shell, path: '.vagrant-provision.sh'
29
+ end
data/vendor/colored.rb ADDED
@@ -0,0 +1,93 @@
1
+ require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
2
+
3
+ # Source: https://github.com/defunkt/colored
4
+
5
+ ##
6
+ # cute.
7
+ #
8
+ # >> "this is red".red
9
+ #
10
+ # >> "this is red with a blue background (read: ugly)".red_on_blue
11
+ #
12
+ # >> "this is red with an underline".red.underline
13
+ #
14
+ # >> "this is really bold and really blue".bold.blue
15
+ #
16
+ # >> Colored.red "This is red" # but this part is mostly untested
17
+ module Colored
18
+ extend self
19
+
20
+ COLORS = {
21
+ 'black' => 30,
22
+ 'red' => 31,
23
+ 'green' => 32,
24
+ 'yellow' => 33,
25
+ 'blue' => 34,
26
+ 'magenta' => 35,
27
+ 'cyan' => 36,
28
+ 'white' => 37
29
+ }
30
+
31
+ EXTRAS = {
32
+ 'clear' => 0,
33
+ 'bold' => 1,
34
+ 'underline' => 4,
35
+ 'reversed' => 7
36
+ }
37
+
38
+ COLORS.each do |color, value|
39
+ define_method(color) do
40
+ colorize(self, :foreground => color)
41
+ end
42
+
43
+ define_method("on_#{color}") do
44
+ colorize(self, :background => color)
45
+ end
46
+
47
+ COLORS.each do |highlight, value|
48
+ next if color == highlight
49
+ define_method("#{color}_on_#{highlight}") do
50
+ colorize(self, :foreground => color, :background => highlight)
51
+ end
52
+ end
53
+ end
54
+
55
+ EXTRAS.each do |extra, value|
56
+ next if extra == 'clear'
57
+ define_method(extra) do
58
+ colorize(self, :extra => extra)
59
+ end
60
+ end
61
+
62
+ define_method(:to_eol) do
63
+ tmp = sub(/^(\e\[[\[\e0-9;m]+m)/, "\\1\e[2K")
64
+ if tmp == self
65
+ return "\e[2K" << self
66
+ end
67
+ tmp
68
+ end
69
+
70
+ def colorize(string, options = {})
71
+ colored = [color(options[:foreground]), color("on_#{options[:background]}"), extra(options[:extra])].compact * ''
72
+ colored << string
73
+ colored << extra(:clear)
74
+ end
75
+
76
+ def colors
77
+ @@colors ||= COLORS.keys.sort
78
+ end
79
+
80
+ def extra(extra_name)
81
+ extra_name = extra_name.to_s
82
+ "\e[#{EXTRAS[extra_name]}m" if EXTRAS[extra_name]
83
+ end
84
+
85
+ def color(color_name)
86
+ background = color_name.to_s =~ /on_/
87
+ color_name = color_name.to_s.sub('on_', '')
88
+ return unless color_name && COLORS[color_name]
89
+ "\e[#{COLORS[color_name] + (background ? 10 : 0)}m"
90
+ end
91
+ end unless Object.const_defined? :Colored
92
+
93
+ String.send(:include, Colored)