dj 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2869ef8740fa6e692c3e7bca1ea54aec575a9d4d
4
+ data.tar.gz: b7552b9afd33c53e4ae39525d80c85868b8d8b32
5
+ SHA512:
6
+ metadata.gz: 5732cbcf301b6671786e78227f5b9b7033f119bcbd7cf68108b00da71e749e84e4f70febba1835ea4fc569559b957cdb23abd583451a85a3eea0042cb32dbb57
7
+ data.tar.gz: 137cb3695bb452f158c68abb9d3818e76644d38643ff282bc3636c5a70e8f79095e798a4f737272f7a2e41fdc1ee87f5bba1b4376e0c5d898023bc52e88af8d4
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,189 @@
1
+ # Docker Jockey
2
+
3
+ ![Jockey](http://i.giphy.com/5iDijZZe6RzYQ.gif)
4
+
5
+ **All you need is Docker!**
6
+
7
+ This is a Docker image that will enable you to develop in all your favorite languages and all you need to install is Docker.
8
+ You don't need to install any language runtimes or environment, just run the commands below and it will **just work**.
9
+
10
+ This image was inspired by [this post about developing with Docker](https://medium.com/iron-io-blog/why-and-how-to-use-docker-for-development-a156c1de3b24).
11
+
12
+ The following commands are the main commands, and they are the same for all languages:
13
+
14
+ * vendor - vendors your dependencies into a /vendor directory.
15
+ * build - builds your program using the vendored dependencies
16
+ * run - runs your program
17
+ * image - this will build and create a Docker image out of your program
18
+
19
+ See below for more details on these commands.
20
+
21
+ ## Install
22
+
23
+ It's packaged as a gem, so just run:
24
+
25
+ ```sh
26
+ gem install dj2
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ The usage is the same for all languages, that's the beauty of this!
32
+
33
+ ### ALL languages
34
+
35
+ Replace the language of your choice in the commands below from this list:
36
+
37
+ * go
38
+ * ruby
39
+ * node
40
+ * php
41
+ * python
42
+
43
+ Here are the main commands you'll use:
44
+
45
+ ```sh
46
+ # vendor
47
+ dj LANG vendor
48
+ # test
49
+ dj LANG run [script.abc]
50
+ # build Docker image
51
+ dj LANG image username/myapp:latest
52
+ # test image
53
+ docker run --rm -p 8080:8080 username/myapp [script.abc]
54
+ # push image to docker hub
55
+ docker push username/myapp
56
+ # check language version
57
+ dj LANG version
58
+ ```
59
+
60
+ `script.abc` is for interpreted languages, for example: `dj ruby run hello.rb`
61
+
62
+ ### Port mapping
63
+
64
+ So you can map ports from the Docker containers to your app.
65
+
66
+ Similar to Docker, use `-p` after `dj`, example:
67
+
68
+ ```sh
69
+ dj -p "8080:8080" ruby run hello.rb
70
+ ```
71
+
72
+ ### Environment Variables
73
+
74
+ Similar to Docker, use `-e` after `dj`, example:
75
+
76
+ ```sh
77
+ dj -e "MYENVVAR=YO" ruby run hello.rb
78
+ ```
79
+
80
+ ### Language Specific Commands
81
+
82
+ #### Go specific commands
83
+
84
+ ```sh
85
+ # build, run already does this, but if you just want to build without running:
86
+ dj go build
87
+ # fmt:
88
+ dj go fmt
89
+ # Build static binary. This is great for making the [tiniest Docker image possible](http://www.iron.io/blog/2015/07/an-easier-way-to-create-tiny-golang-docker-images.html):
90
+ dj go static
91
+ # Cross compile your program into a variety of platforms (based on [this](https://medium.com/iron-io-blog/how-to-cross-compile-go-programs-using-docker-beaa102a316d#95d9):
92
+ dj go cross
93
+ # Build remote repo: this one will produce a binary from a GitHub repo. Equivalent to cloning, vendoring and building
94
+ dj go remote http://github.com/org/project
95
+ ```
96
+
97
+ #### Ruby:
98
+
99
+ NOTE: You must add `require_relative 'bundle/bundler/setup'` to the start of Ruby program/script.
100
+
101
+ ```sh
102
+ # run
103
+ dj ruby run hello.rb
104
+ # build image - hello.rb on the end is the script to run
105
+ dj ruby image username/rubyapp:latest hello.rb
106
+ ```
107
+
108
+ #### Node:
109
+
110
+ ```sh
111
+ # run npm commands like npm start
112
+ dj node npm start
113
+ ```
114
+
115
+ #### Python:
116
+
117
+ Nothing special.
118
+
119
+ #### PHP:
120
+
121
+ Nothing special.
122
+
123
+ ## Examples with various languages
124
+
125
+ You can use the code in this repo for examples: https://github.com/iron-io/dockerworker
126
+
127
+ ## Git
128
+
129
+ Just like git!
130
+
131
+ ```sh
132
+ dj git COMMAND
133
+ ```
134
+
135
+ Authentication? see: http://stackoverflow.com/questions/11403407/git-asks-for-username-everytime-i-push
136
+
137
+ Can keep your username and password:
138
+
139
+ ```sh
140
+ dj git config --global credential.helper store
141
+ ```
142
+
143
+
144
+ ## To Do
145
+
146
+ See: https://github.com/treeder/devo/issues
147
+
148
+ ## Troubleshooting
149
+
150
+ First, enable debugging by adding `-e "LOG_LEVEL=DEBUG"` to your dj docker run command.
151
+
152
+ ## Building Gem
153
+
154
+ ```sh
155
+ bundle install
156
+ ```
157
+
158
+
159
+ ## Building as a Docker image
160
+
161
+ Vendor gems:
162
+
163
+ ```sh
164
+ docker run --rm -v "$PWD":/worker -w /worker iron/ruby:dev bundle install --standalone --clean
165
+ ```
166
+
167
+ Testing:
168
+
169
+ ```sh
170
+ docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock -v "$PWD":/app -v "$HOME":/root -w /app -e "LOG_LEVEL=DEBUG" treeder/ruby-dind ruby bin/dj COMMAND
171
+ ```
172
+
173
+ Build image:
174
+
175
+ ```sh
176
+ docker build -t treeder/dj:latest .
177
+ ```
178
+
179
+ Tag it with the version:
180
+
181
+ ```sh
182
+ docker tag treeder/dj:latest treeder/dj:$(cat version.txt)
183
+ ```
184
+
185
+ Push:
186
+
187
+ ```sh
188
+ docker push treeder/dj
189
+ ```
data/bin/dj ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dj'
4
+
5
+ options = OpenStruct.new
6
+ options.env_vars = []
7
+ options.ports = []
8
+ x = OptionParser.new do |opt|
9
+ opt.banner = "Usage: dj [options] LANG COMMAND [args]"
10
+ opt.on('-e', '--env ENVVAR', 'An environment variable to pass into container.') { |o|
11
+ options.env_vars << o
12
+ }
13
+ opt.on('-p', '--port PORT', 'Port mapping. Same usage as docker run -p.') { |o|
14
+ options.ports << o
15
+ }
16
+
17
+ # No argument, shows at tail. This will print an options summary.
18
+ # Try it and see!
19
+ opt.on_tail("-h", "--help", "Show this message") do
20
+ puts opt
21
+ exit
22
+ end
23
+
24
+ # Another typical switch to print the version.
25
+ opt.on_tail("--version", "Show version") do
26
+ puts DockerJockey::VERSION
27
+ exit
28
+ end
29
+ end
30
+ x.order!
31
+
32
+ DockerJockey.run(ARGV, options)
@@ -0,0 +1,27 @@
1
+ # This has helpers for running this inside a container - docker in docker
2
+ module DockerJockey
3
+
4
+ # Gets volumes for parent container to be used in sub containers
5
+ def self.find_volumes
6
+ @volumes = "-v \"#{Dir.pwd}\":/app"
7
+ begin
8
+ puts "inspect: #{`docker inspect`}"
9
+ di = JSON.parse("#{`docker inspect $HOSTNAME`}")
10
+ # p di
11
+ @volumes = "--volumes-from #{di[0]['Name']}"
12
+ DockerJockey.docker_host = di[0]
13
+ rescue => ex
14
+ p ex
15
+ puts "couldn't inspect"
16
+ end
17
+
18
+ if ARGV.length < 1
19
+ DockerJockey.logger.fatal "No command provided."
20
+ exit
21
+ end
22
+
23
+ # DockerJockey.logger.debug "Options: #{options.inspect}"
24
+
25
+ DockerJockey.volumes = @volumes
26
+ end
27
+ end
@@ -0,0 +1,82 @@
1
+ # require_relative '../bundle/bundler/setup'
2
+ require 'open3'
3
+ require 'json'
4
+ require 'optparse'
5
+ require 'ostruct'
6
+ require 'docker'
7
+ require 'logger'
8
+
9
+ require_relative 'version'
10
+ require_relative 'executor'
11
+ require_relative 'image_helper'
12
+
13
+ require_relative 'langs/ruby_helper'
14
+ require_relative 'langs/node_helper'
15
+ require_relative 'langs/python_helper'
16
+ require_relative 'langs/php_helper'
17
+ require_relative 'langs/go_helper'
18
+
19
+ require_relative 'utils/git_helper'
20
+
21
+ module DockerJockey
22
+ @@docker_host = nil
23
+ @@volumes = nil
24
+ @@logger = nil
25
+
26
+ def self.docker_host=(x)
27
+ @@docker_host = x
28
+ end
29
+
30
+ def self.docker_host
31
+ @@docker_host
32
+ end
33
+
34
+ def self.volumes=(x)
35
+ @@volumes = x
36
+ end
37
+
38
+ def self.volumes
39
+ @@volumes
40
+ end
41
+ def self.logger
42
+ @@logger
43
+ end
44
+ def self.logger=(x)
45
+ @@logger = x
46
+ end
47
+
48
+ def self.run(args, options)
49
+ begin
50
+ lang = args.shift
51
+ case lang
52
+ when 'git'
53
+ helper = DockerJockey::GitHelper.new
54
+ helper.run(args, options)
55
+ when 'go'
56
+ helper = DockerJockey::GoHelper.new
57
+ helper.run(args, options)
58
+ when 'ruby'
59
+ helper = DockerJockey::RubyHelper.new
60
+ helper.run(args, options)
61
+ when 'node'
62
+ helper = DockerJockey::NodeHelper.new
63
+ helper.run(args, options)
64
+ when 'python'
65
+ helper = DockerJockey::PythonHelper.new
66
+ helper.run(args, options)
67
+ when 'php'
68
+ helper = DockerJockey::PhpHelper.new
69
+ helper.run(args, options)
70
+ else
71
+ puts "ERROR: Language not supported: #{lang}"
72
+ end
73
+ # rescue SystemExit, Interrupt => ex
74
+ # puts "Caught #{ex}"
75
+ end
76
+ end
77
+
78
+ end
79
+ DockerJockey.logger = Logger.new(STDOUT)
80
+ DockerJockey.logger.level = ENV['LOG_LEVEL'] ? Logger.const_get(ENV['LOG_LEVEL'].upcase) : Logger::INFO
81
+
82
+ DockerJockey.logger.debug ARGV
@@ -0,0 +1,14 @@
1
+ require_relative 'executor'
2
+ require_relative 'image_helper'
3
+
4
+ require_relative 'langs/ruby_helper'
5
+ require_relative 'langs/node_helper'
6
+ require_relative 'langs/python_helper'
7
+ require_relative 'langs/php_helper'
8
+ require_relative 'langs/go_helper'
9
+
10
+ require_relative 'utils/git_helper'
11
+
12
+ module DockerJockey
13
+
14
+ end
@@ -0,0 +1,165 @@
1
+
2
+ module DockerJockey
3
+
4
+ def self.docker_exec(image, args, options)
5
+ docker_run(image, args, options)
6
+ end
7
+
8
+ def self.docker_exec_script(image, script, options)
9
+ # TODO: change this to use docker api, like docker exec
10
+ # write script and mount inside container
11
+ File.write('__uberscript__', script)
12
+ args = "chmod a+x __uberscript__ && ./__uberscript__"
13
+ docker_run(image, args, options)
14
+ File.delete('__uberscript__')
15
+ end
16
+
17
+ def self.docker_run(image, args, options=OpenStruct.new)
18
+ # mounts = DockerJockey.docker_host[]
19
+ if !image.include? ':'
20
+ image = image + ":latest" # was getting "No such image" error without this
21
+ end
22
+ DockerJockey.logger.debug("docker_exec args: #{args.inspect}")
23
+ cmd = args.is_a?(String) ? ['sh', '-c', "#{args}"] : args
24
+ coptions = {
25
+ 'Image' => image,
26
+ 'Cmd' => cmd,
27
+ # "AttachStdin": true,
28
+ # "Tty": true,
29
+ # "OpenStdin": true,
30
+ # "StdinOnce": true,
31
+ "AttachStdout": true,
32
+ "AttachStderr": true,
33
+ # 'Mounts' => mounts,
34
+ # "Env": [
35
+ # "FOO=bar",
36
+ # "BAZ=quux"
37
+ # ],
38
+ 'WorkingDir' => '/app',
39
+ 'HostConfig' => {},
40
+ }
41
+ if DockerJockey.docker_host
42
+ # Dind version
43
+ coptions["HostConfig"]['VolumesFrom'] = [DockerJockey.docker_host['Name']]
44
+ coptions["HostConfig"]['Binds'] = DockerJockey.docker_host['HostConfig']['Binds']
45
+ # 'PortBindings': DockerJockey.docker_host['HostConfig']['PortBindings'],
46
+ else
47
+ coptions['Volumes'] = { '/app' => {} }
48
+ coptions["HostConfig"]['Binds'] = ["#{Dir.pwd}:/app"]
49
+ end
50
+
51
+ if options.env_vars && options.env_vars.length > 0
52
+ coptions['Env'] = options.env_vars
53
+ end
54
+ if options.ports && options.ports.length > 0
55
+ # info: http://stackoverflow.com/a/20429133/105562
56
+ coptions['ExposedPorts'] = {}
57
+ coptions['HostConfig']['PortBindings'] = {}
58
+ options.ports.each do |p|
59
+ psplit = p.split(':')
60
+ coptions['ExposedPorts']["#{psplit[1]}/tcp"] = {}
61
+ coptions['HostConfig']['PortBindings']["#{psplit[1]}/tcp"] = [{ "HostPort": "#{psplit[0]}" }]
62
+ end
63
+ end
64
+ # puts "container options:"
65
+ # p coptions
66
+ if !Docker::Image.exist?(image)
67
+ puts "Image #{image} doesn't exist, pulling..."
68
+ # Pull image to make sure we have it.
69
+ di = Docker::Image.create('fromImage' => image)
70
+ # Temporary hack until docker gem updated: https://github.com/swipely/docker-api/issues/369
71
+ # begin
72
+ # Docker::Image.create('fromImage' => image_name) do |info|
73
+ # yield info if block_given?
74
+ # end
75
+ # rescue Docker::Error::NotFoundError => e
76
+ # # see: https://github.com/swipely/docker-api/issues/369
77
+ # # as long as this is not fixed we need to re-check on our own
78
+ # # on docker-engines >= 1.10
79
+ # if Gem::Version.new(Docker.version['Version']) >= Gem::Version.new('1.10.0')
80
+ # Docker::Image.get(image_name)
81
+ # else
82
+ # raise e
83
+ # end
84
+ # end
85
+ end
86
+ # END HACK
87
+
88
+ # Now fire it up
89
+ container = Docker::Container.create(coptions)
90
+ # Capture ctrl-c
91
+ Signal.trap("INT") {
92
+ # Ctrl-C was pressed...
93
+ puts "Caught interrupt - killing docker child..."
94
+
95
+ # Kill child process...
96
+ # p `docker kill #{cname}`
97
+ # Process.kill("INT", pid)
98
+ container.delete(:force=>true)
99
+ exit 0
100
+
101
+ # This prevents the process from becoming defunct
102
+ # oe.close
103
+ }
104
+ container.tap(&:start).streaming_logs(follow:true, stdout: true, stderr: true) { |stream, chunk|
105
+ # puts "#{stream}: #{chunk}" # for debugging
106
+ puts chunk
107
+ }
108
+ # puts "Deleting container"
109
+ container.delete(:force => true)
110
+ end
111
+
112
+ def self.popen(maincmd, cname)
113
+ Open3.popen2e('docker', *(maincmd)) {|i,oe,t|
114
+ pid = t.pid # pid of the started process.
115
+ # puts "pid: #{pid}"
116
+ i.close # ensure this exits when it's done with output
117
+
118
+ # Catch interrupts to shut down the docker process too
119
+ Signal.trap("INT") {
120
+ # Ctrl-C was pressed...
121
+ puts "Caught interrupt - killing docker child..."
122
+
123
+ # Kill child process...
124
+ p `docker kill #{cname}`
125
+ # Process.kill("INT", pid)
126
+
127
+ # This prevents the process from becoming defunct
128
+ # oe.close
129
+ }
130
+
131
+ begin
132
+ oe.each {|line|
133
+ if /warning/ =~ line
134
+ puts 'warning'
135
+ end
136
+ puts line
137
+ }
138
+ rescue IOError => ex
139
+ # ignore? closed stream probably
140
+ end
141
+ oe.close
142
+ exit_status = t.value # Process::Status object returned.
143
+ # puts "exit_status: #{exit_status}"
144
+ }
145
+ end
146
+
147
+ def self.exec(cmd, args = [])
148
+ split = cmd.split(' ')
149
+ DockerJockey.logger.debug "Exec: #{(split + args).join(' ')}"
150
+ base = split.shift
151
+ Open3.popen2e(base, *(split + args)) {|i,oe,t|
152
+ pid = t.pid # pid of the started process.
153
+ i.close # ensure this exits when it's done with output
154
+ oe.each {|line|
155
+ if /warning/ =~ line
156
+ puts 'warning'
157
+ end
158
+ puts line
159
+ }
160
+ exit_status = t.value # Process::Status object returned.
161
+ # puts "exit_status: #{exit_status}"
162
+ }
163
+ end
164
+
165
+ end
@@ -0,0 +1,35 @@
1
+ require 'fileutils'
2
+
3
+ module DockerJockey
4
+ class ImageHelper
5
+ def self.build1(from, entry, args)
6
+ if args.length < 1
7
+ raise "devo: image command requires image name and filename of script to run."
8
+ end
9
+ image_name = args[0]
10
+ filename = args[1]
11
+ # tmpdir = 'tmp/app'
12
+ # FileUtils.mkdir_p tmpdir
13
+ # DockerJockey.exec("cp -r . #{tmpdir}")
14
+ entrypoint = [entry]
15
+ entrypoint << filename if filename
16
+ # exec("cp /scripts/lib/Dockerfile /tmp/app")
17
+ dockerfile = "__Dockerfile__"
18
+ File.open(dockerfile, 'w') { |file|
19
+ file.write("FROM #{from}
20
+ WORKDIR /app
21
+ COPY . /app/
22
+ ENTRYPOINT [ #{entrypoint.map{ |e| '"' + e + '"'}.join(', ') } ]
23
+ ")
24
+ }
25
+ # DockerJockey.exec("cat /tmp/app/Dockerfile")
26
+ # DockerJockey.exec("ls -al /tmp/app")
27
+ # FileUtils.cd(tmpdir) do
28
+ DockerJockey.exec("docker version")
29
+ DockerJockey.exec("docker build -t #{image_name} -f #{dockerfile} .")
30
+ # end
31
+ File.delete(dockerfile)
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,89 @@
1
+
2
+ module DockerJockey
3
+ class GoHelper
4
+
5
+ attr_accessor :options
6
+
7
+ def run(args=[], options)
8
+ @options = options
9
+ if args.length < 1
10
+ raise "devo go: invalid args: #{args.inspect}"
11
+ end
12
+ case args[0]
13
+ when 'get', 'vendor'
14
+ script = script_base() + '
15
+ pwd
16
+ cat api.go
17
+ go get
18
+ cp -r $p/vendor $wd
19
+ chmod -R a+rw $wd/vendor
20
+ ' + script_cleanup()
21
+ # ["-w","/go/src/x/y/z","-e","GOPATH=/go/src/x/y/z/vendor:/go"]
22
+ DockerJockey.docker_exec_script("iron/go:dev", script, options)
23
+ when 'build'
24
+ # todo: use extra params provided by user, eg: #{args.join(' '). But need to parse -o to find output file name to copy
25
+ build()
26
+ when 'fmt'
27
+ DockerJockey.docker_exec("iron/go:dev", "go fmt", options)
28
+ when 'static'
29
+ static()
30
+ when 'run'
31
+ build()
32
+ DockerJockey.docker_exec("iron/go", "./app", options)
33
+ when 'image'
34
+ DockerJockey::ImageHelper.build1('iron/go', './app', args[1..args.length])
35
+ when 'version'
36
+ DockerJockey.docker_exec("iron/go:dev", "go version", options)
37
+ else
38
+ raise "Invalid Go command: #{args[0]}"
39
+ end
40
+ end
41
+ def script_base
42
+ script_base = '
43
+ set -e
44
+ #echo $PWD
45
+ wd=$PWD
46
+ defSrcPath="x/y/z"
47
+ if [ -z "$SRCPATH" ]; then
48
+ SRCPATH=$defSrcPath
49
+ fi
50
+ #echo "srcpath $SRCPATH ---"
51
+ p=/go/src/$SRCPATH
52
+ mkdir -p $p
53
+ ls -al
54
+ if [ "$(ls -A $wd)" ]
55
+ then
56
+ # only if files exist, errors otherwise
57
+ cp -r * $p
58
+ fi
59
+ cd $p
60
+ export GOPATH=$p/vendor:/go
61
+ '
62
+ script_base
63
+ end
64
+ def script_cleanup
65
+ script_cleanup = '
66
+ rm -rf /go
67
+ '
68
+ script_cleanup
69
+ end
70
+
71
+ def build()
72
+ script = script_base() + "
73
+ go build -o app
74
+ cp app $wd
75
+ chmod a+rwx $wd/app
76
+ " + script_cleanup()
77
+ DockerJockey.docker_exec_script("iron/go:dev", script, options)
78
+ end
79
+
80
+ def static()
81
+ script = script_base() + "
82
+ CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags=\"-s\" -o static
83
+ cp static $wd
84
+ chmod a+rwx $wd/static
85
+ " + script_cleanup()
86
+ DockerJockey.docker_exec_script("iron/go:dev", script, options)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,27 @@
1
+
2
+ module DockerJockey
3
+ class NodeHelper
4
+
5
+ def run(args, options)
6
+ if args.length < 1
7
+ raise "devo node: invalid args."
8
+ end
9
+ case args[0]
10
+ when 'run'
11
+ DockerJockey.docker_exec("iron/node", "node #{args[1]}", options)
12
+ when 'install', 'vendor'
13
+ # npm install
14
+ DockerJockey.docker_exec("iron/node:dev", "npm install", options)
15
+ DockerJockey.exec("chmod -R a+rw node_modules")
16
+ when 'npm'
17
+ DockerJockey.docker_exec("iron/node:dev", "npm #{args[1]}", options)
18
+ when 'image'
19
+ DockerJockey::ImageHelper.build1('iron/node', 'node', args[1..args.length])
20
+ when 'version'
21
+ DockerJockey.docker_exec("iron/node", "node -v", options)
22
+ else
23
+ raise "Invalid node command: #{args[0]}"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+
2
+ module DockerJockey
3
+ class PhpHelper
4
+
5
+ def run(args, options)
6
+ if args.length < 1
7
+ raise "devo php: invalid args."
8
+ end
9
+ case args[0]
10
+ when 'install', 'vendor'
11
+ # npm install
12
+ DockerJockey.docker_exec("iron/php:dev", "composer install", options)
13
+ DockerJockey.exec("chmod -R a+rw vendor")
14
+ when 'run'
15
+ DockerJockey.docker_exec("iron/php", "php #{args[1]}", options)
16
+ when 'image'
17
+ DockerJockey::ImageHelper.build1('iron/php', 'php', args[1..args.length])
18
+ when 'version'
19
+ DockerJockey.docker_exec("iron/php", "php -v", options)
20
+ else
21
+ raise "Invalid php command: #{args[0]}"
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+
2
+ module DockerJockey
3
+ class PythonHelper
4
+
5
+ def run(args, options)
6
+ if args.length < 1
7
+ raise "devo python: invalid args."
8
+ end
9
+ case args[0]
10
+ when 'install', 'vendor'
11
+ # npm install
12
+ DockerJockey.docker_exec("iron/python:2-dev", "pip install -t packages -r requirements.txt", options)
13
+ DockerJockey.exec("chmod -R a+rw packages")
14
+ when 'run'
15
+ DockerJockey.docker_exec("iron/python:2", "python #{args[1]}", options)
16
+ when 'image'
17
+ DockerJockey::ImageHelper.build1('iron/python:2', 'python', args[1..args.length])
18
+ when 'version'
19
+ DockerJockey.docker_exec("iron/python:2", "python --version".split(' '), options)
20
+ else
21
+ raise "Invalid python command: #{args[0]}"
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+
2
+ module DockerJockey
3
+ class RubyHelper
4
+
5
+ attr_accessor :options
6
+
7
+ def run(args=[], options)
8
+ @options = options
9
+ if args.length < 1
10
+ raise "devo ruby: invalid args."
11
+ end
12
+ case args[0]
13
+ when 'bundle', 'vendor'
14
+ cmd = "install --standalone --clean"
15
+ if args[1] == "update"
16
+ cmd = "update"
17
+ end
18
+ DockerJockey.docker_exec("iron/ruby:dev", "bundle config --local build.nokogiri --use-system-libraries && bundle #{cmd}", options)
19
+ DockerJockey.exec("chmod -R a+rw bundle")
20
+ DockerJockey.exec("chmod -R a+rw .bundle")
21
+ when 'run'
22
+ DockerJockey.docker_exec("iron/ruby", "ruby #{args[1]}", options)
23
+ when 'image'
24
+ DockerJockey::ImageHelper.build1('iron/ruby', 'ruby', args[1..args.length])
25
+ when 'version'
26
+ DockerJockey.docker_exec("iron/ruby", "ruby -v", options)
27
+ else
28
+ raise "Invalid ruby command: #{args[0]}"
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module DockerJockey
3
+ class GitHelper
4
+
5
+ def run(args, options)
6
+ DockerJockey.logger.debug args
7
+ DockerJockey.logger.debug options
8
+ # Just passing this along to git
9
+ DockerJockey.docker_exec("treeder/git", args, options)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module DockerJockey
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dj
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Travis Reeder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docker-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: droplet_kit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: One dev tool to rule them all.
42
+ email: treeder@gmail.com
43
+ executables:
44
+ - dj
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE.md
49
+ - README.md
50
+ - bin/dj
51
+ - lib/dind.rb
52
+ - lib/dj.rb
53
+ - lib/docker_jockey.rb
54
+ - lib/executor.rb
55
+ - lib/image_helper.rb
56
+ - lib/langs/go_helper.rb
57
+ - lib/langs/node_helper.rb
58
+ - lib/langs/php_helper.rb
59
+ - lib/langs/python_helper.rb
60
+ - lib/langs/ruby_helper.rb
61
+ - lib/utils/git_helper.rb
62
+ - lib/version.rb
63
+ homepage: https://github.com/treeder/dj
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.6.6
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Docker Jockey
87
+ test_files: []