capistrano-twelvefactor 0.0.1 → 0.0.2
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fda67dfc4bcf35763b354696413cb6574f8dcf0d
|
4
|
+
data.tar.gz: 7610e9eb9826473fd33110830fee6576d7ad6983
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd6b1f6a28e2d7cf8b9a14522044887d88b4a8e354be4555c3346584c70e1ee8103792d864602ed957803222f9b8c352a77ea56c503953dadd32bfcadb167b59
|
7
|
+
data.tar.gz: 43a8e4481d98e50a662c75f04fc013b6beebf43e5ca105ef7ff2e13f4bd8d534deb51efd243df129f0c0555dfca652e676090514c91f0ad02472f4458805438e
|
data/README.md
CHANGED
@@ -18,14 +18,20 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
### In your Capfile
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'capistrano/twelvefactor'
|
25
|
+
```
|
26
|
+
|
21
27
|
### In your $stage.rb
|
22
28
|
|
23
29
|
Set the file you want to be written to, in order to change environment
|
24
|
-
variables. Usually this would be `.bashrc`, `/etc/environment` or something
|
25
|
-
similar, depending on your
|
30
|
+
variables. Usually this would be `.env`, `.bashrc`, `/etc/environment` or something
|
31
|
+
similar, depending on your OS and app setup. The default is `.env`.
|
26
32
|
|
27
33
|
```ruby
|
28
|
-
set :environment_file, '.
|
34
|
+
set :environment_file, '.custom_file'
|
29
35
|
```
|
30
36
|
|
31
37
|
### On your command line
|
@@ -33,13 +39,33 @@ set :environment_file, '.bashrc'
|
|
33
39
|
#### Setting a value
|
34
40
|
|
35
41
|
```bash
|
36
|
-
$ cap production config:set
|
42
|
+
$ cap production config:set[FOO=bar]
|
43
|
+
```
|
44
|
+
|
45
|
+
**Note**: If your run zsh, you have to use quotes since square brackets are used
|
46
|
+
for some shell features:
|
47
|
+
|
48
|
+
|
49
|
+
```bash
|
50
|
+
$ cap production "config:set[FOO=bar]"
|
37
51
|
```
|
38
52
|
|
39
53
|
#### Removing a value
|
40
54
|
|
41
55
|
```bash
|
42
|
-
$ cap production config:unset
|
56
|
+
$ cap production config:unset[FOO]
|
57
|
+
```
|
58
|
+
|
59
|
+
Same zsh workaround applies here.
|
60
|
+
|
61
|
+
### Restarting your app
|
62
|
+
|
63
|
+
Sometimes a change in the environment file requires a restart of your
|
64
|
+
application. Add this to your `deploy.rb` to do so:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
after 'config:set', 'deploy:restart'
|
68
|
+
after 'config:unset', 'deploy:restart'
|
43
69
|
```
|
44
70
|
|
45
71
|
## Contributing
|
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
# Default value for capistrano
|
2
|
+
set :environment_file, '.env'
|
@@ -4,27 +4,35 @@ namespace :config do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
desc 'Set config value by key'
|
7
|
-
task :set do
|
8
|
-
config = Hash[[:key, :value].zip(
|
7
|
+
task :set, :options do |task, args|
|
8
|
+
config = Hash[[:key, :value].zip(args[:options].split('='))]
|
9
9
|
cmd = Capistrano::Twelvefactor::Command.new(file_name, config)
|
10
10
|
|
11
11
|
on release_roles :all do
|
12
|
-
|
12
|
+
if fetch(:use_sudo)
|
13
|
+
sudo cmd.set_command
|
14
|
+
else
|
15
|
+
execute cmd.set_command
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
16
20
|
desc 'Remove config by key'
|
17
|
-
task :unset do
|
18
|
-
cmd = Capistrano::Twelvefactor::Command.new(file_name, key:
|
21
|
+
task :unset, :options do |task, args|
|
22
|
+
cmd = Capistrano::Twelvefactor::Command.new(file_name, key: args[:options])
|
19
23
|
|
20
24
|
on release_roles :all do
|
21
25
|
begin
|
22
|
-
|
23
|
-
|
26
|
+
if fetch(:use_sudo)
|
27
|
+
sudo cmd.unset_command
|
28
|
+
else
|
29
|
+
execute cmd.unset_command
|
30
|
+
end
|
24
31
|
rescue => e
|
25
|
-
|
26
|
-
|
27
|
-
|
32
|
+
unless e.message =~ /Nothing written/
|
33
|
+
error e
|
34
|
+
exit 1
|
35
|
+
end
|
28
36
|
end
|
29
37
|
end
|
30
38
|
end
|
@@ -4,38 +4,64 @@ load File.expand_path('../twelvefactor/tasks/capistrano-twelvefactor.rake', __FI
|
|
4
4
|
|
5
5
|
module Capistrano
|
6
6
|
module Twelvefactor
|
7
|
+
# Wrapper for remote shell commands
|
7
8
|
class Command
|
9
|
+
# Initialize new command
|
10
|
+
#
|
11
|
+
# @param [String] file filename to write config to
|
12
|
+
# @param [Hash] config config in the form `key: :value`
|
8
13
|
def initialize(file, config)
|
9
14
|
@file = file
|
10
15
|
@config = config
|
11
16
|
end
|
12
17
|
|
18
|
+
# Returns command to replace or append configuration
|
19
|
+
#
|
20
|
+
# @return [String]
|
13
21
|
def set_command
|
14
22
|
[grep_cmd, '&&', replace_cmd, '||', append_cmd].join(' ')
|
15
23
|
end
|
16
24
|
|
25
|
+
# Returns command to remove line from configuration
|
26
|
+
#
|
27
|
+
# @return [String]
|
17
28
|
def unset_command
|
18
29
|
[grep_cmd, '&&', unset_cmd].join(' ')
|
19
30
|
end
|
20
31
|
|
21
32
|
private
|
22
33
|
|
34
|
+
# Returns command to grep config file for assignment
|
35
|
+
#
|
36
|
+
# @return [String]
|
23
37
|
def grep_cmd
|
24
38
|
sprintf 'grep -Fq "%s" %s', key_set_string, @file
|
25
39
|
end
|
26
40
|
|
41
|
+
# Returns key assignment
|
42
|
+
#
|
43
|
+
# @return [String]
|
27
44
|
def key_set_string
|
28
45
|
@config[:key] + '='
|
29
46
|
end
|
30
47
|
|
48
|
+
# Returns command to replace assignment
|
49
|
+
#
|
50
|
+
# @return [String]
|
31
51
|
def replace_cmd
|
32
52
|
sprintf 'sed -i "s/%s.*/%s%s/" %s', key_set_string, key_set_string, @config[:value], @file
|
33
53
|
end
|
34
54
|
|
55
|
+
# Returns command to append assignment to config file
|
56
|
+
#
|
57
|
+
# @return [String]
|
35
58
|
def append_cmd
|
36
59
|
sprintf 'echo "%s%s" >> %s', key_set_string, @config[:value], @file
|
37
60
|
end
|
38
61
|
|
62
|
+
# Returns command to remove assignment from config file
|
63
|
+
#
|
64
|
+
# @return [String]
|
39
65
|
def unset_cmd
|
40
66
|
sprintf 'sed -i /%s/d %s', key_set_string, @file
|
41
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-twelvefactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Behrendt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02
|
11
|
+
date: 2014-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|