Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Move deployment support to separate gem #95

Merged
merged 5 commits into from

6 participants

Brandon Keepers Don Morrison \\ ٩( 'ω' )و // Mark Rebec Samuel Garneau Oscar Rendón
Brandon Keepers
Owner

Most pull requests to dotenv are to support different deployment scenarios. As I explained in #71, I'm not convinced that dotenv should even be used in production. But I also live in a fantasy land where I don't have to manage production environments. Either way, I'm not the right person to be maintaining features that I don't need or use.

So here's my proposal: move all deployment related stuff to dotenv-deployment. dotenv will remain a very small shim intended for development. Someone else can manage dotenv-deployment and let it evolve into whatever people need for managing production configuration.

I would love thoughts from people that don't live in my fantasy land. /cc @wfarr @jnewland @asenchi @garno @elskwid @markrebec @linyows

If this sounds like a good idea, then I would love help testing these changes.

gem 'dotenv', :groups => [:development, :test], :github => 'bkeepers/dotenv', :branch => 'deployment'
gem 'dotenv-deployment', :github => 'bkeepers/dotenv-deployment'

Once everything appears to be working, then I will:

  • Release 0.11.0 with a dependency on dotenv-deployment and deprecation warnings for moved features
  • Remove deprecation warnings and dependency and release 1.0

Closes #71

Don Morrison

