open-dock 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5eee642a498a4d4faa1e00a618afa1b993dfb75a
4
- data.tar.gz: c7a61dc4ad766ebf27b14500296bd9461ccbd300
3
+ metadata.gz: 3f1505c1a79c47a3eaf3547ba9cb41d0b2a5947b
4
+ data.tar.gz: ab491f5bf6610a624e9f8473806cbfb1b0fc0fe1
5
5
  SHA512:
6
- metadata.gz: f6ca4d9d727cb99c000deb9062b9d433480bebfca123a1f9d8d746e8a8f2eb10de79834f89e8d9df995e6fd1ff925fe6ea0aab857905221a5b03ab0f49e0c185
7
- data.tar.gz: 9586f5989f25bf6fe874b98d929afb2a3e3284257ac34d3a2015ca4b63fffe480bee4443a757c2b32dc5685d3e89521c739752403d65d6ede7c0e4547739257b
6
+ metadata.gz: 86e3b55323382232ac6f29a1c20bb3d2725ab7dce58f39958c7a37c3718a7993ca5612b16b1dbca04e7b3d4cf5bb5c91818e7fd1f517ff337a149ea5ef489837
7
+ data.tar.gz: c74ede46fee31e533eb8d55da0cc472420d7e12bcd9a14bbfb0d23cd04ac8f7e9d2ec01111025ddf107604e7a7a9dc1bc6620a3ba62e67d1446a2cdcf1235500
data/README.md CHANGED
@@ -43,9 +43,9 @@ containers
43
43
 
44
44
  ## Configure PROVIDER
45
45
 
46
- `ops list` command will list all providers suported by this gem.
46
+ `ops list` command will list all providers supported by this gem.
47
47
 
48
- TODO: Create more providers (aws, linode, gcloud, ...)
48
+ TODO: Create more providers (vagrant, aws, linode, gcloud, ...)
49
49
 
50
50
  ### Digital Ocean
51
51
 
@@ -152,18 +152,29 @@ www:
152
152
 
153
153
  ### Shipping your local Docker
154
154
 
155
- You can create a file `containers/localhost.yml` where you can define containers. And launch them on your workstation:
155
+ You can create a file `containers/localhost.example.com.yml` where you can define containers. And launch them on your workstation:
156
156
 
157
157
  ```
158
- ops ship localhost
158
+ ops ship localhost.example.com
159
159
  ```
160
160
 
161
- ## TODO: Configure Containers (are nodes, with Chef)
161
+ By convention:
162
+
163
+ * If [host_name] include "localhost" string, it is assumed that containers are shipped on local workstation
164
+
165
+ ## Configure Containers (are nodes for Chef)
162
166
 
163
167
  Configuration with chef commands
164
168
 
165
- * `ops configure CONTAINER_NAME HOST_NAME`: configure with chef a container in host. Here you need to install knife-solo gem.
166
- * knife solo cook [container_user]@[HOST_NAME] -p [container_ssh_port]
169
+ * `ops configure HOST_NAME`: configure with chef all containers in host. Here you need to install knife-solo gem.
170
+ * Equivalent to: knife solo cook root@[HOST_NAME] -p [each container_ssh_port]
171
+ * `--container CONTAINER_NAME` to configure one container (default: '--container all')
172
+
173
+ By convention:
174
+
175
+ * "root" is the user in all containers
176
+ * Each container configuration is defined in a Chef node: `nodes/[container_name].[host_name].json`
177
+ * Then you have to create all container name records in your DNS provider: `[container_name].[host_name] CNAME [host_name].`
167
178
 
168
179
  ## Commands
169
180
 
@@ -177,7 +188,7 @@ Create/delete domain names, create/delete hosts and ship/unship hosts:
177
188
  * `ops ship HOST_NAME` run the containers in the host.
178
189
  * `ops unship HOST_NAME`
179
190
  * TODO: `ops reship HOST_NAME` unship/ship all containers from host.
180
- * TODO: `ops configure CONTAINER_NAME HOST_NAME` configure container with chef.
191
+ * `ops configure HOST_NAME` configure all containers with chef.
181
192
 
182
193
  ## Create your infrastructure project (/ops)
183
194
 
@@ -198,7 +209,7 @@ source 'https://rubygems.org'
198
209
 
199
210
  gem 'open-dock'
200
211
 
201
- # OPTIONAL: Add next gems if you want to integrate with Chef as Configuration management tecnology
212
+ # OPTIONAL: Add next gems if you want to integrate with Chef as Configuration management technology
202
213
  gem 'knife-solo'
203
214
  gem 'librarian-chef'
204
215
  gem 'foodcritic'
@@ -242,4 +253,13 @@ Or integrate it within your Chef infrastructure project. Just add the gem to you
242
253
 
243
254
  ### v0.1.0
244
255
 
