From 93721db499f0db57658423c099f58e91bd59b7e0 Mon Sep 17 00:00:00 2001 From: Anil Date: Fri, 20 Nov 2015 14:48:18 +0530 Subject: [PATCH 1/2] Load environment variables using dotenv package --- lib/commands/base-command-factory.js | 1 + package.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/commands/base-command-factory.js b/lib/commands/base-command-factory.js index 5f0f5da..308efa5 100644 --- a/lib/commands/base-command-factory.js +++ b/lib/commands/base-command-factory.js @@ -3,6 +3,7 @@ var fs = require('fs'); var path = require('path'); var chalk = require('chalk'); +require('dotenv').load(); // Tried just exporting an object, but it was getting // mutated by each function that was _.extend'ing it. // I'm sure there's a way to export a POJO and not have diff --git a/package.json b/package.json index 2d32595..414150a 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "s3": "^4.3.1", "sync-exec": "^0.4.0", "underscore": "^1.7.0", - "silent-error": "^1.0.0" + "silent-error": "^1.0.0", + "dotenv": "^1.2.0" } } From 83e3e64eaf6c93bc9d06cf9cb38c3048e03d5d07 Mon Sep 17 00:00:00 2001 From: Anil Kumar Maurya Date: Fri, 20 Nov 2015 15:19:42 +0530 Subject: [PATCH 2/2] Update Readme to load keys from env variable --- README.md | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ff7e742..89ee764 100644 --- a/README.md +++ b/README.md @@ -43,13 +43,23 @@ You'll also need to setup a S3 bucket, and allow it to be accessed publicly. Ad #### Ember App Setup -In your App's `Brocfile.js`, you'll want to prepend your asset fingerprinting with your S3 Bucket URL: +In your App's `ember-cli-build.js`, you'll want to prepend your asset fingerprinting with your S3 Bucket URL: ```js +var env = process.env.EMBER_ENV; +var fingerprintOptions = { + enabled: true +}; +switch (env) { + case 'development': + fingerprintOptions.prepend = 'http://localhost:4200/'; + break; + case 'production': + fingerprintOptions.prepend = 'https://s3.amazonaws.com/MY-BUCKET-NAME/dist/'; + break; +} var app = new EmberApp({ - 'fingerprint': { - prepend: "https://s3.amazonaws.com/MY-BUCKET-NAME/dist/" - } + 'fingerprint': fingerprintOptions }); ``` @@ -76,8 +86,8 @@ TODO { "production": { "assets": { - "accessKeyId": "[your-id]", - "secretAccessKey": "[your-key]", + "accessKeyId": process.env.ACCESS_KEY_ID, + "secretAccessKey": process.env.SECRET_ACCESS_KEY, "bucket": "[your-s3-bucket]", "prefix": "[optional, dir on S3 to dump all assets]", "distPrefix": "[optional, dir on S3 to put `dist` in e.g. dist-{{SHA}}]" @@ -95,6 +105,19 @@ TODO } ``` +### Add .env file in root dir of project + +``` +ACCESS_KEY_ID=YOUR-ACCESS-KEY +SECRET_ACCESS_KEY=YOUR-SECRET-KEY +``` + +### Edit `.gitignore` + +``` +/.env +``` + ## Usage To deploy your application just run