capistrano-dotenv 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 11fe5a7213474a84d17cab3ae2adb6a6bd564b9a
4
+ data.tar.gz: 042e5d9f370e6f54e588e1501dcfc1dc6d519131
5
+ SHA512:
6
+ metadata.gz: 02719c7430315ce14de5db4669daafb5980497cfaa72189ad815abb7fcaeea45140f5f703539fe9bb66a4ad3a1bb86d11340517cfe26dfed431cd9f783659057
7
+ data.tar.gz: 863dbfcf1543797eec8bc954f1e4fb79b48aad2a1fd18ad393c25d29aee20da8decbf2e0e5a7253ccfd0630090fc82a0793182df21c39bee4cdbc4ca46af4b55
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-dotenv.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 João Paulo Lethier
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ [![Gem Version](https://img.shields.io/gem/v/capistrano-dotenv.svg)](https://rubygems.org/gems/capistrano-dotenv)
2
+ [![Dependencies](https://img.shields.io/gemnasium/jplethier/capistrano-dotenv.svg)](https://gemnasium.com/jplethier/capistrano-dotenv)
3
+ [![Code Climate](https://img.shields.io/codeclimate/github/jplethier/capistrano-dotenv.svg)](https://codeclimate.com/github/jplethier/capistrano-dotenv)
4
+
5
+
6
+ # Capistrano::Dotenv
7
+
8
+ Capitranos tasks to setup and check env vars using dotenv
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'capistrano-dotenv', require: false
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install capistrano-dotenv
25
+
26
+
27
+ ## Usage
28
+
29
+ You should ensure there is a `rails` binstub in the `current/bin` directory on the server otherwise
30
+ this gem won't work (because rails itself won't work).
31
+ If you experience any problems please verify that manually running `rails console` on the server does work.
32
+ If it doesn't you are deploying your rails application wrong (check [#18](https://github.com/ydkn/capistrano-rails-console/issues/18) or [#26](https://github.com/ydkn/capistrano-rails-console/issues/26) for details)!
33
+
34
+ Require in `Capfile`:
35
+
36
+ ```ruby
37
+ require 'capistrano/dotenv'
38
+ ```
39
+
40
+ TODO: adds examples how to use
41
+
42
+ ## Options
43
+
44
+ ### Env file
45
+
46
+ Use differents env files for each environment
47
+
48
+ ```ruby
49
+ set :env_file, ".env_#{stage}"
50
+ ```
51
+
52
+ Or use the same file for every environment(default)
53
+
54
+ ```ruby
55
+ set :env_file, '.env'
56
+ ```
57
+
58
+ ### Optional env vars
59
+
60
+ There are env vars that you want to set only in some enviroments or you will use a default value if it is not defined, so it is not required to be set a value for them. To be able to run check without fail the deployment if those env vars do not have a value set, just set it as optional
61
+
62
+ ```ruby
63
+ set :optional_env_vars, %w(OPTIONAL_VAR1 OPTIONAL_VAR2)
64
+ ```
65
+
66
+ ### Ignored env vars
67
+
68
+ There are project env vars needed only for test or development environment, so those vars need to be ignored when you are deploying the project
69
+
70
+ ```ruby
71
+ set :ignored_env_vars, %w(IGNORED_VAR1 IGNORED_VAR2)
72
+ ```
73
+
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jplethier/capistrano-dotenv.
78
+
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/dotenv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capistrano-dotenv'
8
+ spec.version = Capistrano::Dotenv::VERSION
9
+ spec.authors = ['João Paulo Lethier']
10
+ spec.email = ['jplethier@gmail.com']
11
+ spec.description = %q{Dotenv tasks for capistrano deployment}
12
+ spec.summary = %q{Dotenv tasks for capistrano deployment}
13
+ spec.homepage = 'https://github.com/jplethier/capistrano-dotenv'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'capistrano', '>= 3.5.0', '< 4.0.0'
22
+
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rake'
25
+ end
@@ -0,0 +1,34 @@
1
+ class EnvExtractor
2
+ def extensions
3
+ %w(ru thor rake rb yml ruby yaml erb builder markerb haml)
4
+ end
5
+
6
+ def extract_env_vars(globs = '*')
7
+ results = Hash.new { |hash, key| hash[key] = [] }
8
+
9
+ Array(globs).each do |glob|
10
+ Dir.glob(glob).each do |item|
11
+ next if File.basename(item)[0] == ?.
12
+
13
+ if File.directory?(item)
14
+ results.merge!(extract_env_vars("#{item}/*"))
15
+ else
16
+ next unless extensions.detect {|ext| File.extname(item)[ext] }
17
+ File.readlines(item).each_with_index do |line, ix|
18
+ capture_variables(line).each do |variable|
19
+ results[variable] << { :path => item, :line => ix.succ }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ results
27
+ end
28
+
29
+ private
30
+
31
+ def capture_variables(line)
32
+ line.scan(/ENV(?:\[|\.fetch\()['"]([^'"]+)['"]/).flatten
33
+ end
34
+ end
@@ -0,0 +1,68 @@
1
+ require 'env_extractor'
2
+
3
+ namespace :dotenv do
4
+ task :check do
5
+ env_vars = fetch(:env_vars)
6
+
7
+ OPTIONAL_VARS = fetch(:optional_env_vars, [])#%w(SEGMENT_KEY GTM_CODE RAILS_SERVE_STATIC_FILES ASSETS_VERSION)
8
+ IGNORED_VARS = fetch(:ignored_env_vars, [])#%w(BUNDLE_GEMFILE DB_REAPING_FREQUENCY CI CIRCLE_ARTIFACTS COVERAGE FB_SECRET)
9
+
10
+ missing_vars = []
11
+ optional_vars = []
12
+ EnvExtractor.extract_env_vars.each do |ocurrence|
13
+ next if env_vars.include?(ocurrence[0])
14
+ next if IGNORED_VARS.include?(ocurrence[0])
15
+
16
+ if OPTIONAL_VARS.include?(ocurrence[0])
17
+ optional_vars << ocurrence[0]
18
+ else
19
+ missing_vars << ocurrence[0]
20
+ end
21
+ end
22
+
23
+ fail "You must set a value for env vars:\n#{missing_vars.join("\n")}" if missing_vars.size > 0
24
+
25
+ if optional_vars.size > 0
26
+ puts "You have optional env vars that is not defined:\n#{optional_vars.join("\n")}"
27
+ ask(:continue, "Continue?(Yn)")
28
+ continue = fetch(:continue)
29
+
30
+ fail 'User abort for missing env vars value' if continue.downcase == 'n'
31
+ end
32
+ end
33
+
34
+ task :setup do
35
+ dotenv_contents = fetch(:dotenv_contents)
36
+
37
+ dotenv = StringIO.new
38
+ dotenv << dotenv_contents
39
+ dotenv.rewind
40
+
41
+ upload! dotenv, File.join(shared_path, '.env')
42
+ end
43
+
44
+ task :read do
45
+ env_file = fetch(:env_file, '.env')
46
+ dotenv_contents = ''
47
+
48
+ run_locally do
49
+ fail "You must have a #{env_file} file on your project " \
50
+ 'to be able to deploy it' unless File.exist?(env_file)
51
+
52
+ if env_file.match(/\.gpg$/)
53
+ dotenv_contents = `bundle exec dotgpg cat #{env_file}`
54
+ else
55
+ dotenv_contents = `cat #{env_file}`
56
+ end
57
+ end
58
+
59
+ set :env_vars, dotenv_contents.split("\n").map { |var| var.split('=')[0] }
60
+ set :dotenv_contents, dotenv_contents
61
+ end
62
+
63
+ task :config do
64
+ set :optional_vars, ENV.fetch('OPTIONAL_VARS', [])
65
+ set :ignored_vars, ENV.fetch('IGNORED_VARS', [])
66
+ set :extensions, -> { ENV.fetch('OPTIONAL_VARS', []) }
67
+ end
68
+ end
@@ -0,0 +1,8 @@
1
+ # Capistrano
2
+ module Capistrano
3
+ # Dotenv
4
+ module Dotenv
5
+ # Gem version
6
+ VERSION = '0.0.1'
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'capistrano/dotenv/version'
2
+
3
+ load File.expand_path('../dotenv/tasks.cap', __FILE__)
File without changes
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-dotenv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - João Paulo Lethier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.5.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 4.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.5.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 4.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
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
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ description: Dotenv tasks for capistrano deployment
62
+ email:
63
+ - jplethier@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - capistrano-dotenv.gemspec
73
+ - lib/capistrano-dotenv.rb
74
+ - lib/capistrano/dotenv.rb
75
+ - lib/capistrano/dotenv/env_extractor.rb
76
+ - lib/capistrano/dotenv/tasks.cap
77
+ - lib/capistrano/dotenv/version.rb
78
+ homepage: https://github.com/jplethier/capistrano-dotenv
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Dotenv tasks for capistrano deployment
102
+ test_files: []