prun-ops 0.0.3 → 0.0.4
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 +221 -5
- data/lib/prun-ops/cap/all.rb +6 -4
- data/lib/prun-ops/commands/ship_host.rb +3 -1
- data/lib/prun-ops/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ebe6eda5e0f47e2692d1705abc903e462d0023e
|
4
|
+
data.tar.gz: e80f8e6acd5dda6dbd4c9a9239a8545284b7a291
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27b9e18821e93f35d48ccf9a0c9e1ce4b30272f52c489fbc3fd8bd9cf77faf74fd0e542ceae0fce2f1582ae55a9b4257ab6faaf0f16ddc19626280c3c7aa4fe4
|
7
|
+
data.tar.gz: 8b286b0b740e52408b0de9193dd042273e46c727268a9ac9aec47ac100517f653c768ba5ae71ba6585f4cc2352717c9b165a2c3e6abc185a263481f011f2c0ab
|
data/README.md
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
Covers all Operations in a Ruby on Rails Application server:
|
4
4
|
|
5
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://
|
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
7
|
1. DEPLOYMENT: Capistrano tasks to depoly your rails Apps.
|
8
|
-
1.
|
8
|
+
1. DIAGNOSIS: Capistrano diagnosis tools to guet your Apps status on real time.
|
9
9
|
1. RELEASE: Rake tasks to manage and tag version number in your Apps (X.Y.Z).
|
10
10
|
1. BACKUP: Backup policy for database and files in your Apps, using git as storage.
|
11
11
|
|
@@ -27,9 +27,214 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
$ gem install prun-ops
|
29
29
|
|
30
|
-
## Usage
|
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
|
+
## Usage: Day-to-day rake and capistrano tasks
|
152
|
+
|
153
|
+
Add the gem to the Gemfile in your Rails Application.
|
154
|
+
|
155
|
+
`gem "capistrano-rails"` is included as prun-ops requirement. Create basic files `cap install`
|
156
|
+
|
157
|
+
Capfile should include these requirements:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
require 'capistrano/setup'
|
161
|
+
require 'capistrano/deploy'
|
162
|
+
require 'capistrano/rails'
|
163
|
+
require 'capistrano/bundler'
|
164
|
+
require 'capistrano/rails/assets'
|
165
|
+
require 'capistrano/rails/migrations'
|
166
|
+
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
167
|
+
```
|
168
|
+
|
169
|
+
Add to your config/deploy.rb this:
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
## PRUN-OPS configuration
|
173
|
+
require 'prun-ops/cap/all'
|
174
|
+
```
|
175
|
+
|
176
|
+
Your config/deploy/production.rb:
|
177
|
+
|
178
|
+
```
|
179
|
+
server "example.com", user: 'root', roles: %w{web app}, port: 2222
|
180
|
+
```
|
181
|
+
|
182
|
+
Note: Remember change this line in production.rb file: `config.assets.compile = true`
|
183
|
+
|
184
|
+
### Deployment
|
185
|
+
|
186
|
+
* `cap [stg] deploy` deploy your app as usual
|
187
|
+
* `cap [stg] deploy:restart` restart thin server of this application
|
188
|
+
* `cap [stg] deploy:stop` stop thin server
|
189
|
+
* `cap [stg] deploy:start` start thin server
|
190
|
+
* `cap [stg] db:setup` load schema and seeds for first DB setup
|
191
|
+
|
192
|
+
### Backup
|
193
|
+
|
194
|
+
Backups/restore database and files in your Rails app.
|
195
|
+
|
196
|
+
Configure your 'config/deploy.rb':
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
# Backup directories
|
200
|
+
set :backup_dirs, %w{public/uploads}
|
201
|
+
```
|
202
|
+
|
203
|
+
And your 'config/applciation.rb':
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
# Backup directories
|
207
|
+
config.backup_dirs = %w{public/ckeditor_assets public/system}
|
208
|
+
|
209
|
+
# Backup repo
|
210
|
+
config.backup_repo = "git@github.com:example/backup.git"
|
211
|
+
```
|
212
|
+
|
213
|
+

|
214
|
+
|
215
|
+
* `cap [stg] pull:data`: downloads DDBB and file folders from the stage you need.
|
216
|
+
* `cap [stg] backup:restore[TAG]`: Restore the last backup into the stage indicated, or tagged state if TAG is provided.
|
217
|
+
* `rake backup |TAG|`: Uploads backup to git store from local, tagging with date, or with TAG if provided. Useful to backup production stage.
|
218
|
+
* `rake backup:restore |TAG|`: Restore last backup copy, or tagged with TAG if provided.
|
219
|
+
|
220
|
+
### TODO: Release
|
221
|
+
|
222
|
+
Release management
|
223
|
+
|
224
|
+
* `rake release[VERSION]` push forward from dev-branch to master-branch and tag the commit with VERSION name.
|
225
|
+
* `rake release:delete[VERSION]` remove tag with VERSION name.
|
226
|
+
|
227
|
+

|
228
|
+
|
229
|
+
### Diagnosis
|
230
|
+
|
231
|
+
Some capistrano commands useful to connect to server and help with the problem solving.
|
232
|
+
|
233
|
+
* `cap [stg] ssh` open a ssh connection with server
|
234
|
+
* `cap [stg] log[LOG_FILENAME]` tail rails log by default, or other if LOG_FILENAME is provided
|
235
|
+
* `cap [stg] c` open a rails console with server
|
236
|
+
* `cap [stg] x[COMMAND]` execute any command in server provided as COMMAND (i.e.: cap production x['free -m'])
|
31
237
|
|
32
|
-
TODO: Write usage instructions here
|
33
238
|
|
34
239
|
## Contributing
|
35
240
|
|
@@ -41,4 +246,15 @@ TODO: Write usage instructions here
|
|
41
246
|
|
42
247
|
## License
|
43
248
|
|
44
|
-
[MIT License](http://opensource.org/licenses/MIT).
|
249
|
+
[MIT License](http://opensource.org/licenses/MIT). Made by [Lebrijo.com](http://lebrijo.com)
|
250
|
+
|
251
|
+
## Release notes
|
252
|
+
|
253
|
+
### v0.0.2
|
254
|
+
|
255
|
+
* First publication
|
256
|
+
|
257
|
+
### v0.0.3
|
258
|
+
|
259
|
+
* Changing homepage and License
|
260
|
+
* start|stop|restart thin server per application as Capistrano task
|
data/lib/prun-ops/cap/all.rb
CHANGED
@@ -6,10 +6,12 @@ set :backup_dirs, []
|
|
6
6
|
|
7
7
|
namespace :deploy do
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
%w(start stop restart).each do |action|
|
10
|
+
desc "#{action.capitalize} application"
|
11
|
+
task :"#{action}" do
|
12
|
+
on roles(:app) do
|
13
|
+
execute "service #{fetch :application} #{action}"
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
@@ -15,7 +15,9 @@ command :'ship host' do |c|
|
|
15
15
|
end
|
16
16
|
say "Container '#{container_name}' loading on #{host}, please wait ....\n"
|
17
17
|
Net::SSH.start(host, user) do |ssh|
|
18
|
-
|
18
|
+
command = "docker run #{options.join(" ")} --name #{container_name} #{ports} #{config["image"]} #{config["command"]}"
|
19
|
+
say "Docker CMD: #{command}"
|
20
|
+
ssh.exec command
|
19
21
|
end
|
20
22
|
sleep 5
|
21
23
|
config["post-conditions"].each { |c| system c }
|
data/lib/prun-ops/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Lebrijo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|