prun-ops 0.0.9 → 0.0.10
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 +4 -4
- data/README.md +26 -139
- data/lib/{prun-ops/cap/all.rb → capistrano/all.rake} +0 -4
- data/lib/{prun-ops/cap/backup.rb → capistrano/backup.rake} +0 -0
- data/lib/{prun-ops/cap/diagnosis.rb → capistrano/diagnosis.rake} +0 -0
- data/lib/capistrano/prun-ops.rb +1 -0
- data/lib/{prun-ops/cap/pull.rb → capistrano/pull.rake} +0 -0
- data/lib/prun-ops/railitie.rb +1 -5
- data/lib/prun-ops/version.rb +1 -1
- data/prun-ops.gemspec +3 -6
- metadata +12 -39
- data/bin/ops +0 -3
- data/lib/prun-ops/base.rb +0 -17
- data/lib/prun-ops/commands/create_domain.rb +0 -16
- data/lib/prun-ops/commands/create_host.rb +0 -17
- data/lib/prun-ops/commands/delete_domain.rb +0 -14
- data/lib/prun-ops/commands/delete_host.rb +0 -16
- data/lib/prun-ops/commands/exec_host.rb +0 -16
- data/lib/prun-ops/commands/list.rb +0 -29
- data/lib/prun-ops/commands/provision_host.rb +0 -11
- data/lib/prun-ops/commands/ship_host.rb +0 -26
- data/lib/prun-ops/commands/unship_host.rb +0 -16
- data/lib/prun-ops/digitalocean.rb +0 -33
- data/lib/prun-ops/docker.rb +0 -16
- data/lib/prun-ops/ops.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e784e8b5f778c3efdc55bcdb41e23212880cd58
|
4
|
+
data.tar.gz: eb87a3427d45fdfd94819c8ca825777d0862c91f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f331bee303be767916767c1aa297e2990596fed75d7519e84c62d470c644d6cb1256894b98fa2311502cf53a5d7bcd74418d9237a8d69a0ab94e244e9bd481f8
|
7
|
+
data.tar.gz: 608878b6e9b0b2ea811e46d2f0bb76e29b23de3c8aec06aa245510b36c581cb9064c056b7c20785f20c40f33aed46c19a101cf3ffb00b781e5395ed382b5b653
|
data/README.md
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# PrunOps
|
2
2
|
|
3
|
-
Covers all Operations in a Ruby on Rails Application server:
|
3
|
+
Covers all Deployment and maintainance Operations in a Ruby on Rails Application server:
|
4
4
|
|
5
|
-
1. PROVISION: Create hosts and ship them with Docker containers.
|
6
|
-
1. CONFIGURATION: Build Chef cookbooks and configure/re-configure your servers. Based on [PRUN-CFG cookbook](https://supermarket.getchef.com/cookbooks/prun-cfg).
|
7
5
|
1. DEPLOYMENT: Capistrano tasks to depoly your rails Apps.
|
8
6
|
1. DIAGNOSIS: Capistrano diagnosis tools to guet your Apps status on real time.
|
9
7
|
1. RELEASE: Rake tasks to manage and tag version number in your Apps (X.Y.Z).
|
10
8
|
1. BACKUP: Backup policy for database and files in your Apps, using git as storage.
|
11
9
|
|
12
|
-
Based on
|
10
|
+
Based on:
|
11
|
+
|
12
|
+
* [PRUN Docker image](https://registry.hub.docker.com/u/jlebrijo/prun/).
|
13
|
+
* [PRUN Chef recipe](https://github.com/jlebrijo/prun-cfg).
|
13
14
|
|
14
15
|
## Installation
|
15
16
|
|
@@ -27,130 +28,9 @@ Or install it yourself as:
|
|
27
28
|
|
28
29
|
$ gem install prun-ops
|
29
30
|
|
30
|
-
## Usage: Provision with OPS command
|
31
|
-
|
32
|
-
OPS command is focused to cover first Provision configurations for a the Operations of your infrastructure.
|
33
|
-
|
34
|
-
You can create an infrastructure project (like me [/ops](https://github.com/jlebrijo/ops))
|
35
|
-
|
36
|
-
```
|
37
|
-
mkdir ops && cd ops
|
38
|
-
rbenv local 2.1.2
|
39
|
-
git init
|
40
|
-
```
|
41
|
-
|
42
|
-
Create a Gemfile:
|
43
|
-
|
44
|
-
```
|
45
|
-
source 'https://rubygems.org'
|
46
|
-
|
47
|
-
gem 'prun-ops'
|
48
|
-
|
49
|
-
# OPTIONAL: Add next gems if you want to integrate with Chef as Configuration management tecnology
|
50
|
-
gem 'knife-solo'
|
51
|
-
gem 'librarian-chef'
|
52
|
-
gem 'foodcritic'
|
53
|
-
```
|
54
|
-
|
55
|
-
And: `bundle install`
|
56
|
-
|
57
|
-
To avoid `bundle exec` repfix: `bundle install --binstubs .bundle/bin`
|
58
|
-
|
59
|
-
Or integrate it within your Chef infrastructure project. Just add the gem to your Gemfile.
|
60
|
-
|
61
|
-
### Folder Structure
|
62
|
-
|
63
|
-
TODO: `ops init` to create this structure
|
64
|
-
|
65
|
-
Structure:
|
66
|
-
|
67
|
-
```
|
68
|
-
ops
|
69
|
-
providers
|
70
|
-
digitalocean.yml
|
71
|
-
hosts
|
72
|
-
example.com.yml
|
73
|
-
containers
|
74
|
-
example.com.yml
|
75
|
-
```
|
76
|
-
|
77
|
-
#### Provider file syntax
|
78
|
-
|
79
|
-
TODO: Create more providers (aws, linode, gcloud, ...)
|
80
|
-
|
81
|
-
For a Digital Ocean provider create a file (ops/providers/digitalocean.yml) with your account API key:
|
82
|
-
|
83
|
-
```yml
|
84
|
-
token: a206ae60dda6bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcf0cbf41
|
85
|
-
```
|
86
|
-
|
87
|
-
#### Host file syntax
|
88
|
-
|
89
|
-
For a Digital Ocean host we can make the following file (ops/hosts/example.com.yml):
|
90
|
-
|
91
|
-
```yml
|
92
|
-
user: core # User to connect the host
|
93
|
-
# Values to configure DigitalOcean machine
|
94
|
-
size: 1gb
|
95
|
-
region: ams3
|
96
|
-
image: coreos-stable
|
97
|
-
ssh_keys:
|
98
|
-
- e7:51:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:88:57
|
99
|
-
```
|
100
|
-
|
101
|
-
And create the host: `ops create host example.com`
|
102
|
-
|
103
|
-
### Containers file syntax
|
104
|
-
|
105
|
-
In this file we can configure all containers to run in the host provided in the name:
|
106
|
-
|
107
|
-
```yml
|
108
|
-
www:
|
109
|
-
image: jlebrijo/prun
|
110
|
-
ports:
|
111
|
-
- '2222:22'
|
112
|
-
- '80:80'
|
113
|
-
# command: /bin/bash
|
114
|
-
|
115
|
-
# OPTIONS: use the long name of the options, 'detach' instead of '-d'
|
116
|
-
detach: true
|
117
|
-
# interactive: true
|
118
|
-
# memory: 8g
|
119
|
-
# cpuset: 0-7
|
120
|
-
|
121
|
-
# POST-CONDITIONS: execute after build the container:
|
122
|
-
post-conditions:
|
123
|
-
- sshpass -p 'J3mw?$_6' ssh-copy-id -o 'StrictHostKeyChecking no' -i ~/.ssh/id_rsa.pub root@lebrijo.com -p 2222
|
124
|
-
- ssh root@lebrijo.com -p 2222 "echo 'root:K8rt$_?1' | chpasswd"
|
125
|
-
|
126
|
-
# here you can create other containers
|
127
|
-
# db:
|
128
|
-
# image: ubuntu/postgresql
|
129
|
-
```
|
130
|
-
|
131
|
-
Create containers at host: `ops ship host example.com`
|
132
|
-
|
133
|
-
### Commands
|
134
|
-
|
135
|
-
Create/delete domain names, create/delete hosts and ship/unship hosts:
|
136
|
-
|
137
|
-
* `ops create host HOST_NAME` create the host defined by the name of the file in the 'ops/hosts' folder.
|
138
|
-
* `ops delete host HOST_NAME`
|
139
|
-
* `ops create domain DOMAIN_NAME [IP_ADDRESS]` create a domain to be managed by DigitalOcean.
|
140
|
-
* `ops delete domain DOMAIN_NAME [IP_ADDRESS]`
|
141
|
-
* `ops ship host HOST_NAME` run the containers in the host.
|
142
|
-
* `ops unship host HOST_NAME`
|
143
|
-
|
144
|
-
### TODO: Configuration with Chef
|
145
|
-
|
146
|
-
Configuration with chef commands
|
147
|
-
|
148
|
-
* `ops configure host HOST_NAME`: configure with chef all containers in host. Here you need to install knife-solo gem.
|
149
|
-
* knife solo cook [container_user]@[container_dns_name] -p [container_ssh_port]
|
150
|
-
|
151
31
|
## Usage: Day-to-day rake and capistrano tasks
|
152
32
|
|
153
|
-
|
33
|
+
### Configure Capistrano
|
154
34
|
|
155
35
|
`gem "capistrano-rails"` is included as prun-ops requirement. Create basic files `cap install`
|
156
36
|
|
@@ -163,15 +43,11 @@ require 'capistrano/rails'
|
|
163
43
|
require 'capistrano/bundler'
|
164
44
|
require 'capistrano/rails/assets'
|
165
45
|
require 'capistrano/rails/migrations'
|
46
|
+
require 'capistrano/prun-ops'
|
166
47
|
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
167
48
|
```
|
168
49
|
|
169
|
-
|
170
|
-
|
171
|
-
```ruby
|
172
|
-
## PRUN-OPS configuration
|
173
|
-
require 'prun-ops/cap/all'
|
174
|
-
```
|
50
|
+
Notice that you are adding all prun-ops tasks with the line `require 'capistrano/prun-ops'`
|
175
51
|
|
176
52
|
Your config/deploy/production.rb:
|
177
53
|
|
@@ -196,8 +72,8 @@ Backups/restore database and files in your Rails app.
|
|
196
72
|
Configure your 'config/deploy.rb':
|
197
73
|
|
198
74
|
```ruby
|
199
|
-
# Backup directories
|
200
|
-
set :backup_dirs, %w{public/uploads}
|
75
|
+
# Backup directories
|
76
|
+
set :backup_dirs, %w{public/uploads}
|
201
77
|
```
|
202
78
|
|
203
79
|
And your 'config/applciation.rb':
|
@@ -213,6 +89,7 @@ And your 'config/applciation.rb':
|
|
213
89
|

|
214
90
|
|
215
91
|
* `cap [stg] pull:data`: downloads DDBB and file folders from the stage you need.
|
92
|
+
* `cap [stg] backup[TAG]`: Commit a backup of DDBB and files to the git repo configured. "application-YYYYMMDD" tagged if no tag is provided.
|
216
93
|
* `cap [stg] backup:restore[TAG]`: Restore the last backup into the stage indicated, or tagged state if TAG is provided.
|
217
94
|
* `rake backup |TAG|`: Uploads backup to git store from local, tagging with date, or with TAG if provided. Useful to backup production stage.
|
218
95
|
* `rake backup:restore |TAG|`: Restore last backup copy, or tagged with TAG if provided.
|
@@ -221,12 +98,12 @@ And your 'config/applciation.rb':
|
|
221
98
|
|
222
99
|
Release management
|
223
100
|
|
224
|
-
* `rake release
|
225
|
-
* `rake release:delete
|
101
|
+
* `rake release |VERSION|` push forward from dev-branch to master-branch and tag the commit with VERSION name.
|
102
|
+
* `rake release:delete |VERSION|` remove tag with VERSION name.
|
103
|
+
* `rake git:ff` merge dev branch towards master branch without releasing (Deprecating, new version "rake tomaster[message]")
|
226
104
|
|
227
|
-

|
228
106
|
|
229
|
-
* `rake git:ff` merge dev branch towards master branch without releasing
|
230
107
|
|
231
108
|
### Diagnosis
|
232
109
|
|
@@ -237,6 +114,11 @@ Some capistrano commands useful to connect to server and help with the problem s
|
|
237
114
|
* `cap [stg] c` open a rails console with server
|
238
115
|
* `cap [stg] x[COMMAND]` execute any command in server provided as COMMAND (i.e.: cap production x['free -m'])
|
239
116
|
|
117
|
+
### Monitoring
|
118
|
+
|
119
|
+
Recommend to configure your Rails server with [PRUN Chef recipe](https://github.com/jlebrijo/prun-cfg).
|
120
|
+
|
121
|
+
At this moment we are implementing [NewRelic](http://newrelic.com/) monitoring, including as dependency ['newrelic_rpm'](https://github.com/newrelic/rpm) gem. To configure yourproject you just need to create an account at [NewRelic](http://newrelic.com/) and follow the instructions (creating a 'config/newrelic.yml file with your license_key).
|
240
122
|
|
241
123
|
## Contributing
|
242
124
|
|
@@ -276,4 +158,9 @@ Some capistrano commands useful to connect to server and help with the problem s
|
|
276
158
|
|
277
159
|
### v0.0.9
|
278
160
|
|
279
|
-
* Fixing Capistrano pulling tasks "pull:data"
|
161
|
+
* Fixing Capistrano pulling tasks "pull:data"
|
162
|
+
|
163
|
+
### v0.0.10
|
164
|
+
|
165
|
+
* Removing bin/ops command in order to create open-dock gem
|
166
|
+
* Remove prun-ops dependency from 'config/deployment.rb' file and ad it to 'Capfile' as `require 'capistrano/prun-ops'`
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir.glob("#{File.dirname(__FILE__)}/*.rake").each { |r| load r }
|
File without changes
|
data/lib/prun-ops/railitie.rb
CHANGED
@@ -3,11 +3,7 @@ require 'rails'
|
|
3
3
|
module PrunOps
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
rake_tasks do
|
6
|
-
|
7
|
-
load "tasks/db.rake"
|
8
|
-
load "tasks/git.rake"
|
9
|
-
load "tasks/http.rake"
|
10
|
-
load "tasks/version.rake"
|
6
|
+
Dir.glob("#{File.dirname(__FILE__)}/../tasks/*.rake").each { |r| load r }
|
11
7
|
end
|
12
8
|
end
|
13
9
|
end
|
data/lib/prun-ops/version.rb
CHANGED
data/prun-ops.gemspec
CHANGED
@@ -8,22 +8,19 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = PrunOps::VERSION
|
9
9
|
spec.authors = ["Juan Lebrijo"]
|
10
10
|
spec.email = ["juan@lebrijo.com"]
|
11
|
-
spec.summary = %q{Encapsulates Operations commands needed for a Rails Application.}
|
12
|
-
spec.description = %q{Encapsulates Operations commands for Rails Applications:
|
11
|
+
spec.summary = %q{Encapsulates Deployment and Manteinance Operations commands needed for a Rails Application.}
|
12
|
+
spec.description = %q{Encapsulates Operations commands for Rails Applications: Deploy, Diagnose, Monitoring, Version Releasing and Backup.}
|
13
13
|
spec.homepage = "http://github.com/jlebrijo/prun-ops"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
|
-
spec.executables = ['ops']
|
21
19
|
|
22
20
|
spec.add_development_dependency "bundler", "~> 1.6"
|
23
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
22
|
|
25
23
|
spec.add_runtime_dependency "capistrano-rails"
|
26
|
-
spec.add_runtime_dependency "commander"
|
27
24
|
spec.add_runtime_dependency "thin"
|
28
|
-
spec.add_runtime_dependency "
|
25
|
+
spec.add_runtime_dependency "newrelic_rpm"
|
29
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prun-ops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Lebrijo
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: commander
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: thin
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +67,7 @@ dependencies:
|
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: newrelic_rpm
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - ">="
|
@@ -94,12 +80,11 @@ dependencies:
|
|
94
80
|
- - ">="
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '0'
|
97
|
-
description: 'Encapsulates Operations commands for Rails Applications:
|
98
|
-
|
83
|
+
description: 'Encapsulates Operations commands for Rails Applications: Deploy, Diagnose,
|
84
|
+
Monitoring, Version Releasing and Backup.'
|
99
85
|
email:
|
100
86
|
- juan@lebrijo.com
|
101
|
-
executables:
|
102
|
-
- ops
|
87
|
+
executables: []
|
103
88
|
extensions: []
|
104
89
|
extra_rdoc_files: []
|
105
90
|
files:
|
@@ -108,25 +93,12 @@ files:
|
|
108
93
|
- LICENSE.txt
|
109
94
|
- README.md
|
110
95
|
- Rakefile
|
111
|
-
-
|
96
|
+
- lib/capistrano/all.rake
|
97
|
+
- lib/capistrano/backup.rake
|
98
|
+
- lib/capistrano/diagnosis.rake
|
99
|
+
- lib/capistrano/prun-ops.rb
|
100
|
+
- lib/capistrano/pull.rake
|
112
101
|
- lib/prun-ops.rb
|
113
|
-
- lib/prun-ops/base.rb
|
114
|
-
- lib/prun-ops/cap/all.rb
|
115
|
-
- lib/prun-ops/cap/backup.rb
|
116
|
-
- lib/prun-ops/cap/diagnosis.rb
|
117
|
-
- lib/prun-ops/cap/pull.rb
|
118
|
-
- lib/prun-ops/commands/create_domain.rb
|
119
|
-
- lib/prun-ops/commands/create_host.rb
|
120
|
-
- lib/prun-ops/commands/delete_domain.rb
|
121
|
-
- lib/prun-ops/commands/delete_host.rb
|
122
|
-
- lib/prun-ops/commands/exec_host.rb
|
123
|
-
- lib/prun-ops/commands/list.rb
|
124
|
-
- lib/prun-ops/commands/provision_host.rb
|
125
|
-
- lib/prun-ops/commands/ship_host.rb
|
126
|
-
- lib/prun-ops/commands/unship_host.rb
|
127
|
-
- lib/prun-ops/digitalocean.rb
|
128
|
-
- lib/prun-ops/docker.rb
|
129
|
-
- lib/prun-ops/ops.rb
|
130
102
|
- lib/prun-ops/railitie.rb
|
131
103
|
- lib/prun-ops/version.rb
|
132
104
|
- lib/tasks/backup.rake
|
@@ -158,5 +130,6 @@ rubyforge_project:
|
|
158
130
|
rubygems_version: 2.4.2
|
159
131
|
signing_key:
|
160
132
|
specification_version: 4
|
161
|
-
summary: Encapsulates Operations commands needed for a
|
133
|
+
summary: Encapsulates Deployment and Manteinance Operations commands needed for a
|
134
|
+
Rails Application.
|
162
135
|
test_files: []
|
data/bin/ops
DELETED
data/lib/prun-ops/base.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Ops
|
2
|
-
DIR = "ops"
|
3
|
-
HOSTS_DIR = "#{DIR}/hosts"
|
4
|
-
CONTAINERS_DIR = "#{DIR}/containers"
|
5
|
-
PROVIDERS_DIR = "#{DIR}/providers"
|
6
|
-
|
7
|
-
|
8
|
-
def self.get_user_for(host_name)
|
9
|
-
host_file = "#{HOSTS_DIR}/#{host_name}.yml"
|
10
|
-
begin
|
11
|
-
params = YAML.load_file host_file
|
12
|
-
params["user"]
|
13
|
-
rescue
|
14
|
-
raise "Please, create '#{host_file}' configuring your host"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
command :'create domain' do |c|
|
2
|
-
c.summary = 'Create a domain in your DigitalOcean account'
|
3
|
-
c.syntax = 'ops create domain [domain name] [ip address]'
|
4
|
-
c.description = "Create the domain with #{DigitalOcean::CONFIG_FILE} credentials"
|
5
|
-
c.example 'Create the domain example.com in your DigitalOcean console', 'ops create domain example.com'
|
6
|
-
c.action do |args, options|
|
7
|
-
ip = (args[1].nil?)? '1.1.1.1':args[1]
|
8
|
-
domain = DropletKit::Domain.new(ip_address: ip, name: args[0])
|
9
|
-
resp = DigitalOcean::client.domains.create domain
|
10
|
-
if domain == resp
|
11
|
-
say "Domain #{resp.name} succesfully created!"
|
12
|
-
else
|
13
|
-
raise resp
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
command :'create host' do |c|
|
2
|
-
c.summary = 'Create a droplet/host in your DO account'
|
3
|
-
c.syntax = 'ops create host [DNS_name]'
|
4
|
-
c.description = "Creates the host described in the file #{Ops::HOSTS_DIR}/[DNS_name].yml"
|
5
|
-
c.example "Create the host example.com in your DigitalOcean console. This is described in '#{Ops::HOSTS_DIR}/example.com.yml' like:\n # size: 512mb\n # region: ams1\n # image: coreos-stable\n # ssh_keys:\n # - e7:51:47:bc:7f:dc:2f:3c:56:65:28:e1:10:9c:88:57 xx:xx:xx:xx:xx:xx:xx", 'ops create host example.com'
|
6
|
-
c.action do |args, options|
|
7
|
-
droplet = DigitalOcean::build_droplet args[0]
|
8
|
-
cli = DigitalOcean::client
|
9
|
-
resp = cli.droplets.create droplet
|
10
|
-
if resp == droplet
|
11
|
-
ip = cli.find_droplet_by_name(args[0]).networks["v4"].first.ip_address
|
12
|
-
say "Droplet #{args[0]} (IP: #{ip}) succesfully created!"
|
13
|
-
else
|
14
|
-
raise resp
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
command :'delete domain' do |c|
|
2
|
-
c.summary = 'Delete a domain in your DigitalOcean account'
|
3
|
-
c.syntax = 'ops delete domain [domain name]'
|
4
|
-
c.description = "Delete the domain with #{DigitalOcean::CONFIG_FILE} credentials"
|
5
|
-
c.example 'Delete the domain example.com in your DigitalOcean console', 'ops delete domain example.com'
|
6
|
-
c.action do |args, options|
|
7
|
-
resp = DigitalOcean::client.domains.delete name: args[0]
|
8
|
-
if resp.is_a?(TrueClass)
|
9
|
-
say "Domain #{args[0]} succesfully deleted!"
|
10
|
-
else
|
11
|
-
raise resp
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
command :'delete host' do |c|
|
2
|
-
c.summary = 'Delete a host in your DigitalOcean account'
|
3
|
-
c.syntax = 'ops delete host [DNS_name]'
|
4
|
-
c.description = "Delete the host, based on DNS_name, which (not need but) should be described in its #{Ops::HOSTS_DIR}/[DNS_name].yml file "
|
5
|
-
c.example 'Delete the host example.com in your DigitalOcean console', 'ops delete host example.com'
|
6
|
-
c.action do |args, options|
|
7
|
-
cli = DigitalOcean::client
|
8
|
-
id = cli.find_droplet_by_name(args[0]).id
|
9
|
-
resp = cli.droplets.delete id: id
|
10
|
-
if resp.is_a?(TrueClass)
|
11
|
-
say "Droplet #{args[0]} succesfully deleted!"
|
12
|
-
else
|
13
|
-
raise resp
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
command :'exec host' do |c|
|
2
|
-
c.summary = 'Execute a command in host'
|
3
|
-
c.description = "Execute a command in host defined by DNS_name"
|
4
|
-
c.syntax = 'ops exec host [host_name] "[command]"'
|
5
|
-
c.example "", "ops exec host example.com 'docker ps -a'"
|
6
|
-
c.action do |args, options|
|
7
|
-
host = args[0]
|
8
|
-
user = Ops::get_user_for(host)
|
9
|
-
|
10
|
-
Net::SSH.start(host, user) do |ssh|
|
11
|
-
Docker::containers_for(host).each do |container_name, config|
|
12
|
-
ssh.exec args[1]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
command :list do |c|
|
2
|
-
c.summary = 'List all droplet creation parameters'
|
3
|
-
c.syntax = 'ops list'
|
4
|
-
c.description = "This shows a list in the format '- [id] => [description]'. Use [id] values to create your host file in #{Ops::DIR}/hosts/[dns_name].yml "
|
5
|
-
c.action do |args, options|
|
6
|
-
cli = DigitalOcean::client
|
7
|
-
say "\nDESCRIPTION: #{c.description}\n"
|
8
|
-
|
9
|
-
say "\nSizes:"
|
10
|
-
cli.sizes.all.each do |i|
|
11
|
-
say " - #{i.slug.ljust(6)} => $#{i.price_monthly}/mo"
|
12
|
-
end
|
13
|
-
|
14
|
-
say "\nRegions:"
|
15
|
-
cli.regions.all.each do |i|
|
16
|
-
say " - #{i.slug.ljust(6)} => #{i.name}"
|
17
|
-
end
|
18
|
-
|
19
|
-
say "\nImages:"
|
20
|
-
cli.images.all.each do |i|
|
21
|
-
say " - #{i.slug.ljust(20)} => #{i.distribution} #{i.name}" unless i.slug.nil?
|
22
|
-
end
|
23
|
-
|
24
|
-
say "\nSSH Keys:"
|
25
|
-
cli.ssh_keys.all.each do |i|
|
26
|
-
say " - #{i.fingerprint} => #{i.name}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
command :'provision host' do |c|
|
2
|
-
c.summary = 'Create and ship the host based on config files'
|
3
|
-
c.syntax = 'ops provision host [host_name]'
|
4
|
-
c.description = "Agregate both commands Create and Ship host"
|
5
|
-
c.example "Creates and ships example.com host", 'ops provisiion host example.com'
|
6
|
-
c.action do |args, options|
|
7
|
-
system "#{program :name} create host #{args.join(" ")}"
|
8
|
-
sleep 15
|
9
|
-
system "#{program :name} ship host #{args.join(" ")}"
|
10
|
-
end
|
11
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
command :'ship host' do |c|
|
2
|
-
c.summary = 'Create Docker containers defined in ops/containers/[host_name].yml'
|
3
|
-
c.syntax = 'ops ship host [host_name]'
|
4
|
-
c.description = "Create all docker containers described in #{Ops::CONTAINERS_DIR}/[host_name].yml"
|
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 host example.com'
|
6
|
-
c.action do |args, options|
|
7
|
-
host = args[0]
|
8
|
-
user = Ops::get_user_for(host)
|
9
|
-
|
10
|
-
Docker::containers_for(host).each do |container_name, config|
|
11
|
-
ports = config["ports"].map{|port| "-p #{port}"}.join(" ")
|
12
|
-
options = []
|
13
|
-
config.reject{|k| Docker::SPECIAL_OPTS.include? k}.each do |option, value|
|
14
|
-
options << "--#{option}=#{value}"
|
15
|
-
end
|
16
|
-
say "Container '#{container_name}' loading on #{host}, please wait ....\n"
|
17
|
-
Net::SSH.start(host, user) do |ssh|
|
18
|
-
command = "docker run #{options.join(" ")} --name #{container_name} #{ports} #{config["image"]} #{config["command"]}"
|
19
|
-
say "Docker CMD: #{command}\n"
|
20
|
-
ssh.exec command
|
21
|
-
end
|
22
|
-
sleep 5
|
23
|
-
config["post-conditions"].each { |c| system c }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
command :'unship host' do |c|
|
2
|
-
c.summary = 'Removes all Docker containers defined for the host in '#{Ops::CONTAINERS_DIR}/[host_name].yml'
|
3
|
-
c.syntax = 'ops ship host [host_name]'
|
4
|
-
c.description = "Removes all Docker containers defined for the host in '#{Ops::CONTAINERS_DIR}/[host_name].yml"
|
5
|
-
c.example "", 'ops unship host example.com'
|
6
|
-
c.action do |args, options|
|
7
|
-
host = args[0]
|
8
|
-
user = Ops::get_user_for(host)
|
9
|
-
|
10
|
-
Net::SSH.start(host, user) do |ssh|
|
11
|
-
Docker::containers_for(host).each do |container_name, config|
|
12
|
-
ssh.exec "docker rm -f #{container_name}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'droplet_kit'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
module DigitalOcean
|
5
|
-
CONFIG_FILE = "#{Ops::PROVIDERS_DIR}/digitalocean.yml"
|
6
|
-
|
7
|
-
def self.client
|
8
|
-
begin
|
9
|
-
config = YAML.load_file CONFIG_FILE
|
10
|
-
rescue
|
11
|
-
raise "Please, create '#{CONFIG_FILE}' file with token value"
|
12
|
-
end
|
13
|
-
DropletKit::Client.new(access_token: config["token"])
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.build_droplet(host_name)
|
17
|
-
begin
|
18
|
-
params = YAML.load_file "#{Ops::DIR}/hosts/#{host_name}.yml"
|
19
|
-
params["name"]= host_name
|
20
|
-
rescue
|
21
|
-
raise "Please, create '#{CONFIG_FILE}' file with token value"
|
22
|
-
end
|
23
|
-
DropletKit::Droplet.new params
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
module DropletKit
|
28
|
-
class Client
|
29
|
-
def find_droplet_by_name(host_name)
|
30
|
-
self.droplets.all.find{|d| d.name == host_name}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/prun-ops/docker.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'droplet_kit'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
module Docker
|
5
|
-
SPECIAL_OPTS = ["image", "ports", "command", "post-conditions"]
|
6
|
-
|
7
|
-
def self.containers_for(host_name)
|
8
|
-
config_file = "#{Ops::CONTAINERS_DIR}/#{host_name}.yml"
|
9
|
-
begin
|
10
|
-
config = YAML.load_file config_file
|
11
|
-
rescue
|
12
|
-
raise "Please, create '#{config_file}' file with all containers configured"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
data/lib/prun-ops/ops.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'commander/import'
|
3
|
-
require 'net/ssh'
|
4
|
-
require 'prun-ops/base'
|
5
|
-
require 'prun-ops/digitalocean'
|
6
|
-
require 'prun-ops/docker'
|
7
|
-
require 'prun-ops/version'
|
8
|
-
|
9
|
-
program :name, 'ops'
|
10
|
-
program :version, PrunOps::VERSION
|
11
|
-
program :description, 'Helps to manage Provision/Configuration/Deployment processes based on DigitalOcean, Docker, Chef and Capistrano'
|
12
|
-
program :help_formatter, :compact
|
13
|
-
|
14
|
-
require 'prun-ops/commands/list'
|
15
|
-
require 'prun-ops/commands/create_host'
|
16
|
-
require 'prun-ops/commands/delete_host'
|
17
|
-
require 'prun-ops/commands/create_domain'
|
18
|
-
require 'prun-ops/commands/delete_domain'
|
19
|
-
require 'prun-ops/commands/ship_host'
|
20
|
-
require 'prun-ops/commands/unship_host'
|
21
|
-
require 'prun-ops/commands/exec_host'
|
22
|
-
require 'prun-ops/commands/provision_host'
|
23
|
-
|