fivetanley/ember-cli-dotenv

path option doesn't behave well with ember-cli-deploy's development workflow

Opened this issue · 9 comments

I am using this addon with ember-cli-deploy's development workflow. I have 3 different env files for different environments: .env.deploy.${env}.

Here's the config/dotenv.js contents:

/* eslint-env node */

module.exports = function(env) {
  return {
    clientAllowedKeys: [
      'API_HOST',
      'ASSET_HOST',
      'REDIS_URL',
      'SOCKET_URL',
      'S3_BUCKET_NAME',
      'AWS_REGION',
    ],
    path: `./.env.deploy.${env}`
  }
}

Running ember s works fine for the development environment but ember deploy staging and ember deploy production commands seem to not find the correct env file.

Changing the path variable from ./.env.deploy.${env} to ../.env.deploy.${env} does the trick.

Forgot to mention that this is the behavior in 2.0.0

On the master branch path: '../.env.deploy.${env}' fails with:
[ember-cli-dotenv]: ENOENT: no such file or directory, open '../.env.deploy.development'

xn commented

same

Any news?

Same. Updates @fivetanley?

it seems that env is not properly set when issuing ember deploy production a workaround is specified in this issue #46

this worked for me

/* eslint-env node */

'use strict';

const path = require('path');

module.exports = function(env) {
  // $ ember deploy production
  // [0] = node
  // [1] = ember
  // [2] command = deploy
  // [3] target = production
  const [,, command, target] = process.argv;

  if (command && target && command === 'deploy') {
    env = target;
  }

  const isProd = env == 'production';
  const isStaging = env == 'staging';
  const envFile = (isProd || isStaging) ? `.env.deploy.${env}` : '.env';

  return {
    clientAllowedKeys: [...],
    path: path.join(__dirname, '..', envFile)
  };
};

@sescobb27 where have you put this code?

@viniciussbs in config/dotenv.js

Thank you, @sescobb27. I'll give it a try.

jkeen commented

Here I am in 2020 and I had this same puzzling issue. Not sure why it happened in a new ember app but didn't in another one also running dotenv 3, but this was really puzzling and surprising.

The code above helped, but it needed a small modification to support other commands from ember-cli-deploy like ember deploy:list prod, etc etc

For future confused travelers to this thread or #46

// config/dotenv.js

'use strict';
const path = require('path');

module.exports = function(env) {
  // $ ember deploy production
  // [0] = node
  // [1] = ember
  // [2] command = deploy
  // [3] target = production
  const [,, command, target] = process.argv;

  if (command && target && (command === 'deploy' || command.indexOf("deploy:") == 0)) {
    env = target;
  }

  const isProd     = (env == 'production' || env == 'prod');
  const isStaging  = env == 'staging';
  const envFile    = (isProd || isStaging) ? `.env.deploy.${env}` : '.env';

  return {
    clientAllowedKeys: [...],
    path: path.join(__dirname, '..', envFile)
  };
};