@bkeepers: Nice work! The separation of the env manipulation from the deployment concern is great to see. Heck, the more focused README alone is worth the effort. (Full disclosure: I've stated before that I think this is a good idea. AND IT IS!)

The release plan with warnings of deprecations makes a lot of sense.

Good to see this happening.

Don Morrison elskwid commented on the diff
README.md
((5 lines not shown))
Storing [configuration in the environment](http://www.12factor.net/config) is one of the tenets of a [twelve-factor app](http://www.12factor.net/). Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.
-But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. Dotenv load variables from a `.env` file into `ENV` when the environment is bootstrapped.
+But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. dotenv loads variables from a `.env` file into `ENV` when the environment is bootstrapped.
+
+dotenv is intended to be used in development. If you would like to use it in production or other environments, see [dotenv-deployment](https://github.com/bkeepers/dotenv-deployment)
Don Morrison
elskwid added a note

A good signal that the line between the gems is in the right place. "You're here to load stuff into ENV but if you want to do something else go over there."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Don Morrison elskwid commented on the diff
README.md
@@ -84,29 +80,6 @@ Whenever your application loads, these variables will be available in `ENV`:
config.fog_directory = ENV['S3_BUCKET']
```
-## Capistrano integration
Don Morrison
elskwid added a note

:wave: :wave:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
\\ ٩( 'ω' )و //

LGTM

Mark Rebec

Love this idea! Separating this both gives a better base where we can continue to evolve any deployment stuff as new use cases and deployment tools come about, and it helps to discourage some of the "misuse" of Dotenv and to better inform the community of intended/recommended deployment integrations.

Samuel Garneau

Love this idea as well! :+1:

Brandon Keepers bkeepers merged commit 6bfd750 into from
Brandon Keepers bkeepers deleted the branch
Brandon Keepers bkeepers referenced this pull request
Merged

1.0.0 #106

Oscar Rendón

Since bundler require gems in order, this forces the user to put dotenv-deployment before dotenv-rails on the gemfile, otherwise it will show deprecation warning, even if dotenv-deployment is present (At least until #106 gets merged)

@bkeepers Let me know if you want me to update the docs or something, We're good anyway once 1.0.0 is released

Owner

Doh, good point. I should have tried to require dotenv/deployment first and rescued the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4 Gemfile
View
@@ -1,6 +1,8 @@
source 'https://rubygems.org'
gemspec :name => 'dotenv'
+gem 'dotenv-deployment', :github => 'bkeepers/dotenv-deployment'
+
group :guard do
gem 'guard-rspec'
gem 'guard-bundler'
@@ -9,4 +11,4 @@ end
platforms :rbx do
gem 'rubysl', '~> 2.0' # if using anything in the ruby standard library
-end
+end
37 README.md
View
@@ -1,10 +1,13 @@
# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.png?branch=master)](https://travis-ci.org/bkeepers/dotenv)
-Dotenv loads environment variables from `.env` into `ENV`.
+Shim to load environment variables from `.env` into `ENV` in *development*.
Storing [configuration in the environment](http://www.12factor.net/config) is one of the tenets of a [twelve-factor app](http://www.12factor.net/). Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.
-But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. Dotenv load variables from a `.env` file into `ENV` when the environment is bootstrapped.
+But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. dotenv loads variables from a `.env` file into `ENV` when the environment is bootstrapped.
+
+dotenv is intended to be used in development. If you would like to use it in production or other environments, see [dotenv-deployment](https://github.com/bkeepers/dotenv-deployment)
Don Morrison
elskwid added a note

A good signal that the line between the gems is in the right place. "You're here to load stuff into ENV but if you want to do something else go over there."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
## Installation
@@ -64,13 +67,6 @@ S3_BUCKET=YOURS3BUCKET
SECRET_KEY=YOURSECRETKEYGOESHERE
```
-You can also create files per environment, such as `.env.test`.
-
-```shell
-S3_BUCKET=tests3bucket
-SECRET_KEY=testsecretkey
-```
-
An alternate yaml-like syntax is supported:
```yaml
@@ -84,29 +80,6 @@ Whenever your application loads, these variables will be available in `ENV`:
config.fog_directory = ENV['S3_BUCKET']
```
-## Capistrano integration
Don Morrison
elskwid added a note

:wave: :wave:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
-
-If you want to use Dotenv with Capistrano in your production environment, make sure the dotenv gem is included in your Gemfile `:production` group.
-
-### Capistrano version 2.x.x
-
-Add the gem to your `config/deploy.rb` file:
-
-```ruby
-require "dotenv/capistrano"
-```
-
-It will symlink the `.env` located in `/path/to/shared` in the new release.
-
-
-### Capistrano version 3.x.x
-
-Just add `.env` to the list of linked files, for example:
-
-```ruby
-set :linked_files, %w{config/database.yml .env}
-```
-
## Should I commit my .env file?
It is recommended that you store development-only settings in your `.env` file, and commit it to your repository. Make sure that all your credentials for your development environment are different from your other deployments. This makes it easy for other developers to get started on your project, without compromising your credentials for other environments.
2  dotenv.gemspec
View
@@ -16,6 +16,8 @@ Gem::Specification.new do |gem|
gem.name = "dotenv"
gem.require_paths = ["lib"]
+ gem.add_dependency "dotenv-deployment", "0.0.1"
+
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
end
10 lib/dotenv-rails.rb
View
@@ -1 +1,11 @@
require 'dotenv/railtie'
+
+env_file = ".env.#{Rails.env}"
+if File.exists?(env_file) && !defined?(Dotenv::Deployment)
+ warn "Auto-loading of `#{env_file}` will be removed in 1.0. See " +
+ "https://github.com/bkeepers/dotenv-deployment if you would like to " +
+ "continue using this feature."
+ Dotenv.load ".env.#{Rails.env}"
+end
+
+Dotenv.load '.env'
15 lib/dotenv/capistrano.rb
View
@@ -1,11 +1,6 @@
-require 'capistrano/version'
+warn "Capistrano support has been moved to the dotenv-deployment gem. Add it " +
+ "to your Gemfile and change the require to 'dotenv/deployment/capistrano'. " +
+ "See https://github.com/bkeepers/dotenv-deployment#capistrano."
-if defined?(Capistrano::VERSION) && Capistrano::VERSION >= '3.0'
- raise 'Please read https://github.com/bkeepers/dotenv#capistrano-integration to update your dotenv configuration for new Capistrano version'
-else
- require 'dotenv/capistrano/recipes'
-
- Capistrano::Configuration.instance(:must_exist).load do
- before "deploy:finalize_update", "dotenv:symlink"
- end
-end
+# This will be removed in 1.0
+require 'dotenv/deployment/capistrano'
12 lib/dotenv/capistrano/recipes.rb
View
@@ -1,12 +0,0 @@
-Capistrano::Configuration.instance(:must_exist).load do
- _cset(:dotenv_path){ "#{shared_path}/.env" }
-
- symlink_args = (role = fetch(:dotenv_role, nil) ? {:roles => role} : {})
-
- namespace :dotenv do
- desc "Symlink shared .env to current release"
- task :symlink, symlink_args do
- run "ln -nfs #{dotenv_path} #{release_path}/.env"
- end
- end
-end
6 lib/dotenv/railtie.rb
View
@@ -3,12 +3,10 @@
module Dotenv
class Railtie < Rails::Railtie
rake_tasks do
- desc 'Load environment settings from .env'
task :dotenv do
- Dotenv.load ".env.#{Rails.env}", '.env'
+ # If the dotenv task is defined, then dotenv has already been loaded.
+ warn "The `dotenv` task is no longer needed and will be removed in 1.0."
end
end
end
end
-
-Dotenv.load ".env.#{Rails.env}", '.env'
Something went wrong with that request. Please try again.