ddev 0.1.0

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: fc4349cd9967ad94d84017fa932d3505617dcfbb
4
+ data.tar.gz: cc67a5be21c3457bbb3f9df79a8eeaea538cff20
5
+ SHA512:
6
+ metadata.gz: 2dbde191bcd2dd65fd07b7b69318595956cc89f593a8359c59b82cfa89b3d56ac8bf29ce4a1cc893fa7c3e65adf83bc70878cf901fe84bced8c3fb7cdc315213
7
+ data.tar.gz: ee25fc6c89ee441cce4069c23a93d7bac3a5c8103e4bb30e206bc03abc2289e11c20c930676e5ed907a34c28e966d7beec6c06d4de91c4f8cf9c08a007dbca76
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in docker-thor.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Justin Toniazzo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Docker::Thor
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/docker/thor`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'docker-thor'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install docker-thor
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/docker-thor.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "docker/thor"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require "pty"
5
+ require "rainbow"
6
+
7
+ require_relative "../lib/ddev/version"
8
+
9
+ module Ddev
10
+ class CLI < Thor
11
+ # When pushing updated container versions, update these constants. They are
12
+ # used when pushing, pulling, and building images.
13
+ VERSIONS = {
14
+ "dev" => {
15
+ "base" => 1,
16
+ "app" => 1,
17
+ "psql" => 1
18
+ }
19
+ }.freeze
20
+
21
+ #ALL_IMAGES = %w(base ruby psql nginx rails).freeze
22
+ ALL_IMAGES = {
23
+ "dev" => %w(base app psql)
24
+ }.freeze
25
+
26
+ PROJECT = "homepage".freeze
27
+
28
+ desc "build", "Build images. Pass image name to build a specific one; otherwise builds all"
29
+ option :env, default: "dev", type: :string
30
+ def build(*images)
31
+ env = options[:env]
32
+ images = ALL_IMAGES[env] if images.empty?
33
+ images = Array(images)
34
+
35
+ puts "Generating build script for #{images.join(", ")}"
36
+ commands = []
37
+
38
+ images.each do |image|
39
+ version = VERSIONS.dig env, image
40
+ tag = "jutonz/#{PROJECT}-#{env}-#{image}:#{version}"
41
+ dockerfile = "docker/#{env}/#{image}/Dockerfile"
42
+
43
+ commands << "#{sudo}docker #{docker_opts} build -f #{dockerfile} -t #{tag} ."
44
+ end
45
+
46
+ stream_output commands.join(" && "), exec: true
47
+ end
48
+
49
+ desc "push", "Upload locally built images to the remote store"
50
+ option :env, default: "dev", type: :string
51
+ def push(*images)
52
+ env = options[:env]
53
+ images = ALL_IMAGES[env] if images.empty?
54
+ images = Array(images)
55
+
56
+ push_cmds = []
57
+
58
+ images.each do |image|
59
+ version = VERSIONS.dig env, image
60
+ tag_cmd = "#{sudo}docker tag jutonz/#{PROJECT}-#{env}-#{image}:#{version} jutonz/#{PROJECT}-#{env}-#{image}:latest"
61
+ puts tag_cmd
62
+ `#{tag_cmd}`
63
+
64
+ push_cmds << "#{sudo}docker push jutonz/#{PROJECT}-#{env}-#{image}:#{version}"
65
+ end
66
+
67
+ push_cmd = push_cmds.join " && "
68
+ stream_output push_cmd, exec: true
69
+ end
70
+
71
+ desc "pull", "Pull the latest remote images to your local machine"
72
+ option :env, default: "dev", type: :string
73
+ def pull(*images)
74
+ env = options[:env]
75
+ images = ALL_IMAGES[env] if images.empty?
76
+ images = Array(images)
77
+
78
+ pull_cmds = []
79
+
80
+ images.each do |image|
81
+ version = VERSIONS.dig env, image
82
+ pull_cmds << "#{sudo}docker pull jutonz/#{PROJECT}-#{env}-#{image}:#{version}"
83
+ end
84
+
85
+ pull_cmd = pull_cmds.join " && "
86
+ stream_output pull_cmd, exec: true
87
+ end
88
+
89
+ desc "up", "Start your dockerized app server"
90
+ option :env, default: "dev", type: :string
91
+ def up
92
+ if `which docker-compose`.chomp.empty?
93
+ error = "Could not find docker-compose executible in path. Please " \
94
+ "install it to continue"
95
+ puts Rainbow(error).fg :red
96
+ exit 1
97
+ end
98
+
99
+ pidfile = "tmp/pids/server.pid"
100
+ FileUtils.rm pidfile if File.exist? pidfile
101
+
102
+ env = options[:env]
103
+ compose_file = File.expand_path "docker/#{env}/docker-compose.yml"
104
+
105
+ stream_output "#{sudo}docker-compose -f #{compose_file} up", exec: true
106
+ end
107
+
108
+ desc "down", "Stop your dockerized app server"
109
+ option :env, default: "dev", type: :string
110
+ def down
111
+ if `which docker-compose`.chomp.empty?
112
+ error = "Could not find docker-compose executible in path. Please " \
113
+ "install it to continue"
114
+ puts Rainbow(error).fg :red
115
+ exit 1
116
+ end
117
+
118
+ env = options[:env]
119
+ compose_file = File.expand_path "docker/#{env}/docker-compose.yml"
120
+
121
+ stream_output "#{sudo}docker-compose -f #{compose_file} down", exec: true
122
+ end
123
+
124
+ desc "initdb", "Setup initial postgres database"
125
+ def initdb
126
+ local_data_dir = File.expand_path "../tmp/psql", __FILE__
127
+ `#{sudo}rm -r #{local_data_dir}` if File.exists? local_data_dir # todo prompt
128
+
129
+ container = "psql"
130
+ version = VERSIONS.dig "dev", container
131
+ container = "jutonz/#{PROJECT}-dev-psql:#{version}"
132
+ stream_output "#{sudo}docker run --rm --volume #{local_data_dir}:/var/lib/postgresql/data --volume #{`pwd`.chomp}:/tmp/code #{container} /bin/bash -c /etc/initdb.sh", exec: true
133
+ end
134
+
135
+ desc "cleanup", "cleans up dangling docker images"
136
+ def cleanup
137
+ dangling = `#{sudo}docker images --filter dangling=true -q`.split("\n")
138
+
139
+ if dangling.none?
140
+ puts "No images to cleanup. Yay!"
141
+ exit 0
142
+ end
143
+
144
+ puts "Cleaning up dangling images: #{dangling.join(", ")}"
145
+ stream_output "#{sudo}docker rmi -f #{dangling.join(" ")}", exec: true
146
+ end
147
+
148
+ desc "bash CONTAINER", "Create a new instance of the given image with a bash prompt"
149
+ option :env, default: "dev", type: :string
150
+ def bash(image = "ruby")
151
+ env = options[:env]
152
+ version = VERSIONS.dig env, image
153
+ image = "jutonz/#{PROJECT}-#{env}-#{image}:#{version}"
154
+ stream_output "#{sudo}docker run -it --rm --volume #{`pwd`.chomp}:/root #{image} /bin/bash", exec: true
155
+ end
156
+
157
+ desc "connect CONTAINER", "Connect to a running container"
158
+ option :env, default: "dev", type: :string
159
+ def connect(image = "ruby")
160
+ env = options[:env]
161
+ version = VERSIONS.dig env, image
162
+ image = "jutonz/#{PROJECT}-#{env}-#{image}:#{version}"
163
+
164
+ cmd = "#{sudo}docker ps --filter ancestor=#{image} -aq"
165
+ puts cmd
166
+ container = `#{cmd}`.chomp
167
+
168
+ if container.empty?
169
+ puts Rainbow("No running containers for image #{image}").red
170
+ exit 1
171
+ end
172
+
173
+ stream_output "#{sudo}docker exec -it #{container} /bin/bash", exec: true
174
+ end
175
+
176
+ desc "version", "Prints out version information"
177
+ def version
178
+ puts Ddev::VERSION
179
+ end
180
+
181
+ no_commands do
182
+ def stream_output(string, print_command: true, exec: false)
183
+ puts string if print_command
184
+ if exec
185
+ exec string
186
+ else
187
+ PTY.spawn string do |stdout, stdin, pid|
188
+ stdout.each { |line| puts line }
189
+ end
190
+ end
191
+ end
192
+
193
+ def sudo
194
+ `uname`.chomp == "Darwin" ? "" : "sudo " # use sudo on linux hosts
195
+ end
196
+
197
+ def docker_opts
198
+ return "" unless ENV["JENKINS"]
199
+ opts = "--tls"
200
+
201
+ if host = ENV["DOCKER_HOST_IP"]
202
+ opts += " --host tcp://#{host}"
203
+ end
204
+
205
+ opts
206
+ end
207
+ end
208
+ end
209
+ end
210
+
211
+ Ddev::CLI.start ARGV
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ddev/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ddev"
8
+ spec.version = Ddev::VERSION
9
+ spec.authors = ["Justin Toniazzo"]
10
+ spec.email = ["jutonz42@gmail.com"]
11
+
12
+ spec.summary = %q(CLI and project structure for developing and deploying dockerized apps)
13
+ #spec.description = %q( TODO: Write a longer description or delete this line. )
14
+ spec.homepage = "https://github.com/jutonz/ddev"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "thor"
34
+ spec.add_dependency "rainbow"
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.15"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ module Ddev
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ddev
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Toniazzo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
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: rainbow
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
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - jutonz42@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/ddev
99
+ - bin/setup
100
+ - ddev.gemspec
101
+ - lib/ddev.rb
102
+ - lib/ddev/version.rb
103
+ homepage: https://github.com/jutonz/ddev
104
+ licenses:
105
+ - MIT
106
+ metadata:
107
+ allowed_push_host: https://rubygems.org
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.6.8
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: CLI and project structure for developing and deploying dockerized apps
128
+ test_files: []