dockly 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe48214f959251a622ec6458e33b73c9c75b4ac7
4
+ data.tar.gz: 3788dea01e592c04e702b8892e3b638dfcec2dc1
5
+ SHA512:
6
+ metadata.gz: fcfb39baac628840756bc4f944570bf8b7be9713d3a627841ade18601971b1395848943538b8c48f3a4dcd610423adb03eb84552c887e658aab6fcc3a559de9b
7
+ data.tar.gz: d9075e08f45a02cfbb101b9e1ef590f43b8e9f7ea0de29aa59f51aa1e9739692b7ad62426e32549f70dd66100a7fc4c547e3e4fafa5c227a848ea1a334bcb11f
data/.cane ADDED
@@ -0,0 +1,3 @@
1
+ --no-doc
2
+ --abc-max 30
3
+ --style-measure 120
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ # bundler
2
+ .bundle
3
+
4
+ # OSX
5
+ .DS_Store
6
+
7
+ # Vim
8
+ *.swp
9
+
10
+ Gemfile.lock
11
+ *.gem
12
+ build/
13
+ dist/
14
+
15
+ docker-export-ubuntu-latest.tar.gz
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --profile
3
+ --format documentation
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p125
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ script: CI=true bundle exec rake
7
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # TODO: @adamjt, let's open a pull for this so we can base off ddollar/foreman
4
+ gem 'foreman', :git => 'https://github.com/adamjt/foreman'
5
+
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Swipely, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,221 @@
1
+ Dockly
2
+ =======
3
+
4
+ `dockly` is a gem made to ease the pain of packaging an application. For this gem to be useful, quite a few assumptions can be made about your stack:
5
+
6
+ - You use AWS
7
+ - You're deploying to a Debian-based system
8
+ - You want to use [Docker](http://docker.io) for process isolation
9
+
10
+ Although only a specific type of repository may be used, these assumptions allow us to define a simple DSL to describe your repository.
11
+
12
+ The DSL
13
+ -------
14
+
15
+ The DSL is broken down into multiple objects, all of which conform to a specific format. Each object starts with the name of the section,
16
+ followed by a name for the object you're creating, and a block for configuration.
17
+
18
+ ```ruby
19
+ docker :test_docker do
20
+ # code here
21
+ end
22
+ ```
23
+
24
+ Each object has an enumeration of valid attributes. The following code sets the `repo` attribute in a `docker` called `test_docker`:
25
+
26
+ ```ruby
27
+ docker :test_docker do
28
+ repo 'an-awesome-repo'
29
+ end
30
+ ```
31
+
32
+ Finally, each object has zero or more valid references to other DSL objects. The following code sets `deb` that references a `docker`:
33
+
34
+ ```ruby
35
+ docker :my_docker do
36
+ repo 'my-repo'
37
+ end
38
+
39
+ deb :my_deb do
40
+ docker :my_docker
41
+ end
42
+ ```
43
+
44
+ Below is an alternative syntax that accomplishes the same thing:
45
+
46
+ ```ruby
47
+ deb :my_deb do
48
+ docker do
49
+ repo 'my-repo'
50
+ end
51
+ end
52
+ ```
53
+
54
+ `docker`
55
+ --------
56
+
57
+ The `docker` DSL is used to define Docker containers. It has the following attributes:
58
+
59
+ - `import`
60
+ - required: `true`
61
+ - default: `nil`
62
+ - description: the location (url or S3 path) of the base image to start building from
63
+ - `git_archive`:
64
+ - required: `false`
65
+ - default: `nil`
66
+ - description: the relative file path of git repo that should be added to the container
67
+ - `build`
68
+ - required: `true`
69
+ - default: `nil`
70
+ - description: aditional Dockerfile commands that you'd like to pass to `docker build`
71
+ - `repo`
72
+ - required: `true`
73
+ - default: `'dockly'`
74
+ - description: the repository of the created image
75
+ - `tag`
76
+ - required: `true`
77
+ - default: `nil`
78
+ - description: the tag of the created image
79
+ - `build_dir`
80
+ - required: `true`
81
+ - default: `./build/docker`
82
+ - description: the directory of the temporary build files
83
+ - `package_dir`
84
+ - required: `true`
85
+ - default: `/opt/docker`
86
+ - description: the location of the created image in the Debian package
87
+ - `timeout`
88
+ - required: `true`
89
+ - default: `60`
90
+ - description: the excon timeout for read and write when talking to docker through docker-api
91
+ - `build_caches`
92
+ - required: `false`
93
+ - default: `[]`
94
+ - description: a listing of references to build caches to run
95
+
96
+ `foreman`
97
+ ---------
98
+
99
+ The `foreman` DSL is used to define the foreman export scripts. It has the following attributes:
100
+
101
+ - `env`
102
+ - description: accepts same arguments as `foreman start --env`
103
+ - `procfile`
104
+ - required: `true`
105
+ - default: `'Procfile'`
106
+ - description: the Procfile to use
107
+ - `type`
108
+ - required: `true`
109
+ - default: `'upstart'`
110
+ - description: the type of foreman script being defined
111
+ - `user`
112
+ - required: `true`
113
+ - default: `'nobody'`
114
+ - description: the user the scripts will run as
115
+ - `root_dir`
116
+ - required: `false`
117
+ - default: `'/tmp'`
118
+ - description: set the root directory
119
+ - `init_dir`
120
+ - required: `false`
121
+ - default: `'/etc/init'`
122
+ - description: the location of the startup scripts in the Debian package
123
+ - `prefix`
124
+ - required: `false`
125
+ - default: `nil`
126
+ - description: a prefix given to each command from foreman.
127
+ must be using https://github.com/adamjt/foreman for this to work
128
+
129
+ `deb`
130
+ -----
131
+
132
+ The `deb` DSL is used to define Debian packages. It has the following attributes:
133
+
134
+ - `package_name`
135
+ - required: `true`
136
+ - default: `nil`
137
+ - description: the name of the created package
138
+ - `version`
139
+ - required: `true`
140
+ - default: `0.0`
141
+ - description: the version of the created package
142
+ - `release`
143
+ - required: `true`
144
+ - default: `0`
145
+ - description: the realese version of the created package
146
+ - `arch`
147
+ - required: `true`
148
+ - default: `x86_64`
149
+ - description: the intended architecture of the created package
150
+ - `build_dir`
151
+ - required: `true`
152
+ - default: `build/deb`
153
+ - description: the location of the temporary files on the local file system
154
+ - `pre_install`, `post_install`, `pre_uninstall`, `post_uninstall`
155
+ - required: `false`
156
+ - default: `nil`
157
+ - description: script hooks for package events
158
+ - `s3_bucket`
159
+ - required: `false`
160
+ - default: `nil`
161
+ - description: the s3 bucket the package is uploaded to
162
+
163
+ In addition to the above attributes, `deb` has the following references:
164
+
165
+ - `docker`
166
+ - required: `false`
167
+ - default: `nil`
168
+ - class: `Dockly::Docker`
169
+ - description: configuration for an image packaged with the deb
170
+ - `foreman`
171
+ - required: `false`
172
+ - default: `nil`
173
+ - class: `Dockly::Foreman`
174
+ - description: any Foreman scripts used in the deb
175
+
176
+
177
+ Demo
178
+ ===
179
+
180
+ ```ruby
181
+ deb :dockly_package do
182
+ package_name 'dockly_package'
183
+ version '1.0'
184
+ release '1'
185
+
186
+ docker do
187
+ name :dockly_docker
188
+ tag 'dockly_docker'
189
+ import 's3://dockly-bucket-name/base-image.tar.gz'
190
+ git_archive '/app'
191
+ timeout 120
192
+
193
+ build_cache do
194
+ s3_bucket "dockly-bucket-name"
195
+ s3_object_prefix "bundle_cache/"
196
+ hash_command "cd /app && ./script/bundle_hash"
197
+ build_command "cd /app && ./script/bundle_package"
198
+ output_dir "/app/vendor/bundle"
199
+ use_latest true
200
+ end
201
+
202
+ build <<-EOF
203
+ run cd /app && echo "1.0-1" > VERSION && echo "#{Dockly.git_sha}" >> VERSION
204
+ EOF
205
+ # git_sha is available from Dockly
206
+ end
207
+
208
+ foreman do
209
+ name 'dockly'
210
+ procfile 'Procfile'
211
+ prefix 'source /etc/dockly_env '
212
+ log_dir '/data/logs'
213
+ user 'ubuntu'
214
+ end
215
+
216
+ s3_bucket 'dockly-bucket-name'
217
+ # ends up in s3://#{s3_bucket}/#{package_name}/#{git_hash}/#{package_name}_#{version}.#{release}_#{arch}.deb
218
+ end
219
+ ```
220
+
221
+ Copyright (c) 2013 Swipely, Inc. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ # Copyright Swipely, Inc. All rights reserved.
2
+
3
+ $LOAD_PATH.unshift( File.join( File.dirname(__FILE__), 'lib' ) )
4
+
5
+ require 'rake'
6
+ require 'dockly'
7
+ require 'rspec/core/rake_task'
8
+ require 'cane/rake_task'
9
+
10
+ task :default => [:spec, :quality]
11
+
12
+ RSpec::Core::RakeTask.new do |t|
13
+ t.pattern = 'spec/**/*_spec.rb'
14
+ t.rspec_opts = '--tag ~docker' if ENV['CI']
15
+ end
16
+
17
+ Cane::RakeTask.new(:quality) do |cane|
18
+ cane.canefile = '.cane'
19
+ end
data/bin/dockly ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ $: << File.join(File.dirname(__FILE__), "..", "lib")
5
+ require 'dockly'
6
+ require 'dockly/cli'
7
+
8
+ Dockly::Cli.run
data/dockly.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/dockly/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Swipely, Inc."]
6
+ gem.email = %w{tomhulihan@swipely.com bright@swipely.com toddlunter@swipely.com}
7
+ gem.description = %q{Packaging made easy}
8
+ gem.summary = %q{Packaging made easy}
9
+ gem.homepage = "https://github.com/swipely/dockly"
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.license = 'MIT'
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "dockly"
15
+ gem.require_paths = %w{lib}
16
+ gem.version = Dockly::VERSION
17
+ gem.add_dependency 'clamp', '~> 0.6'
18
+ gem.add_dependency 'docker-api', '~> 1.5.2'
19
+ gem.add_dependency 'dockly-util'
20
+ gem.add_dependency 'excon'
21
+ gem.add_dependency 'fog', '~> 1.14.0'
22
+ gem.add_dependency 'foreman'
23
+ gem.add_dependency 'fpm', '~> 0.4.42'
24
+ gem.add_dependency 'grit'
25
+ gem.add_development_dependency 'cane'
26
+ gem.add_development_dependency 'pry'
27
+ gem.add_development_dependency 'rake'
28
+ gem.add_development_dependency 'rspec'
29
+ gem.add_development_dependency 'vcr'
30
+ gem.add_development_dependency 'webmock'
31
+ end
data/lib/dockly.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'dockly/util'
2
+ require 'fog'
3
+ require 'pry'
4
+ require 'foreman/cli_fix'
5
+ require 'foreman/export/base_fix'
6
+
7
+ module Dockly
8
+ end
9
+
10
+ require 'dockly/aws'
11
+ require 'dockly/foreman'
12
+ require 'dockly/build_cache'
13
+ require 'dockly/docker'
14
+ require 'dockly/deb'
15
+ require 'dockly/util/tar'
16
+ require 'dockly/util/git'
17
+
18
+ module Dockly
19
+ def setup(file = 'dockly.rb')
20
+ git_sha rescue 'unknown'
21
+ Dockly::Deb.instances
22
+ Dockly::Docker.instances
23
+ Dockly::Foreman.instances
24
+ instance_eval(IO.read(file), file)
25
+ end
26
+
27
+ {
28
+ :deb => Dockly::Deb,
29
+ :docker => Dockly::Docker,
30
+ :foreman => Dockly::Foreman
31
+ }.each do |method, klass|
32
+ define_method(method) do |sym, &block|
33
+ klass.new!(:name => sym, &block)
34
+ end
35
+ end
36
+
37
+ def git_sha
38
+ @git_sha ||= Dockly::Util::Git.git_sha
39
+ end
40
+
41
+ module_function :setup, :deb, :docker, :foreman, :git_sha
42
+ end
43
+
44
+ require 'dockly/rake_task'
data/lib/dockly/aws.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'fog/aws'
2
+
3
+ # This module holds the connections for all AWS services used by the gem.
4
+ module Dockly::AWS
5
+ extend self
6
+
7
+ def service(name, klass)
8
+ define_method name do
9
+ if val = instance_variable_get(:"@#{name}")
10
+ val
11
+ else
12
+ instance = klass.new(creds)
13
+ instance_variable_set(:"@#{name}", instance)
14
+ end
15
+ end
16
+ services << name
17
+ end
18
+
19
+ def services
20
+ @services ||= []
21
+ end
22
+
23
+ def env_attr(*names)
24
+ names.each do |name|
25
+ define_method name do
26
+ instance_variable_get(:"@#{name}") || ENV[name.to_s.upcase]
27
+ end
28
+
29
+ define_method :"#{name}=" do |val|
30
+ reset_cache!
31
+ instance_variable_set(:"@#{name}", val)
32
+ end
33
+
34
+ env_attrs << name
35
+ end
36
+ end
37
+
38
+ def env_attrs
39
+ @env_attrs ||= []
40
+ end
41
+
42
+ def creds
43
+ attrs = Hash[env_attrs.map { |attr| [attr, public_send(attr)] }].reject { |k, v| v.nil? }
44
+ if attrs.empty?
45
+ if ENV['FOG_CREDENTIAL']
46
+ attrs = {} # let Fog use the env var
47
+ else
48
+ attrs = { :use_iam_profile => true }
49
+ end
50
+ end
51
+ attrs
52
+ end
53
+
54
+ def reset_cache!
55
+ services.each { |service| instance_variable_set(:"@#{service}", nil) }
56
+ end
57
+
58
+ service :s3, Fog::Storage::AWS
59
+ env_attr :aws_access_key_id, :aws_secret_access_key
60
+ end