capistrano-file-permissions 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +75 -0
- data/Rakefile +1 -0
- data/capistrano-file-permissions.gemspec +24 -0
- data/lib/capistrano-file-permissions.rb +0 -0
- data/lib/capistrano/file-permissions.rb +1 -0
- data/lib/capistrano/tasks/file-permissions.rake +86 -0
- metadata +103 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Peter Mitchell (peterjmit@gmail.com)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Capistrano::FilePermissions
|
2
|
+
|
3
|
+
File permissions handling for Capistrano v3.*
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'capistrano', '~> 3.0.0'
|
11
|
+
gem 'capistrano-file-permissions'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install capistrano-file-permissions
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Require the module in your `Capfile`:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'capistrano/file-permissions'
|
28
|
+
```
|
29
|
+
|
30
|
+
Set the (relative) paths to the files you want to be handled during deployment,
|
31
|
+
and optionally add a user to give access.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
set :file_permissions_paths, ["app/logs", "app/cache"]
|
35
|
+
set :file_permissions_users, ["www-data"]
|
36
|
+
```
|
37
|
+
|
38
|
+
### Acl
|
39
|
+
|
40
|
+
Add the acl task to the deployment flow
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
before "deploy:updated", "deploy:set_permissions:acl"
|
44
|
+
```
|
45
|
+
|
46
|
+
Assume `app/logs` is a shared directory, and `app/cache` is part of the normal
|
47
|
+
release, this gem would execute the following:
|
48
|
+
|
49
|
+
```
|
50
|
+
[..] setfacl -m u:www-data:rwx,u:<deploy-user>:rwx <path-to-app>/shared/app/logs <path-to-app>/<release>/app/cache
|
51
|
+
```
|
52
|
+
|
53
|
+
### Other tasks
|
54
|
+
* deploy:set_permissions:chmod
|
55
|
+
* deploy:set_permissions:chgrp
|
56
|
+
|
57
|
+
### Configuration
|
58
|
+
|
59
|
+
The gem makes the following configuration variables available (shown with defaults)
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
set :file_permissions_roles, :all
|
63
|
+
set :file_permissions_paths, []
|
64
|
+
set :file_permissions_users, []
|
65
|
+
set :file_permissions_groups, []
|
66
|
+
set :file_permissions_chmod_mode, "0777"
|
67
|
+
```
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
1. Fork it
|
72
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
73
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
74
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'capistrano-file-permissions'
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ['Peter Mitchell']
|
9
|
+
spec.email = ['peterjmit@gmail.com']
|
10
|
+
spec.description = %q{File permissions management for Capistrano 3.x}
|
11
|
+
spec.summary = %q{File permissions management for Capistrano 3.x}
|
12
|
+
spec.homepage = 'https://github.com/peterjmit/capistrano-file-permissions'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'capistrano', '>= 3.0.0'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path('../tasks/file-permissions.rake', __FILE__)
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Capistrano
|
2
|
+
class FileNotFound < StandardError
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
def absolute_writable_paths
|
7
|
+
linked_dirs = fetch(:linked_dirs)
|
8
|
+
fetch(:file_permissions_paths).map do |d|
|
9
|
+
linked_dirs.include?(d) ? shared_path.join(d) : release_path.join(d)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def acl_entries(items, type = 'u', permissions = 'rwx')
|
14
|
+
items.map { |item| "#{type}:#{item}:#{permissions}" }
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :deploy do
|
18
|
+
namespace :set_permissions do
|
19
|
+
task :check do
|
20
|
+
on roles fetch(:file_permissions_roles) do
|
21
|
+
absolute_writable_paths.each do |path|
|
22
|
+
unless test "[ -d #{path} ]" or test "[ -e #{path} ]"
|
23
|
+
msg = "Cannot change permissions: #{path} is not a file or directory"
|
24
|
+
error msg
|
25
|
+
fail Capistrano::FileNotFound, msg
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Set user/group permissions on configured paths with setfacl"
|
32
|
+
task :acl => [:check] do
|
33
|
+
next unless any? :file_permissions_paths
|
34
|
+
on roles fetch(:file_permissions_roles) do |host|
|
35
|
+
users = fetch(:file_permissions_users).push(host.user)
|
36
|
+
entries = acl_entries(users);
|
37
|
+
paths = absolute_writable_paths
|
38
|
+
|
39
|
+
if any? :file_permissions_groups
|
40
|
+
entries.push(*acl_entries(fetch(:file_permissions_groups), 'g'))
|
41
|
+
end
|
42
|
+
|
43
|
+
entries = entries.join(',')
|
44
|
+
|
45
|
+
execute :setfacl, "-m", entries, *paths
|
46
|
+
execute :setfacl, "-dm", entries, *paths
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "Recursively set mode (from \"file_permissions_chmod_mode\") on configured paths with chmod"
|
51
|
+
task :chmod => [:check] do
|
52
|
+
next unless any? :file_permissions_paths
|
53
|
+
on roles fetch(:file_permissions_roles) do |host|
|
54
|
+
execute :chmod, "-R", fetch(:file_permissions_chmod_mode), *absolute_writable_paths
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "Recursively change group ownership for configured paths, and make them group writable"
|
59
|
+
task :chgrp => [:check] do
|
60
|
+
next unless any? :file_permissions_paths
|
61
|
+
next unless any? :file_permissions_groups
|
62
|
+
|
63
|
+
groups = fetch(:file_permissions_groups)
|
64
|
+
if groups.length > 1
|
65
|
+
warn "More than one group configured, using the first group only"
|
66
|
+
end
|
67
|
+
|
68
|
+
on roles fetch(:file_permissions_roles) do |host|
|
69
|
+
paths = absolute_writable_paths
|
70
|
+
execute :sudo, :chgrp, "-R", groups.first, *paths
|
71
|
+
# make sure all child directories inherit group writable
|
72
|
+
execute :sudo, :chmod, "-R", "g+rws", *paths
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
namespace :load do
|
79
|
+
task :defaults do
|
80
|
+
set :file_permissions_roles, :all
|
81
|
+
set :file_permissions_paths, []
|
82
|
+
set :file_permissions_users, []
|
83
|
+
set :file_permissions_groups, []
|
84
|
+
set :file_permissions_chmod_mode, "0777"
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-file-permissions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Peter Mitchell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: File permissions management for Capistrano 3.x
|
63
|
+
email:
|
64
|
+
- peterjmit@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- capistrano-file-permissions.gemspec
|
75
|
+
- lib/capistrano-file-permissions.rb
|
76
|
+
- lib/capistrano/file-permissions.rb
|
77
|
+
- lib/capistrano/tasks/file-permissions.rake
|
78
|
+
homepage: https://github.com/peterjmit/capistrano-file-permissions
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.25
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: File permissions management for Capistrano 3.x
|
103
|
+
test_files: []
|