Skip to content

Enable easier customization of production environments. - #2164

Closed
rwjblue wants to merge 1 commit into
ember-cli:masterfrom
rwjblue:allow-easier-custom-production-environments
Closed

rwjblue wants to merge 1 commit into
ember-cli:masterfrom
rwjblue:allow-easier-custom-production-environments

Conversation

@rwjblue

@rwjblue rwjblue commented Oct 2, 2014

Copy link
Copy Markdown
Member

The following is all that is needed to enable building staging as another production type environment:

var app = new EmberApp({
  productionEnvironments: [ 'production', 'staging' ]
});

```javascript
var app = new EmberApp({
  productionEnvironments: [ 'production', 'staging' ]
});
```
@stefanpenner

Copy link
Copy Markdown
Contributor

-1 lets not introduce another flag we will break soon aswe have plans (@domme's work) to improve this area

@rwjblue rwjblue mentioned this pull request Oct 2, 2014
@rwjblue

rwjblue commented Oct 2, 2014

Copy link
Copy Markdown
Member Author

Then ship the other thing. :trollface:

@rwjblue rwjblue closed this Oct 2, 2014
@rwjblue

rwjblue commented Oct 2, 2014

Copy link
Copy Markdown
Member Author

For those that need this the following works now, Stef wants you to feel pain:

var EmberApp = require('ember-cli/lib/broccoli/ember-app');

var isProductionLikeBuild = ['production', 'staging'].indexOf(process.env.EMBER_ENV) > -1;

var app = new EmberApp({
  wrapInEval: !isProductionLikeBuild,
  minifyCSS: {
    enabled: isProductionLikeBuild
  },
  minifyJS: {
    enabled: isProductionLikeBuild
  },
  tests: !isProductionLikeBuild,
  hinting: !isProductionLikeBuild,
  vendorFiles: {
    'handlebars.js': {
      staging:  'bower_components/handlebars/handlebars.runtime.js'
    },
    'ember.js': {
      staging:  'bower_components/ember/ember.prod.js'
    }
  }
});

@stefanpenner

Copy link
Copy Markdown
Contributor

stef has also provided a thoughtful proposal to get us out of this local min https://gist.github.com/rwjblue/51f1df4b21a23466ae47

@dschmidt has also started to implement #1520 and can likely use a hand.

@psrpinto

Copy link
Copy Markdown

In the workaround above,
wrapInEval: isProductionLikeBuild should be
wrapInEval: !isProductionLikeBuild

right? @rwjblue

EDIT:
Also, if you're fingerprinting assets, you have to enable it explicitly:

var app = new EmberApp({
  ...

  fingerprint: {
    enabled: isProductionLikeBuild
  }
});

@rwjblue

rwjblue commented Oct 17, 2014

Copy link
Copy Markdown
Member Author

@regularjack - Ooops, yes, updated (thanks for catching).

@devinus

devinus commented May 18, 2015

Copy link
Copy Markdown

@rwjblue Has this situation improved at all?

@stefanpenner

Copy link
Copy Markdown
Contributor

@devinus nope, we have not worked on the configuration story yet

@skylar

skylar commented Jul 7, 2015

Copy link
Copy Markdown

Ha, I just wrote something very similar to what @rwjblue wrote for my app. It might be worth updating the core docs under "environment" to make it clear that different environments aren't supported and that you should stick to the core dev/test/prod.

I very much like the idea of a set of config flags that could be imported/reused by other configurations. For example, we'd take a "production" config and modify it slightly for staging. Ping me if someone else is working on this currently and could use some help.

@KaiFuglem

Copy link
Copy Markdown

@skylar would you be able to share how you achieved this? I haven't been able to get the code above working for me. Thanks in advance!

@skylar

skylar commented Oct 17, 2015

Copy link
Copy Markdown

@KaiFuglem ha - yes, I forgot I had done this. In any case, I put my ember-cli-build.js in a just for you. let me know if that helps:

https://gist.github.com/skylar/e1ca3ea34dbca53d63ff

@devinus

devinus commented Oct 17, 2015

Copy link
Copy Markdown

Why couldn't we get something like this until this huge refactor lands?

@skylar

skylar commented Oct 17, 2015

Copy link
Copy Markdown

@devinus do you have a PR?

@devinus

devinus commented Oct 17, 2015

Copy link
Copy Markdown

@skylar We're on the PR.

@KaiFuglem

Copy link
Copy Markdown

Thanks @skylar! That worked for me, but for those still having issues implementing this, I also had to modify an app.import:

  app.import({
    development: 'xxx-debug.js',
    production: 'xxx.js',
    staging: 'xxx.js'
  });

@blimmer

blimmer commented Nov 18, 2015

Copy link
Copy Markdown
Contributor

I really would love to see some kind of support like @rwjblue mentioned way back at the start of this issue.

var app = new EmberApp({
  productionEnvironments: [ 'production', 'staging' ]
});

I've run into 3 subtle problems today that caused deployment headaches because of differences between my staging and production environments.

In my workflow, staging should be just like production so I can catch bugs before I deploy to prod. Since I use ember-cli-deploy-redis the new versions aren't activated until I explicitly say so, however it's really unsettling to test everything/accept stories on staging and then find (multiple) bugs in production caused by build differences.

I currently have 11 instances of flipping the switch based on isProductionLikeBuild in my ember-cli-build.js file, which is about 10 too many, IMO.

@stefanpenner

Copy link
Copy Markdown
Contributor

I would recommend, people stick to the 3 main envs, and use ENV vars (Accessible inside the builld and the config/environment.js to configure further.

This allows addons to understand the intent of a given ENV. I plan to also the concept of --target (ios/embedded/electron etc.etc.) the 3x3 matrix + ENV var channel should handle most cases. While allowing common addons/tooling to understand the intent.

Staging, would be production + different ENV vars specifying specific endpoints/domains etc)

@2468ben

2468ben commented Nov 18, 2015

Copy link
Copy Markdown

@blimmer I have/had the same pain point with ember-cli & ember-cli-deploy and was using the switches until I ran into a couple plugins that internally based things on env === 'production'. I recently moved over to some ENV vars similar to @stefanpenner's suggestion; here's some relevant bits of my files for how it works. But this way ember-cli only sees 'production', and ember-cli-deploy + app code gets production and staging env vars to work with.

It feels confusing to type out, but I'd be glad to talk on slack/wherever if you want more code or a better-thought-out explanation.

//.env.staging
EMBER_ENV=production
DEPLOY_ENV=staging
PRODUCTION_LIKE_BUILD=true


//config/deploy.js
require('dotenv').load();  //loads .env
require('dotenv').config({path: '.env.'+deployTarget});  //loads .env.staging
var ENV = {
    build: {
      environment: deployTarget  //returns 'staging' 
    }
}


// config/environment.js
var ENV = {
  ...
  environment: environment, //returns 'production'
  EmberENV: {
    PRODUCTION_LIKE_BUILD: process.env['PRODUCTION_LIKE_BUILD']  //returns true
    environment: process.env['DEPLOY_ENV']  //returns 'staging'
  }
}

@blimmer

blimmer commented May 18, 2016

Copy link
Copy Markdown
Contributor

@stefanpenner I ran into this again today with a bug report we should have caught in staging. are there any updates wrt this problem? should I submit an RFC to get more feedback? I would really like to help figure out a solution for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants