capistrano-env_config 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d9ecd854065ec9fa3cc2d99fe6f3d0cd1be82b8
4
- data.tar.gz: 17d48b6067c3795bd28f21e2a31091a4e24607fc
3
+ metadata.gz: 2dec343550dfd2b3654978a89e53149fa139ca27
4
+ data.tar.gz: 26058a4ef80721f3c3cdbdfc5b57b306140abed8
5
5
  SHA512:
6
- metadata.gz: b2d0978e01919ac08ddd9591da3987249ae420d14c87872f36a302e7358c1283a0c6aaffdcc1724f5b1e98df9a492dbf129eb54d7d60470bfb909c99a536a499
7
- data.tar.gz: 8b48884c0e9c11757d3e1155b75abf53e3cc2881221fba45faa051bf811a40fa230a35fce9a86ed52d56cb3da925b15b248452f146979584ad9efa9d63536ac1
6
+ metadata.gz: af3c204fb185a1bbb94918962f6643e67c999e6788f2920c32c0d34986fcd4f949d4ff3e4f37ce28b47bd9e8938a4088e7e04e534ecdf27fda5a362a24574b57
7
+ data.tar.gz: ca1260e663d042e711b692901367768ab880e601b2d2907d06dc98fff0f1ecbba4173a3f3e69990721556680b662c8d758e0186f55c3ccf0def392f36f546c52
@@ -0,0 +1,15 @@
1
+ v0.0.2
2
+ ------
3
+
4
+ * Removed development dependency on `gem 'rake'`
5
+ * Improved gem description. Added documentation about programatic use.
6
+ * Added configuration option for roles that env_config sets/reads the
7
+ environment variables from.
8
+ * Added an argument for specifically setting roles when using the `Environment`
9
+ class programatically.
10
+
11
+
12
+ v0.0.1
13
+ ------
14
+
15
+ * Initial version.
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
+ [![Gem Version](https://badge.fury.io/rb/capistrano-env_config.svg)](https://badge.fury.io/rb/capistrano-env_config)
2
+
1
3
  capistrano-env_config
2
4
  =====================
3
5
 
4
- A tool for managing your environment variables across your cluster.
6
+ A tool for managing your environment variables across your cluster. The library
7
+ manipulates the system-wide environment variables by modifying the
8
+ `/etc/environment` file.
5
9
 
6
10
  Usage
7
11
  -----
@@ -12,9 +16,31 @@ Usage
12
16
  * `cap env:set[VARIABLE_NAME=VALUE]` – To set an environment variable
13
17
  * `cap env:sync` – To synchronise the environment configuration across servers
14
18
 
19
+ If you need to programatically manipulate the environment you can use the
20
+ `Capistrano::EnvConfig::Environment` class like so:
21
+
22
+ ```ruby
23
+ require 'capistrano/env_config/environment'
24
+
25
+ environment = Capistrano::EnvConfig::Environment.new
26
+ environment.list
27
+ environment.get( 'VARIABLE' )
28
+ environment.set( 'VARIABLE', 'VALUE' )
29
+ environment.delete( 'VARIABLE' )
30
+ environment.sync
31
+ ```
32
+
15
33
  Installation
16
34
  ------------
17
35
 
36
+ Add the gem to your Gemfile:
37
+
38
+ ```gemfile
39
+ group :development do
40
+ gem 'capistrano-env_config'
41
+ end
42
+ ```
43
+
18
44
  In your server provisioning script, make sure the deploy user has write access
19
45
  to the `/etc/environment` file, which is used to store the configured variables.
20
46
 
@@ -23,4 +49,12 @@ The simplest way to do that would be to:
23
49
  ```bash
24
50
  chown :deploy /etc/environment
25
51
  chmod g+w /etc/environment
26
- ```
52
+ ```
53
+
54
+ License
55
+ -------
56
+
57
+ Copyright Itay Grudev (c) 2017.
58
+
59
+ This gem and all associated documentation is distributed under the terms of the
60
+ GNU GPL v3 license.
@@ -1,8 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- lib = File.expand_path( '../lib', __FILE__ )
4
- $LOAD_PATH.unshift( lib ) unless $LOAD_PATH.include?( lib )
5
-
6
3
  require 'capistrano/env_config/version'
7
4
 
8
5
  Gem::Specification.new do |spec|
@@ -11,12 +8,14 @@ Gem::Specification.new do |spec|
11
8
  spec.authors = [ 'Itay Grudev' ]
12
9
  spec.email = [ 'itay+capistrano-env_config+github.com[]grudev.com' ]
13
10
  spec.homepage = 'https://github.com/itay-grudev/capistrano-env_config'
11
+ spec.license = 'GPL-3.0'
14
12
  spec.summary = 'A tool for managing your environment variables across your cluster.'
15
- spec.description = <<-EOF
13
+ spec.description = <<-EOF.gsub(/^\s+/, '')
16
14
  EnvConfig is a tool for setting and syncing environment variables across
17
- your the servers in your cluster with a few simple Capistrano tasks.}
15
+ your the servers in your cluster with a few simple Capistrano tasks. The
16
+ library manipulates the system-wide environment variables by modifying the
17
+ `/etc/environment` file.
18
18
  EOF
19
- spec.license = 'GPL-3.0'
20
19
 
21
20
  spec.rubyforge_project = 'capistrano-env_config'
22
21
 
@@ -24,9 +23,9 @@ Gem::Specification.new do |spec|
24
23
  spec.require_paths = [ 'lib' ]
25
24
 
26
25
  spec.required_ruby_version = '>= 1.9.3'
27
- spec.add_dependency 'capistrano', '~> 3.1'
26
+
27
+ spec.add_dependency 'capistrano', '~> 3.7'
28
28
 
29
29
  spec.add_development_dependency 'rspec', '~> 3.6'
30
30
  spec.add_development_dependency 'simplecov', '~> 0.14'
31
- spec.add_development_dependency 'rake'
32
31
  end
@@ -1 +1,19 @@
1
- load File.expand_path( '../tasks/env_config.rake', __FILE__ )
1
+ require 'capistrano/plugin'
2
+
3
+ module Capistrano
4
+ class EnvConfig < Capistrano::Plugin
5
+
6
+ def define_tasks
7
+ eval_rakefile File.expand_path( '../tasks/env_config.rake', __FILE__ )
8
+ end
9
+
10
+ def set_defaults
11
+ set_if_empty :env_config_roles, :all
12
+ end
13
+ end
14
+ end
15
+
16
+ install_plugin Capistrano::EnvConfig
17
+
18
+ require 'capistrano/env_config/environment'
19
+ require 'capistrano/env_config/version'
@@ -1,57 +1,56 @@
1
1
  module Capistrano
2
- module EnvConfig
3
- class Environment
4
- class KeyNotSpecified < RuntimeError; end
5
-
6
- BLANK_RE = /\A[[:space:]]*\z/
7
-
8
- def initialize
9
- variables = { }
10
-
11
- # Acquire all configuration variables and store them in a dictionary (hash)
12
- on roles( :all ) do
13
- output = capture( 'cat /etc/environment' )
14
- output.each_line do |line|
15
- captures = line.match( /\s*([A-Z_][A-Z0-9_]*)=(.*)/ )
16
- if captures&.length == 3
17
- variables[ captures[1] ] = captures[2]
18
- end
2
+ class EnvConfig::Environment
3
+ class KeyNotSpecified < RuntimeError; end
4
+
5
+ BLANK_RE = /\A[[:space:]]*\z/
6
+
7
+ def initialize( roles = fetch( :env_config_roles ) )
8
+ variables = { }
9
+
10
+ # Acquire all configuration variables and store them in a dictionary (hash)
11
+ on roles( roles ) do
12
+ output = capture( 'cat /etc/environment' )
13
+ output.each_line do |line|
14
+ captures = line.match( /\s*([A-Z_][A-Z0-9_]*)=(.*)/ )
15
+ if captures&.length == 3
16
+ variables[ captures[1] ] = captures[2]
19
17
  end
20
18
  end
21
- @variables = variables
22
19
  end
23
20
 
24
- def get( key )
25
- raise KeyNotSpecified.new if BLANK_RE === key
26
- return @variables[ key.to_s.upcase ]
27
- end
21
+ @variables = variables
22
+ end
28
23
 
29
- def list
30
- @variables
31
- end
24
+ def get( key )
25
+ raise KeyNotSpecified.new if BLANK_RE === key
26
+ return @variables[ key.to_s.upcase ]
27
+ end
32
28
 
33
- def set( key, value )
34
- raise KeyNotSpecified.new if BLANK_RE === key
35
- @variables[ key.to_s.upcase ] = value.to_s
36
- end
29
+ def list
30
+ @variables
31
+ end
37
32
 
38
- def delete( key )
39
- raise KeyNotSpecified.new if BLANK_RE === key
40
- @variables.delete( key.to_s.upcase )
41
- end
33
+ def set( key, value )
34
+ raise KeyNotSpecified.new if BLANK_RE === key
35
+ @variables[ key.to_s.upcase ] = value.to_s
36
+ end
42
37
 
43
- def sync
44
- # Concatenate all variables and output them in the appropariate format
45
- environment = ''
46
- @variables.each do |key, value|
47
- environment += "#{key.upcase}=#{value}\n"
48
- end
38
+ def delete( key )
39
+ raise KeyNotSpecified.new if BLANK_RE === key
40
+ @variables.delete( key.to_s.upcase )
41
+ end
49
42
 
50
- # Upload the variables to all servers
51
- on roles( :all ) do
52
- contents = StringIO.new( environment, 'r' )
53
- upload! contents, '/etc/environment'
54
- end
43
+ def sync( roles = fetch( :env_config_roles ) )
44
+ # Concatenate all variables and output them in the appropariate format
45
+ environment = ''
46
+ @variables.each do |key, value|
47
+ environment += "#{key.upcase}=#{value}\n"
48
+ end
49
+
50
+ # Upload the variables to all servers
51
+ on roles( roles ) do
52
+ contents = StringIO.new( environment, 'r' )
53
+ upload! contents, '/etc/environment'
55
54
  end
56
55
  end
57
56
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
- module EnvConfig
3
- VERSION = '0.0.1'
2
+ class EnvConfig
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-env_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Itay Grudev
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: '3.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: '3.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,23 +52,11 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.14'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- description: |2
70
- EnvConfig is a tool for setting and syncing environment variables across
71
- your the servers in your cluster with a few simple Capistrano tasks.}
55
+ description: |
56
+ EnvConfig is a tool for setting and syncing environment variables across
57
+ your the servers in your cluster with a few simple Capistrano tasks. The
58
+ library manipulates the system-wide environment variables by modifying the
59
+ `/etc/environment` file.
72
60
  email:
73
61
  - itay+capistrano-env_config+github.com[]grudev.com
74
62
  executables: []
@@ -76,6 +64,7 @@ extensions: []
76
64
  extra_rdoc_files: []
77
65
  files:
78
66
  - ".gitignore"
67
+ - CHANGELOG.md
79
68
  - Gemfile
80
69
  - Gemfile.lock
81
70
  - LICENSE