management 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +93 -114
- data/lib/ext/fog.rb +4 -0
- data/lib/management/commands/run_script.rb +2 -0
- data/lib/management/version.rb +1 -1
- data/spec/main_spec.rb +22 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -2,122 +2,103 @@
|
|
2
2
|
|
3
3
|
Minimalist EC2 configuration & deployment tool.
|
4
4
|
|
5
|
-
- Version: **1.
|
5
|
+
- Version: **1.3**
|
6
6
|
|
7
|
-
![
|
7
|
+
[![Build Status](https://travis-ci.org/sdegutis/management.svg?branch=master)](https://travis-ci.org/sdegutis/management)
|
8
|
+
[![Dependency Status](https://gemnasium.com/sdegutis/management.svg)](https://gemnasium.com/sdegutis/management)
|
9
|
+
[![Code Climate](https://codeclimate.com/github/sdegutis/management.png)](https://codeclimate.com/github/sdegutis/management)
|
10
|
+
[![Gem Version](https://badge.fury.io/rb/management.svg)](http://badge.fury.io/rb/management)
|
11
|
+
[![Gittip](http://img.shields.io/gittip/sdegutis.png)](https://www.gittip.com/sdegutis/)
|
8
12
|
|
9
13
|
#### Install
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
#### Intro
|
14
|
-
|
15
|
-
Read [this short blog post](http://sdegutis.github.io/2014/06/09/announcing-management/) for a brief summary of this project.
|
15
|
+
gem install management
|
16
16
|
|
17
17
|
#### Usage
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
types:
|
85
|
-
web: # NOTE: this just gets passed to compute.servers.create
|
86
|
-
image_id: ami-1234
|
87
|
-
flavor_id: m1.small
|
88
|
-
key_name: my-ssh-key-name
|
89
|
-
groups: ["web"]
|
90
|
-
ssh_key_path: resources/my-ssh-key
|
91
|
-
|
92
|
-
scripts:
|
93
|
-
setup-web:
|
94
|
-
- copy: [resources/scripts/bootstrap_base.sh, /home/webapp/bootstrap_base.sh]
|
95
|
-
- run: /home/webapp/bootstrap_base.sh
|
96
|
-
- copy: [resources/files/web.conf.erb, /etc/init/web.conf, template: true]
|
97
|
-
- copy: [resources/files/nginx.conf, /etc/init/nginx.conf]
|
98
|
-
- copy: [resources/scripts/start_web_server.sh, /home/webapp/start_web_server.sh]
|
99
|
-
- run: /home/webapp/start_web_server.sh
|
100
|
-
```
|
19
|
+
$ management
|
20
|
+
Usage: management [command [arg ...]]
|
21
|
+
|
22
|
+
Commands:
|
23
|
+
create-server <env> <type>
|
24
|
+
list-servers [<env>]
|
25
|
+
destroy-servers <server> [...]
|
26
|
+
start-server <server>
|
27
|
+
stop-server <server>
|
28
|
+
run-script <server> <script>
|
29
|
+
ssh-server <server>
|
30
|
+
list-addresses
|
31
|
+
attach-address <address> <server>
|
32
|
+
open-console
|
33
|
+
|
34
|
+
-h, --help Display this screen
|
35
|
+
-v, --version Show version
|
36
|
+
|
37
|
+
#### Features
|
38
|
+
|
39
|
+
1. All your configuration is done in a single YAML file.
|
40
|
+
2. Automating deployment can be done in plain-old bash.
|
41
|
+
3. You explicitly specify what files to copy and where to.
|
42
|
+
4. You can mix run-script and copy-file phases together.
|
43
|
+
5. There's a built-in concept of environments.
|
44
|
+
6. You can template any of your copied files (using ERB).
|
45
|
+
7. There are as few implicit rules as possible.
|
46
|
+
|
47
|
+
Management isn't for everyone. It uses a push-based method which isn't
|
48
|
+
ideal if you have tons of servers, but is perfect for small setups
|
49
|
+
like the one we have at work. Also, it assumes you're only dealing
|
50
|
+
with servers that it created, since it requires certain metadata to
|
51
|
+
work. And because it uses EC2 tags, it's currently kind of hard-coded
|
52
|
+
to only work on EC2.
|
53
|
+
|
54
|
+
#### Sample Configs
|
55
|
+
|
56
|
+
Put this in `management_config.yml` at the root of some project:
|
57
|
+
|
58
|
+
cloud:
|
59
|
+
provider: AWS
|
60
|
+
aws_access_key_id: 123
|
61
|
+
aws_secret_access_key: 456
|
62
|
+
region: New York 1
|
63
|
+
|
64
|
+
envs:
|
65
|
+
- staging
|
66
|
+
- production
|
67
|
+
|
68
|
+
types:
|
69
|
+
web:
|
70
|
+
image_id: ami-1234
|
71
|
+
flavor_id: m1.small
|
72
|
+
key_name: my-ssh-key-name
|
73
|
+
groups: ["web"]
|
74
|
+
ssh_key_path: resources/my-ssh-key
|
75
|
+
|
76
|
+
scripts:
|
77
|
+
setup-web:
|
78
|
+
- copy: [resources/scripts/bootstrap_base.sh, /home/webapp/bootstrap_base.sh]
|
79
|
+
- run: /home/webapp/bootstrap_base.sh
|
80
|
+
- copy: [resources/files/web.conf.erb, /etc/init/web.conf, template: true]
|
81
|
+
- copy: [resources/files/nginx.conf, /etc/init/nginx.conf]
|
82
|
+
- copy: [resources/scripts/start_web_server.sh, /home/webapp/start_web_server.sh]
|
83
|
+
- run: /home/webapp/start_web_server.sh
|
101
84
|
|
102
85
|
Management doesn't care where any of your files are, with the exception of
|
103
86
|
`management_config.yml`, which it expects to be in your project's
|
104
87
|
root. Here's the relevant part of the file structure that the above
|
105
88
|
sample config assumes:
|
106
89
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
`-- start_web_server.sh
|
120
|
-
```
|
90
|
+
./my-project
|
91
|
+
|-- management_config.yml
|
92
|
+
`-- resources
|
93
|
+
|-- files
|
94
|
+
| |-- nginx.conf
|
95
|
+
| `-- web.conf.erb
|
96
|
+
|-- keys
|
97
|
+
| |-- id_rsa_digitalocean
|
98
|
+
| `-- id_rsa_digitalocean.pub
|
99
|
+
`-- scripts
|
100
|
+
|-- bootstrap_base.sh
|
101
|
+
`-- start_web_server.sh
|
121
102
|
|
122
103
|
#### Details
|
123
104
|
|
@@ -172,17 +153,15 @@ If you wanted to install Ruby 2 in your setup phase, you might add
|
|
172
153
|
this to one of your scripts
|
173
154
|
([courtesy of Brandon Hilkert](https://github.com/brandonhilkert/fucking_shell_scripts)):
|
174
155
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
make
|
183
|
-
|
184
|
-
rm -rf /tmp/ruby*
|
185
|
-
```
|
156
|
+
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
|
157
|
+
cd /tmp
|
158
|
+
wget http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
|
159
|
+
tar -xzf ruby-2.0.0-p247.tar.gz
|
160
|
+
cd ruby-2.0.0-p247
|
161
|
+
./configure --prefix=/usr/local
|
162
|
+
make
|
163
|
+
sudo make install
|
164
|
+
rm -rf /tmp/ruby*
|
186
165
|
|
187
166
|
#### License
|
188
167
|
|
data/lib/ext/fog.rb
CHANGED
@@ -45,6 +45,7 @@ module Management
|
|
45
45
|
def copy_file(server, local_path, remote_path, opts = nil)
|
46
46
|
should_template = opts && opts[:template]
|
47
47
|
custom_chown = opts && opts[:chown]
|
48
|
+
custom_chmod = opts && opts[:chmod]
|
48
49
|
|
49
50
|
Dir.mktmpdir('management-file-dir') do |file_tmpdir|
|
50
51
|
|
@@ -70,6 +71,7 @@ module Management
|
|
70
71
|
server.copy_file(local_tar_path, remote_tar_path)
|
71
72
|
server.extract_tar(remote_tar_path)
|
72
73
|
server.chown_r(remote_path, custom_chown) if custom_chown
|
74
|
+
server.chmod(remote_path, custom_chmod) if custom_chmod
|
73
75
|
end
|
74
76
|
end
|
75
77
|
end
|
data/lib/management/version.rb
CHANGED
data/spec/main_spec.rb
CHANGED
@@ -184,6 +184,10 @@ describe 'management' do
|
|
184
184
|
FileUtils.chown_R(user, group, File.join("/fake-remote-dir", remote))
|
185
185
|
end
|
186
186
|
|
187
|
+
server.define_singleton_method(:chmod) do |remote, chmod|
|
188
|
+
FileUtils.chmod(Integer(chmod), File.join("/fake-remote-dir", remote))
|
189
|
+
end
|
190
|
+
|
187
191
|
end
|
188
192
|
|
189
193
|
it "copies file contents into their remote paths" do
|
@@ -219,6 +223,24 @@ describe 'management' do
|
|
219
223
|
expect( Etc.getgrgid(stats.gid).name ).to eq `id -gn`.chomp
|
220
224
|
end
|
221
225
|
|
226
|
+
it "chmods files correctly when specified" do
|
227
|
+
File.write("foo", "hello world")
|
228
|
+
FileUtils.chmod(0755, "foo")
|
229
|
+
without_stdout { subject.copy_file(server, "foo", "/remote/foo", chmod: "0700") }
|
230
|
+
|
231
|
+
stats = File.stat("/fake-remote-dir/remote/foo")
|
232
|
+
expect(stats.mode & 0o777).to eq 0o700
|
233
|
+
end
|
234
|
+
|
235
|
+
it "doesn't chmod anything unless specified" do
|
236
|
+
File.write("foo", "hello world")
|
237
|
+
FileUtils.chmod(0755, "foo")
|
238
|
+
without_stdout { subject.copy_file(server, "foo", "/remote/foo") }
|
239
|
+
|
240
|
+
stats = File.stat("/fake-remote-dir/remote/foo")
|
241
|
+
expect(stats.mode & 0o777).to eq 0o755
|
242
|
+
end
|
243
|
+
|
222
244
|
it "fails if multiple local paths don't exist" do
|
223
245
|
script = subject.get_script("testing")
|
224
246
|
list = subject.missing_local_files(script)
|