245
- * Launch local containers with `containers/localhost.yml` and `ops ship localhost`
256
+ * Launch local containers with `containers/localhost.yml` and `ops ship localhost`
257
+
258
+ ### v0.1.1
259
+
260
+ Create command `ops configure [host_name]` this will cook all containers. By convention:
261
+
262
+ * "root" is the user in all containers
263
+ * Each container configuration is defined in a Chef node: `nodes/[container_name].[host_name].json`
264
+ * Then you have to create all container name records in your DNS provider: `[container_name].[host_name] CNAME [host_name].`
265
+ * If [host_name] include "localhost" string, it is assumed that containers are shipped on local workstation
@@ -0,0 +1,8 @@
1
+ module Chef
2
+ def self.cook(user, container_name, host, ssh_port)
3
+ say "Container '#{container_name}' configuring on #{host}, please wait ....\n"
4
+ command = "knife solo cook #{user}@#{container_name}.#{host} -p #{ssh_port}"
5
+ say "Chef CMD: #{command}\n"
6
+ system command
7
+ end
8
+ end
@@ -0,0 +1,27 @@
1
+ command :configure do |c|
2
+ c.summary = 'Configure all Docker containers in a host using knife solo'
3
+ c.syntax = 'ops configure [host_name]'
4
+ c.description = "Configure all docker containers described in #{Ops::CONTAINERS_DIR}/[host_name].yml"
5
+ c.option '--container CONTAINER_NAME', String, 'Only configure this container'
6
+ c.example "Create a container called 'www' in the host example.com. This is described in '#{Ops::CONTAINERS_DIR}/example.com.yml' like:\n # www:\n # detach: true\n # image: jlebrijo/prun\n # ports:\n # - '2222:22'\n # - '80:80'\n # db:\n # detach: true\n # image: jlebrijo/prun-db\n # ports:\n # - '2223:22'\n # - '5432'\n # Equivalent to run:\n # knife solo cook root@www.example.com -p 2222\n # knife solo cook root@db.example.com -p 2223'\n # So you will need to create chef node files as 'nodes/[container_name].[host_name].json':\n # nodes/www.example.com.json\n # nodes/db.example.com.json", 'ops configure example.com'
7
+ c.action do |args, options|
8
+ options.default container: 'all'
9
+ host = args[0]
10
+ user = Docker::DEFAULT_USER
11
+ containers = Docker::containers_for(host)
12
+
13
+ if options.container == "all"
14
+ containers.each do |container_name, config|
15
+ ssh_port = get_port config
16
+ Chef::cook(user,container_name, host, ssh_port)
17
+ end
18
+ else
19
+ ssh_port = get_port containers[options.container]
20
+ Chef::cook(user, options.container, host, ssh_port)
21
+ end
22
+ end
23
+
24
+ def get_port(config)
25
+ config["ports"].select{|port| port.end_with? ":22"}[0].split(':')[0]
26
+ end
27
+ end
@@ -1,11 +1,11 @@
1
1
  command :ship do |c|
2
2
  c.summary = 'Create Docker containers defined in ops/containers/[host_name].yml'
3
- c.syntax = 'ops ship host [host_name]'
3
+ c.syntax = 'ops ship [host_name]'
4
4
  c.description = "Create all docker containers described in #{Ops::CONTAINERS_DIR}/[host_name].yml"
5
5
  c.example "Create a container called 'www' in the host example.com. This is described in '#{Ops::CONTAINERS_DIR}/example.com.yml' like:\n # www:\n # detach: true\n # image: jlebrijo/prun\n # ports:\n # - '2222:22'\n # - '80:80'", 'ops ship example.com'
6
6
  c.action do |args, options|
7
7
  host = args[0]
8
- user = Ops::get_user_for(host) unless host == "localhost"
8
+ user = Ops::get_user_for(host) unless host.include? "localhost"
9
9
 
10
10
  Docker::containers_for(host).each do |container_name, config|
11
11
  ports = config["ports"].map{|port| "-p #{port}"}.join(" ")
@@ -15,12 +15,11 @@ command :ship do |c|
15
15
  end
16
16
  say "Container '#{container_name}' loading on #{host}, please wait ....\n"
17
17
  command = "docker run #{options.join(" ")} --name #{container_name} #{ports} #{config["image"]} #{config["command"]}"
18
- if host == "localhost"
18
+ say "Docker CMD: #{command}\n"
19
+ if host.include? "localhost"
19
20
  system command
20
21
  else
21
22
  Net::SSH.start(host, user) do |ssh|
22
-
23
- say "Docker CMD: #{command}\n"
24
23
  ssh.exec command
25
24
  end
26
25
  end
@@ -3,6 +3,7 @@ require 'yaml'
3
3
 
4
4
  module Docker
5
5
  SPECIAL_OPTS = ["image", "ports", "command", "post-conditions"]
6
+ DEFAULT_USER = "root"
6
7
 
7
8
  def self.containers_for(host_name)
8
9
  config_file = "#{Ops::CONTAINERS_DIR}/#{host_name}.yml"
@@ -4,6 +4,7 @@ require 'net/ssh'
4
4
  require 'open-dock/base'
5
5
  require 'open-dock/providers'
6
6
  require 'open-dock/docker'
7
+ require 'open-dock/chef'
7
8
  require 'open-dock/version'
8
9
 
9
10
  program :name, 'ops'
@@ -1,3 +1,3 @@
1
1
  module OpenDock
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open-dock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Lebrijo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,6 +113,8 @@ files:
113
113
  - bin/ops
114
114
  - lib/open-dock.rb
115
115
  - lib/open-dock/base.rb
116
+ - lib/open-dock/chef.rb
117
+ - lib/open-dock/commands/configure_host.rb
116
118
  - lib/open-dock/commands/create_host.rb
117
119
  - lib/open-dock/commands/delete_host.rb
118
120
  - lib/open-dock/commands/exec_host.rb