management 1.2 → 1.3

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.
data/README.md CHANGED
@@ -2,122 +2,103 @@
2
2
 
3
3
  Minimalist EC2 configuration & deployment tool.
4
4
 
5
- - Version: **1.2**
5
+ - Version: **1.3**
6
6
 
7
- ![build status](https://travis-ci.org/sdegutis/management.svg?branch=master)
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
- `gem install management`
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
- $ management
21
- Usage: management [command] [args*]
22
-
23
- Commands:
24
- create-server <env> <type>
25
- list-servers [<env>]
26
- destroy-server <server>
27
- start-server <server>
28
- stop-server <server>
29
- run-script <server> <script>
30
- ssh-server <server>
31
-
32
- -h, --help Display this screen
33
- -v, --version Show version
34
-
35
- $ management list-servers
36
- Name State IP Private IP Size Env Type EC2 ID
37
- -------------------- ---------- -------------------- -------------------- ---------- --------------- --------------- -----------
38
-
39
-
40
- $ management create-server staging web
41
- Created "staging-web-1".
42
-
43
-
44
- $ management list-servers
45
- Name State IP Private IP Size Env Type EC2 ID
46
- -------------------- ---------- -------------------- -------------------- ---------- --------------- --------------- -----------
47
- staging-web-1 running 101.102.103.104 1.2.3.4 m1.large staging db i-12341234
48
-
49
-
50
- $ management run-script staging-web-1 setup-web
51
- Copying resources/scripts/bootstrap_base.sh -> /home/webapp/bootstrap_base.sh
52
- Running /home/webapp/bootstrap_base.sh
53
- [...snip...]
54
- Copying resources/files/web.conf.erb -> /etc/init/web.conf
55
- Copying resources/files/nginx.conf -> /etc/init/nginx.conf
56
- Copying resources/scripts/start_web_server.sh -> /home/webapp/start_web_server.sh
57
- Running /home/webapp/start_web_server.sh
58
- [...snip...]
59
- ```
60
-
61
- #### Niche
62
-
63
- The remote server only needs ssh and `tar -xzf` to be available, which
64
- means it'll work in pretty much any linux server, out-of-the-box.
65
-
66
- If you only need to provision and manage a handful of servers, this
67
- project may be right for you.
68
-
69
- #### Setup
70
-
71
- Put this in `management_config.yml':
72
-
73
- ```yaml
74
- cloud: # NOTE: this just gets passed to Fog::Compute.new
75
- provider: AWS
76
- aws_access_key_id: 123
77
- aws_secret_access_key: 456
78
- region: New York 1
79
-
80
- envs:
81
- - staging
82
- - production
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
- ./my-project
109
- |-- management_config.yml
110
- `-- resources
111
- |-- files
112
- | |-- nginx.conf
113
- | `-- web.conf.erb
114
- |-- keys
115
- | |-- id_rsa_digitalocean
116
- | `-- id_rsa_digitalocean.pub
117
- `-- scripts
118
- |-- bootstrap_base.sh
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
- ```bash
176
- sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
177
- cd /tmp
178
- wget http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
179
- tar -xzf ruby-2.0.0-p247.tar.gz
180
- cd ruby-2.0.0-p247
181
- ./configure --prefix=/usr/local
182
- make
183
- sudo make install
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
@@ -71,4 +71,8 @@ class Fog::Compute::Server
71
71
  def chown_r(remote_path, chown)
72
72
  ssh("sudo chown -R #{chown} #{remote_path}")
73
73
  end
74
+
75
+ def chmod(remote_path, chmod)
76
+ ssh("sudo chmod #{chmod} #{remote_path}")
77
+ end
74
78
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Management
2
- VERSION = "1.2"
2
+ VERSION = "1.3"
3
3
  end
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: management
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: