├── app
└── .gitkeep
├── addon
└── .gitkeep
├── vendor
└── .gitkeep
├── tests
├── unit
│ └── .gitkeep
├── integration
│ └── .gitkeep
├── dummy
│ ├── app
│ │ ├── helpers
│ │ │ └── .gitkeep
│ │ ├── models
│ │ │ └── .gitkeep
│ │ ├── routes
│ │ │ └── .gitkeep
│ │ ├── styles
│ │ │ └── app.css
│ │ ├── components
│ │ │ └── .gitkeep
│ │ ├── controllers
│ │ │ └── .gitkeep
│ │ ├── templates
│ │ │ ├── components
│ │ │ │ └── .gitkeep
│ │ │ └── application.hbs
│ │ ├── router.js
│ │ ├── app.js
│ │ └── index.html
│ ├── public
│ │ ├── robots.txt
│ │ └── crossdomain.xml
│ └── config
│ │ └── environment.js
├── test-helper.js
├── helpers
│ ├── destroy-app.js
│ ├── resolver.js
│ ├── start-app.js
│ └── module-for-acceptance.js
├── .jshintrc
└── index.html
├── .watchmanconfig
├── .bowerrc
├── config
├── environment.js
└── ember-try.js
├── .npmignore
├── lib
├── md5-hash.js
├── aws
│ ├── cloud-formation.js
│ └── elastic-beanstalk.js
├── commands
│ └── provision.js
└── elastic-beanstalk-deploy-plugin.js
├── testem.json
├── .ember-cli
├── .gitignore
├── bower.json
├── index.js
├── ember-cli-build.js
├── .jshintrc
├── .editorconfig
├── .travis.yml
├── LICENSE.md
├── package.json
├── README.md
└── assets
└── cloud-formation-template.json
/app/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/addon/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/vendor/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/unit/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/integration/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/helpers/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/models/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/routes/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/styles/app.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/components/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/controllers/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/templates/components/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {
2 | "ignore_dirs": ["tmp", "dist"]
3 | }
4 |
--------------------------------------------------------------------------------
/.bowerrc:
--------------------------------------------------------------------------------
1 | {
2 | "directory": "bower_components",
3 | "analytics": false
4 | }
5 |
--------------------------------------------------------------------------------
/tests/dummy/public/robots.txt:
--------------------------------------------------------------------------------
1 | # http://www.robotstxt.org
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/tests/dummy/app/templates/application.hbs:
--------------------------------------------------------------------------------
1 |
Welcome to Ember
2 |
3 | {{outlet}}
4 |
--------------------------------------------------------------------------------
/config/environment.js:
--------------------------------------------------------------------------------
1 | /*jshint node:true*/
2 | 'use strict';
3 |
4 | module.exports = function(/* environment, appConfig */) {
5 | return { };
6 | };
7 |
--------------------------------------------------------------------------------
/tests/test-helper.js:
--------------------------------------------------------------------------------
1 | import resolver from './helpers/resolver';
2 | import {
3 | setResolver
4 | } from 'ember-qunit';
5 |
6 | setResolver(resolver);
7 |
--------------------------------------------------------------------------------
/tests/helpers/destroy-app.js:
--------------------------------------------------------------------------------
1 | import Ember from 'ember';
2 |
3 | export default function destroyApp(application) {
4 | Ember.run(application, 'destroy');
5 | }
6 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | bower_components/
2 | tests/
3 | tmp/
4 | dist/
5 |
6 | .bowerrc
7 | .editorconfig
8 | .ember-cli
9 | .travis.yml
10 | .npmignore
11 | **/.gitkeep
12 | bower.json
13 | Brocfile.js
14 | testem.json
15 |
--------------------------------------------------------------------------------
/lib/md5-hash.js:
--------------------------------------------------------------------------------
1 | /*jshint node: true*/
2 | var crypto = require('crypto');
3 |
4 | module.exports = function md5Hash(buf) {
5 | var md5 = crypto.createHash('md5');
6 | md5.update(buf);
7 | return md5.digest('hex');
8 | };
9 |
--------------------------------------------------------------------------------
/testem.json:
--------------------------------------------------------------------------------
1 | {
2 | "framework": "qunit",
3 | "test_page": "tests/index.html?hidepassed",
4 | "disable_watching": true,
5 | "launch_in_ci": [
6 | "PhantomJS"
7 | ],
8 | "launch_in_dev": [
9 | "PhantomJS",
10 | "Chrome"
11 | ]
12 | }
13 |
--------------------------------------------------------------------------------
/tests/dummy/app/router.js:
--------------------------------------------------------------------------------
1 | import Ember from 'ember';
2 | import config from './config/environment';
3 |
4 | const Router = Ember.Router.extend({
5 | location: config.locationType
6 | });
7 |
8 | Router.map(function() {
9 | });
10 |
11 | export default Router;
12 |
--------------------------------------------------------------------------------
/.ember-cli:
--------------------------------------------------------------------------------
1 | {
2 | /**
3 | Ember CLI sends analytics information by default. The data is completely
4 | anonymous, but there are times when you might want to disable this behavior.
5 |
6 | Setting `disableAnalytics` to true will prevent any data from being sent.
7 | */
8 | "disableAnalytics": false
9 | }
10 |
--------------------------------------------------------------------------------
/tests/helpers/resolver.js:
--------------------------------------------------------------------------------
1 | import Resolver from 'ember/resolver';
2 | import config from '../../config/environment';
3 |
4 | const resolver = Resolver.create();
5 |
6 | resolver.namespace = {
7 | modulePrefix: config.modulePrefix,
8 | podModulePrefix: config.podModulePrefix
9 | };
10 |
11 | export default resolver;
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 |
7 | # dependencies
8 | /node_modules
9 | /bower_components
10 |
11 | # misc
12 | /.sass-cache
13 | /connect.lock
14 | /coverage/*
15 | /libpeerconnection.log
16 | npm-debug.log
17 | testem.log
18 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ember-cli-deploy-elastic-beanstalk",
3 | "dependencies": {
4 | "ember": "1.13.11",
5 | "ember-cli-shims": "0.0.6",
6 | "ember-cli-test-loader": "0.2.1",
7 | "ember-data": "1.13.15",
8 | "ember-load-initializers": "0.1.7",
9 | "ember-qunit": "0.4.16",
10 | "ember-qunit-notifications": "0.1.0",
11 | "ember-resolver": "~0.1.20",
12 | "jquery": "^1.11.3",
13 | "loader.js": "ember-cli/loader.js#3.4.0",
14 | "qunit": "~1.20.0"
15 | }
16 | }
--------------------------------------------------------------------------------
/tests/dummy/app/app.js:
--------------------------------------------------------------------------------
1 | import Ember from 'ember';
2 | import Resolver from 'ember/resolver';
3 | import loadInitializers from 'ember/load-initializers';
4 | import config from './config/environment';
5 |
6 | let App;
7 |
8 | Ember.MODEL_FACTORY_INJECTIONS = true;
9 |
10 | App = Ember.Application.extend({
11 | modulePrefix: config.modulePrefix,
12 | podModulePrefix: config.podModulePrefix,
13 | Resolver
14 | });
15 |
16 | loadInitializers(App, config.modulePrefix);
17 |
18 | export default App;
19 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /* jshint node: true */
2 | 'use strict';
3 |
4 | var ElasticBeanstalkDeployPlugin = require('./lib/elastic-beanstalk-deploy-plugin');
5 | var ProvisionCommand = require('./lib/commands/provision');
6 |
7 | module.exports = {
8 | name: 'ember-cli-deploy-elastic-beanstalk',
9 |
10 | includedCommands: function() {
11 | return { 'eb:provision': ProvisionCommand };
12 | },
13 |
14 | createDeployPlugin: function(options) {
15 | return new ElasticBeanstalkDeployPlugin({
16 | name: options.name
17 | });
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/tests/helpers/start-app.js:
--------------------------------------------------------------------------------
1 | import Ember from 'ember';
2 | import Application from '../../app';
3 | import config from '../../config/environment';
4 |
5 | export default function startApp(attrs) {
6 | let application;
7 |
8 | let attributes = Ember.merge({}, config.APP);
9 | attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
10 |
11 | Ember.run(() => {
12 | application = Application.create(attributes);
13 | application.setupForTesting();
14 | application.injectTestHelpers();
15 | });
16 |
17 | return application;
18 | }
19 |
--------------------------------------------------------------------------------
/ember-cli-build.js:
--------------------------------------------------------------------------------
1 | /*jshint node:true*/
2 | /* global require, module */
3 | var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
4 |
5 | module.exports = function(defaults) {
6 | var app = new EmberAddon(defaults, {
7 | // Add options here
8 | });
9 |
10 | /*
11 | This build file specifes the options for the dummy test app of this
12 | addon, located in `/tests/dummy`
13 | This build file does *not* influence how the addon or the app using it
14 | behave. You most likely want to be modifying `./index.js` or app's build file
15 | */
16 |
17 | return app.toTree();
18 | };
19 |
--------------------------------------------------------------------------------
/tests/helpers/module-for-acceptance.js:
--------------------------------------------------------------------------------
1 | import { module } from 'qunit';
2 | import startApp from '../helpers/start-app';
3 | import destroyApp from '../helpers/destroy-app';
4 |
5 | export default function(name, options = {}) {
6 | module(name, {
7 | beforeEach() {
8 | this.application = startApp();
9 |
10 | if (options.beforeEach) {
11 | options.beforeEach.apply(this, arguments);
12 | }
13 | },
14 |
15 | afterEach() {
16 | destroyApp(this.application);
17 |
18 | if (options.afterEach) {
19 | options.afterEach.apply(this, arguments);
20 | }
21 | }
22 | });
23 | }
24 |
--------------------------------------------------------------------------------
/tests/dummy/public/crossdomain.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "predef": [
3 | "document",
4 | "window",
5 | "-Promise"
6 | ],
7 | "browser": true,
8 | "boss": true,
9 | "curly": true,
10 | "debug": false,
11 | "devel": true,
12 | "eqeqeq": true,
13 | "evil": true,
14 | "forin": false,
15 | "immed": false,
16 | "laxbreak": false,
17 | "newcap": true,
18 | "noarg": true,
19 | "node": true,
20 | "noempty": false,
21 | "nonew": false,
22 | "nomen": false,
23 | "onevar": false,
24 | "plusplus": false,
25 | "regexp": false,
26 | "undef": true,
27 | "sub": true,
28 | "strict": false,
29 | "white": false,
30 | "eqnull": true,
31 | "esnext": true,
32 | "unused": true
33 | }
34 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 |
8 | [*]
9 | end_of_line = lf
10 | charset = utf-8
11 | trim_trailing_whitespace = true
12 | insert_final_newline = true
13 | indent_style = space
14 | indent_size = 2
15 |
16 | [*.js]
17 | indent_style = space
18 | indent_size = 2
19 |
20 | [*.hbs]
21 | insert_final_newline = false
22 | indent_style = space
23 | indent_size = 2
24 |
25 | [*.css]
26 | indent_style = space
27 | indent_size = 2
28 |
29 | [*.html]
30 | indent_style = space
31 | indent_size = 2
32 |
33 | [*.{diff,md}]
34 | trim_trailing_whitespace = false
35 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | ---
2 | language: node_js
3 | node_js:
4 | - "0.12"
5 |
6 | sudo: false
7 |
8 | cache:
9 | directories:
10 | - node_modules
11 |
12 | env:
13 | - EMBER_TRY_SCENARIO=default
14 | - EMBER_TRY_SCENARIO=ember-release
15 | - EMBER_TRY_SCENARIO=ember-beta
16 | - EMBER_TRY_SCENARIO=ember-canary
17 |
18 | matrix:
19 | fast_finish: true
20 | allow_failures:
21 | - env: EMBER_TRY_SCENARIO=ember-canary
22 |
23 | before_install:
24 | - export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
25 | - "npm config set spin false"
26 | - "npm install -g npm@^2"
27 |
28 | install:
29 | - npm install -g bower
30 | - npm install
31 | - bower install
32 |
33 | script:
34 | - ember try $EMBER_TRY_SCENARIO test
35 |
--------------------------------------------------------------------------------
/tests/dummy/app/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Dummy
7 |
8 |
9 |
10 | {{content-for 'head'}}
11 |
12 |
13 |
14 |
15 | {{content-for 'head-footer'}}
16 |
17 |
18 | {{content-for 'body'}}
19 |
20 |
21 |
22 |
23 | {{content-for 'body-footer'}}
24 |
25 |
26 |
--------------------------------------------------------------------------------
/config/ember-try.js:
--------------------------------------------------------------------------------
1 | /*jshint node:true*/
2 | module.exports = {
3 | scenarios: [
4 | {
5 | name: 'default',
6 | dependencies: { }
7 | },
8 | {
9 | name: 'ember-release',
10 | dependencies: {
11 | 'ember': 'components/ember#release'
12 | },
13 | resolutions: {
14 | 'ember': 'release'
15 | }
16 | },
17 | {
18 | name: 'ember-beta',
19 | dependencies: {
20 | 'ember': 'components/ember#beta'
21 | },
22 | resolutions: {
23 | 'ember': 'beta'
24 | }
25 | },
26 | {
27 | name: 'ember-canary',
28 | dependencies: {
29 | 'ember': 'components/ember#canary'
30 | },
31 | resolutions: {
32 | 'ember': 'canary'
33 | }
34 | }
35 | ]
36 | };
37 |
--------------------------------------------------------------------------------
/tests/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "predef": [
3 | "document",
4 | "window",
5 | "location",
6 | "setTimeout",
7 | "$",
8 | "-Promise",
9 | "define",
10 | "console",
11 | "visit",
12 | "exists",
13 | "fillIn",
14 | "click",
15 | "keyEvent",
16 | "triggerEvent",
17 | "find",
18 | "findWithAssert",
19 | "wait",
20 | "DS",
21 | "andThen",
22 | "currentURL",
23 | "currentPath",
24 | "currentRouteName"
25 | ],
26 | "node": false,
27 | "browser": false,
28 | "boss": true,
29 | "curly": true,
30 | "debug": false,
31 | "devel": false,
32 | "eqeqeq": true,
33 | "evil": true,
34 | "forin": false,
35 | "immed": false,
36 | "laxbreak": false,
37 | "newcap": true,
38 | "noarg": true,
39 | "noempty": false,
40 | "nonew": false,
41 | "nomen": false,
42 | "onevar": false,
43 | "plusplus": false,
44 | "regexp": false,
45 | "undef": true,
46 | "sub": true,
47 | "strict": false,
48 | "white": false,
49 | "eqnull": true,
50 | "esnext": true,
51 | "unused": true
52 | }
53 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/tests/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Dummy Tests
7 |
8 |
9 |
10 | {{content-for 'head'}}
11 | {{content-for 'test-head'}}
12 |
13 |
14 |
15 |
16 |
17 | {{content-for 'head-footer'}}
18 | {{content-for 'test-head-footer'}}
19 |
20 |
21 | {{content-for 'body'}}
22 | {{content-for 'test-body'}}
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | {{content-for 'body-footer'}}
32 | {{content-for 'test-body-footer'}}
33 |
34 |
35 |
--------------------------------------------------------------------------------
/tests/dummy/config/environment.js:
--------------------------------------------------------------------------------
1 | /* jshint node: true */
2 |
3 | module.exports = function(environment) {
4 | var ENV = {
5 | modulePrefix: 'dummy',
6 | environment: environment,
7 | baseURL: '/',
8 | locationType: 'auto',
9 | EmberENV: {
10 | FEATURES: {
11 | // Here you can enable experimental features on an ember canary build
12 | // e.g. 'with-controller': true
13 | }
14 | },
15 |
16 | APP: {
17 | // Here you can pass flags/options to your application instance
18 | // when it is created
19 | }
20 | };
21 |
22 | if (environment === 'development') {
23 | // ENV.APP.LOG_RESOLVER = true;
24 | // ENV.APP.LOG_ACTIVE_GENERATION = true;
25 | // ENV.APP.LOG_TRANSITIONS = true;
26 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
27 | // ENV.APP.LOG_VIEW_LOOKUPS = true;
28 | }
29 |
30 | if (environment === 'test') {
31 | // Testem prefers this...
32 | ENV.baseURL = '/';
33 | ENV.locationType = 'none';
34 |
35 | // keep test console output quieter
36 | ENV.APP.LOG_ACTIVE_GENERATION = false;
37 | ENV.APP.LOG_VIEW_LOOKUPS = false;
38 |
39 | ENV.APP.rootElement = '#ember-testing';
40 | }
41 |
42 | if (environment === 'production') {
43 |
44 | }
45 |
46 | return ENV;
47 | };
48 |
--------------------------------------------------------------------------------
/lib/aws/cloud-formation.js:
--------------------------------------------------------------------------------
1 | var AWS = require('aws-sdk');
2 | var RSVP = require('rsvp');
3 | var awscred = require('awscred');
4 | var loadRegion = RSVP.denodeify(awscred.loadRegion.bind(awscred));
5 |
6 | function CloudFormation() {
7 | this.cf = new AWS.CloudFormation({
8 | apiVersion: '2010-05-15',
9 | region: 'us-east-1'
10 | });
11 | }
12 |
13 | CloudFormation.prototype.createStack = function(options) {
14 | var params = {
15 | StackName: options.stackName,
16 | Capabilities: [
17 | 'CAPABILITY_IAM',
18 | ],
19 | OnFailure: 'DELETE',
20 | Parameters: [
21 | {
22 | ParameterKey: 'FastBootApplication',
23 | ParameterValue: options.applicationName,
24 | }, {
25 | ParameterKey: 'FastBootEnvironmentName',
26 | ParameterValue: options.environmentName
27 | }
28 |
29 | ],
30 | TemplateBody: JSON.stringify(options.template)
31 | };
32 |
33 | return this.performAction('createStack', params)
34 | .then(function(data) {
35 | return data.StackId;
36 | });
37 | };
38 |
39 | CloudFormation.prototype.describeStack = function(stackID) {
40 | return this.performAction('describeStacks', {
41 | StackName: stackID
42 | });
43 | };
44 |
45 | CloudFormation.prototype.performAction = function(actionName, params) {
46 | var cf = this.cf;
47 | var action = RSVP.denodeify(cf[actionName].bind(cf));
48 |
49 | return this.loadRegion()
50 | .then(function() {
51 | return action(params);
52 | });
53 | };
54 |
55 | CloudFormation.prototype.loadRegion = function() {
56 | if (!this._regionPromise) {
57 | var cf = this.cf;
58 | this._regionPromise = loadRegion()
59 | .then(function(region) {
60 | cf.config.region = region;
61 | });
62 | }
63 |
64 | return this._regionPromise;
65 | };
66 |
67 | module.exports = CloudFormation;
68 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ember-cli-deploy-elastic-beanstalk",
3 | "version": "0.3.0",
4 | "description": "An ember-cli-deploy plugin for deploying to AWS Elastic Beanstalk running FastBoot",
5 | "directories": {
6 | "doc": "doc",
7 | "test": "tests"
8 | },
9 | "scripts": {
10 | "build": "ember build",
11 | "start": "ember server",
12 | "test": "ember try:testall"
13 | },
14 | "repository": "https://github.com/tomdale/ember-cli-deploy-elastic-beanstalk",
15 | "engines": {
16 | "node": ">= 0.10.0"
17 | },
18 | "author": "Tom Dale ",
19 | "license": "MIT",
20 | "devDependencies": {
21 | "broccoli-asset-rev": "^2.2.0",
22 | "ember-cli": "1.13.13",
23 | "ember-cli-app-version": "^1.0.0",
24 | "ember-cli-content-security-policy": "0.4.0",
25 | "ember-cli-dependency-checker": "^1.1.0",
26 | "ember-cli-htmlbars": "^1.0.1",
27 | "ember-cli-htmlbars-inline-precompile": "^0.3.1",
28 | "ember-cli-ic-ajax": "0.2.4",
29 | "ember-cli-inject-live-reload": "^1.3.1",
30 | "ember-cli-qunit": "^1.0.4",
31 | "ember-cli-release": "0.2.8",
32 | "ember-cli-sri": "^1.2.0",
33 | "ember-cli-uglify": "^1.2.0",
34 | "ember-data": "1.13.15",
35 | "ember-disable-proxy-controllers": "^1.0.1",
36 | "ember-export-application-global": "^1.0.4",
37 | "ember-disable-prototype-extensions": "^1.0.0",
38 | "ember-try": "~0.0.8"
39 | },
40 | "keywords": [
41 | "ember-addon",
42 | "ember-cli-deploy-plugin"
43 | ],
44 | "dependencies": {
45 | "aws-sdk": "^2.2.26",
46 | "awscred": "^1.1.0",
47 | "chalk": "^1.1.1",
48 | "ember-cli-babel": "^5.1.5",
49 | "ember-cli-deploy-plugin": "^0.2.0",
50 | "fs-promise": "^0.3.1",
51 | "glob": "^6.0.1",
52 | "inquirer": "^0.11.0",
53 | "rsvp": "^3.1.0"
54 | },
55 | "ember-addon": {
56 | "configPath": "tests/dummy/config"
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/lib/aws/elastic-beanstalk.js:
--------------------------------------------------------------------------------
1 | var AWS = require('aws-sdk');
2 | var RSVP = require('rsvp');
3 | var awscred = require('awscred');
4 | var loadRegion = RSVP.denodeify(awscred.loadRegion.bind(awscred));
5 |
6 | function ElasticBeanstalk() {
7 | this.eb = new AWS.ElasticBeanstalk({
8 | apiVersion: '2010-12-01',
9 | region: 'us-east-1'
10 | });
11 | }
12 |
13 | ElasticBeanstalk.prototype.describeApplications = function() {
14 | return this.performAction('describeApplications')
15 | .then(function(apps) {
16 | return apps ? apps.Applications : [];
17 | });
18 | };
19 |
20 | ElasticBeanstalk.prototype.describeEnvironment = function(appName, envName) {
21 | return this.performAction('describeEnvironments', {
22 | ApplicationName: appName,
23 | EnvironmentNames: [envName]
24 | })
25 | .then(function(data) {
26 | return data.Environments[0];
27 | });
28 | };
29 |
30 | ElasticBeanstalk.prototype.createApplication = function(appName) {
31 | return this.performAction('createApplication', {
32 | ApplicationName: appName
33 | })
34 | .then(function(data) {
35 | return data.Application;
36 | });
37 | };
38 |
39 | ElasticBeanstalk.prototype.createEnvironment = function(options) {
40 | var appName = options.applicationName;
41 | var environmentName = options.environmentName;
42 | var versionLabel = options.versionLabel;
43 |
44 | return this.performAction('createEnvironment', {
45 | ApplicationName: appName,
46 | EnvironmentName: environmentName,
47 | VersionLabel: versionLabel,
48 | SolutionStackName: "64bit Amazon Linux 2015.09 v2.0.5 running Node.js"
49 | });
50 | };
51 |
52 | ElasticBeanstalk.prototype.createApplicationVersion = function(appName) {
53 | var versionLabel = appName + Date.now();
54 |
55 | return this.performAction('createApplicationVersion', {
56 | ApplicationName: appName,
57 | VersionLabel: versionLabel,
58 | AutoCreateApplication: false,
59 | SourceBundle: {
60 | S3Bucket: 'ember-fastboot-elastic-beanstalk',
61 | S3Key: 'latest.zip'
62 | }
63 | })
64 | .then(function() {
65 | return versionLabel;
66 | });
67 | };
68 |
69 | ElasticBeanstalk.prototype.updateEnvironment = function(applicationName, environmentName, env) {
70 | var params = {
71 | ApplicationName: applicationName,
72 | EnvironmentName: environmentName,
73 | OptionSettings: buildEBEnv(env)
74 | };
75 |
76 | return this.performAction('updateEnvironment', params);
77 | };
78 |
79 | ElasticBeanstalk.prototype.loadRegion = function() {
80 | if (!this._regionPromise) {
81 | var eb = this.eb;
82 | this._regionPromise = loadRegion()
83 | .then(function(region) {
84 | eb.config.region = region;
85 | });
86 | }
87 |
88 | return this._regionPromise;
89 | };
90 |
91 | ElasticBeanstalk.prototype.performAction = function(actionName, params) {
92 | var eb = this.eb;
93 | var action = RSVP.denodeify(eb[actionName].bind(eb));
94 |
95 | return this.loadRegion()
96 | .then(function() {
97 | return action(params);
98 | });
99 | };
100 |
101 | function buildEBEnv(hash) {
102 | var env = [];
103 |
104 | for (var key in hash) {
105 | env.push({
106 | Namespace: 'aws:elasticbeanstalk:application:environment',
107 | OptionName: key,
108 | Value: hash[key]
109 | });
110 | }
111 |
112 | return env;
113 | }
114 |
115 | module.exports = ElasticBeanstalk;
116 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ember-cli-deploy-elastic-beanstalk
2 |
3 | An ember-cli-deploy plugin for deploying an Ember app to AWS Elastic Beanstalk running
4 | FastBoot. Designed to be used in tandem with
5 | [ember-fastboot-elastic-beanstalk][ember-fastboot-elastic-beanstalk].
6 |
7 | [ember-fastboot-elastic-beanstalk]: https://github.com/tomdale/ember-fastboot-elastic-beanstalk
8 |
9 | This plugin builds your application for FastBoot server-side rendering,
10 | then uploads a zip of the build to Amazon S3.
11 |
12 | ## What is an ember-cli-deploy plugin?
13 |
14 | A plugin is an addon that can be executed as a part of the ember-cli-deploy pipeline. A plugin will implement one or more of the ember-cli-deploy's pipeline hooks.
15 |
16 | For more information on what plugins are and how they work, please refer to the [Plugin Documentation][plugin-documentation].
17 |
18 | [plugin-documentation]: http://ember-cli.github.io/ember-cli-deploy/plugins
19 |
20 | ## Quick Start
21 |
22 | To get up and running quickly, do the following:
23 |
24 | - Configure your ember-cli-deploy pipeline for deploying to a CDN as
25 | usual. I recommend [ember-cli-deploy-s3][ember-cli-deploy-s3] with
26 | CloudFront.
27 | - Install this plugin
28 |
29 | [ember-cli-deploy-s3]: https://github.com/ember-cli-deploy/ember-cli-deploy-s3
30 |
31 | ```bash
32 | $ ember install ember-cli-deploy-elastic-beanstalk
33 | ```
34 |
35 | - Place the following configuration into `config/deploy.js`
36 |
37 | ```javascript
38 | ENV['elastic-beanstalk'] = {
39 | bucket: ''
40 | }
41 | ```
42 |
43 | - Run the pipeline
44 |
45 | ```bash
46 | $ ember deploy
47 | ```
48 |
49 | ## Installation
50 |
51 | Run the following command in your terminal:
52 |
53 | ```bash
54 | ember install ember-cli-deploy-elastic-beanstalk
55 | ```
56 |
57 | ## A Note on AWS Permissions
58 |
59 | This plugin relies on the official AWS SDK to perform uploads to S3. As
60 | such, it will inherit any credentials you have saved by running `aws
61 | configure` via the [AWS CLI][aws-cli].
62 |
63 | [aws-cli]: https://aws.amazon.com/cli/
64 |
65 | For managing multiple credentials, I recommend using the
66 | officially-supported profiles feature of AWS.
67 |
68 | To create a new profile, make sure you've installed the AWS CLI and then
69 | run:
70 |
71 | ```bash
72 | aws configure --profile acme-corp
73 | ```
74 |
75 | Enter your access key, secret key and other information requested. Once
76 | done, this will create a profile called `acme-corp`.
77 |
78 | To do a deploy with this saved credential profile, invoke the command
79 | with the `AWS_PROFILE` environment variable set:
80 |
81 | ```bash
82 | AWS_PROFILE=acme-corp ember deploy
83 | ```
84 |
85 | ## ember-cli-deploy Hooks Implemented
86 |
87 | For detailed information on what plugin hooks are and how they work, please refer to the [Plugin Documentation][1].
88 |
89 | - `build`
90 | - `didBuild`
91 | - `willUpload`
92 | - `upload`
93 |
94 | ## Configuration Options
95 |
96 | For detailed information on how configuration of plugins works, please
97 | refer to the [Plugin Documentation][plugin-documentation].
98 |
99 | ### bucket (`required`)
100 |
101 | The AWS bucket that the FastBoot build will be uploaded to.
102 |
103 | *Default:* `undefined`
104 |
105 | ### environment
106 |
107 | The environment target for the FastBoot build. Can be one of
108 | `"development"` or `"production"`.
109 |
110 | *Default:* `production`
111 |
112 | ### outputPath
113 |
114 | The path to the directory you'd like the FastBoot build to be built in to.
115 |
116 | *Default:* `tmp/fastboot-dist`
117 |
118 | ### zipPath
119 |
120 | The path to the zip file that should be created from the `outputPath`.
121 |
122 | *Default:* `tmp/fastboot-dist.zip`
123 |
124 | ## Thanks
125 |
126 | A big thank you to [Luke Melia](https://github.com/lukemelia) for
127 | helping me refactor my deploy script into an ember-cli-deploy plugin and
128 | to the entire ember-cli-deploy core team for answering my many
129 | questions.
130 |
--------------------------------------------------------------------------------
/assets/cloud-formation-template.json:
--------------------------------------------------------------------------------
1 | {
2 | "AWSTemplateFormatVersion": "2010-09-09",
3 |
4 | "Mappings" : {
5 | "Region2Principal" : {
6 | "us-east-1" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
7 | "us-west-2" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
8 | "us-west-1" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
9 | "eu-west-1" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
10 | "ap-southeast-1" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
11 | "ap-northeast-1" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
12 | "ap-northeast-2" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
13 | "ap-southeast-2" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
14 | "sa-east-1" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
15 | "cn-north-1" : { "EC2Principal" : "ec2.amazonaws.com.cn", "OpsWorksPrincipal" : "opsworks.amazonaws.com.cn" },
16 | "eu-central-1" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" }
17 | }
18 |
19 | },
20 |
21 | "Parameters": {
22 | "FastBootApplication": {
23 | "Type": "String"
24 | },
25 |
26 | "FastBootEnvironmentName": {
27 | "Type": "String"
28 | }
29 | },
30 |
31 | "Resources": {
32 | "FastBootBucket": {
33 | "Type": "AWS::S3::Bucket"
34 | },
35 |
36 | "FastBootServerRole": {
37 | "Type": "AWS::IAM::Role",
38 | "Properties" : {
39 | "AssumeRolePolicyDocument" : {
40 | "Statement" : [{
41 | "Effect" : "Allow",
42 | "Principal": { "Service": [{ "Fn::FindInMap" : ["Region2Principal", {"Ref" : "AWS::Region"}, "EC2Principal"]}] },
43 | "Action" : [ "sts:AssumeRole" ]
44 | } ]
45 | },
46 | "Path": "/"
47 | }
48 | },
49 |
50 | "FastBootServerRolePolicy": {
51 | "Type": "AWS::IAM::Policy",
52 | "Properties": {
53 | "PolicyName" : "FastBootServerRole",
54 | "PolicyDocument" : {
55 | "Statement": [{
56 | "Effect": "Allow",
57 | "Action": [
58 | "s3:GetObject"
59 | ],
60 | "Resource": { "Fn::Join": [
61 | "", ["arn:aws:s3:::", { "Ref": "FastBootBucket" }, "/*" ]
62 | ] }
63 | }]
64 | },
65 | "Roles": [ { "Ref": "FastBootServerRole" } ]
66 | }
67 | },
68 |
69 | "FastBootServerInstanceProfile": {
70 | "Type": "AWS::IAM::InstanceProfile",
71 | "Properties": {
72 | "Path": "/",
73 | "Roles": [ { "Ref": "FastBootServerRole" } ]
74 | }
75 | },
76 |
77 | "FastBootApplicationVersion": {
78 | "Type": "AWS::ElasticBeanstalk::ApplicationVersion",
79 | "Properties": {
80 | "Description": "Initial FastBoot server",
81 | "ApplicationName": { "Ref": "FastBootApplication" },
82 | "SourceBundle": {
83 | "S3Bucket": "ember-fastboot-elastic-beanstalk",
84 | "S3Key": "latest.zip"
85 | }
86 | }
87 | },
88 |
89 | "FastBootConfigurationTemplate" : {
90 | "Type" : "AWS::ElasticBeanstalk::ConfigurationTemplate",
91 | "Properties" : {
92 | "ApplicationName" : { "Ref" : "FastBootApplication" },
93 | "Description" : "Default Configuration",
94 | "SolutionStackName" : "64bit Amazon Linux 2015.09 v2.0.6 running Node.js",
95 | "OptionSettings" : [{
96 | "Namespace": "aws:autoscaling:launchconfiguration",
97 | "OptionName": "IamInstanceProfile",
98 | "Value": { "Ref": "FastBootServerInstanceProfile" }
99 | }]
100 | }
101 | },
102 |
103 | "FastBootEnvironment": {
104 | "Type": "AWS::ElasticBeanstalk::Environment",
105 | "Properties": {
106 | "EnvironmentName": { "Ref": "FastBootEnvironmentName" },
107 | "ApplicationName": { "Ref": "FastBootApplication" },
108 | "TemplateName": { "Ref" : "FastBootConfigurationTemplate" },
109 | "VersionLabel": { "Ref" : "FastBootApplicationVersion" }
110 | }
111 | }
112 |
113 | },
114 |
115 | "Outputs": {
116 | "EnvironmentID": {
117 | "Description": "ID of the Elastic Beanstalk environment",
118 | "Value": { "Ref": "FastBootEnvironment" }
119 | },
120 |
121 | "DeploymentBucket": {
122 | "Value": { "Ref": "FastBootBucket" }
123 | },
124 |
125 | "URL": {
126 | "Description": "URL of the AWS Elastic Beanstalk Environment",
127 | "Value": { "Fn::Join": ["", ["http://", { "Fn::GetAtt": ["FastBootEnvironment", "EndpointURL"] }]]
128 | }
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/lib/commands/provision.js:
--------------------------------------------------------------------------------
1 | var chalk = require('chalk');
2 | var fs = require('fs');
3 | var path = require('path');
4 | var Promise = require('rsvp').Promise;
5 |
6 | var CloudFormation = require('../aws/cloud-formation');
7 | var ElasticBeanstalk = require('../aws/elastic-beanstalk');
8 |
9 | var CREATE_NEW_APP = 'Create a new application';
10 |
11 | module.exports = {
12 | name: 'eb:provision',
13 |
14 | description: 'Provisions an Elastic Beanstalk environment for FastBoot',
15 |
16 | run: function() {
17 | this.cf = new CloudFormation();
18 | this.eb = new ElasticBeanstalk();
19 |
20 | this.ui.writeLine(chalk.green('Provisioning AWS for FastBoot\n'));
21 |
22 | return this.askQuestions()
23 | .then(this.createApplicationIfNeeded.bind(this))
24 | .then(this.createStack.bind(this))
25 | .then(this.waitForStack.bind(this))
26 | .then(this.writeConfiguration.bind(this));
27 | },
28 |
29 | askQuestions: function() {
30 | var ui = this.ui;
31 | var self = this;
32 |
33 | return this.eb.describeApplications()
34 | .then(function(apps) {
35 | var questions = buildQuestions(apps);
36 | return ui.prompt(questions);
37 | })
38 | .then(function(answers) {
39 | self.answers = answers;
40 | });
41 | },
42 |
43 | createApplicationIfNeeded: function() {
44 | var answers = this.answers;
45 |
46 | if (answers.newApplicationName !== undefined) {
47 | return this.createApplication(answers.newApplicationName)
48 | .then(function(appName) {
49 | answers.applicationName = appName;
50 | });
51 | }
52 |
53 | answers.applicationName = answers.application.ApplicationName;
54 | },
55 |
56 | createStack: function() {
57 | var template = loadTemplate();
58 | var applicationName = this.answers.applicationName;
59 | var environmentName = this.answers.environmentName;
60 | var stackName = (applicationName + '-' + environmentName).replace(/ /, '');
61 |
62 | template.Description = "Ember FastBoot - " + this.project.name() + " - " + environmentName;
63 |
64 | return this.cf.createStack({
65 | stackName: stackName,
66 | applicationName: applicationName,
67 | environmentName: environmentName,
68 | template: template
69 | });
70 | },
71 |
72 | createApplication: function(appName) {
73 | var ui = this.ui;
74 | var eb = this.eb;
75 |
76 | ui.startProgress('Creating application ' + appName);
77 |
78 | return eb.createApplication(appName)
79 | .then(function(app) {
80 | ui.stopProgress();
81 | return app.ApplicationName;
82 | });
83 | },
84 |
85 | waitForStack: function(stackID) {
86 | var ui = this.ui;
87 | var answers = this.answers;
88 | var environmentName = answers.environmentName;
89 | var cf = this.cf;
90 |
91 | ui.writeLine(chalk.green('\nThe environment may take 5-10 minutes to be created. Please be patient.'));
92 | ui.writeLine(chalk.green('Configuration details will be saved once environment creation has completed.\n'));
93 |
94 | ui.startProgress('Waiting for ' + environmentName + ' environment to be created.');
95 |
96 | var outputs = this.outputs = {};
97 |
98 | return new Promise(function(resolve, reject) {
99 | var stopPolling = function() {
100 | ui.stopProgress();
101 | clearInterval(interval);
102 | };
103 |
104 | var interval = setInterval(function() {
105 | cf.describeStack(stackID)
106 | .then(function(data) {
107 | var status = data.Stacks[0].StackStatus;
108 |
109 | if (status === 'CREATE_COMPLETE') {
110 | stopPolling();
111 | extractOutputs(outputs, data);
112 | resolve(data);
113 |
114 | ui.writeLine(chalk.green('Environment created.'));
115 | } else if (status === 'CREATE_FAILED') {
116 | stopPolling();
117 | reject(data);
118 |
119 | ui.writeLine(chalk.red('Stack creation failed'));
120 | }
121 | })
122 | .catch(function(err) {
123 | stopPolling();
124 | reject(err);
125 | });
126 | }, 5000);
127 | });
128 | },
129 |
130 | writeConfiguration: function() {
131 | var environmentName = this.answers.environmentName;
132 | var applicationName = this.answers.applicationName;
133 | var configPath = '.env.deploy.' + environmentName;
134 | var outputs = this.outputs;
135 |
136 | var config =
137 | "FASTBOOT_EB_APPLICATION=" + applicationName + "\n" +
138 | "FASTBOOT_EB_ENVIRONMENT=" + outputs.EnvironmentID + "\n" +
139 | "FASTBOOT_EB_BUCKET=" + outputs.DeploymentBucket + "\n";
140 |
141 | fs.appendFileSync(configPath, config);
142 |
143 | this.ui.writeLine('Wrote configuration to ' + configPath + ':');
144 | this.ui.write("\n" + config + "\n");
145 | this.ui.writeLine(chalk.green('Run ' + chalk.blue('ember deploy ' + environmentName) + ' to deploy your app, then visit ' + chalk.blue(this.outputs.URL)));
146 | }
147 | };
148 |
149 | function buildQuestions(apps) {
150 | return [{
151 | name: 'application',
152 | message: 'Which Elastic Beanstalk application would you like to use?',
153 | type: 'rawlist',
154 | choices: function() {
155 | var choices = apps.map(function(app) {
156 | return {
157 | name: app.ApplicationName,
158 | value: app
159 | };
160 | });
161 |
162 | choices.push(CREATE_NEW_APP);
163 |
164 | return choices;
165 | }
166 | }, {
167 | name: 'newApplicationName',
168 | message: 'What is the name of the application?',
169 | type: 'input',
170 | when: function(answers) {
171 | return answers.application === CREATE_NEW_APP;
172 | }
173 | }, {
174 | name: 'environmentName',
175 | message: 'Which environment?',
176 | type: 'rawlist',
177 | choices: ['development', 'staging', 'production']
178 | }];
179 | }
180 |
181 | function loadTemplate() {
182 | var templatePath = path.join(__dirname, '../../assets/cloud-formation-template.json');
183 | return JSON.parse(fs.readFileSync(templatePath));
184 | }
185 |
186 | function extractOutputs(outputs, data) {
187 | data.Stacks[0].Outputs.forEach(function(output) {
188 | outputs[output.OutputKey] = output.OutputValue;
189 | });
190 |
191 | return outputs;
192 | }
193 |
--------------------------------------------------------------------------------
/lib/elastic-beanstalk-deploy-plugin.js:
--------------------------------------------------------------------------------
1 | /*jshint node: true*/
2 |
3 | var fs = require('fs-promise');
4 | var path = require('path');
5 | var glob = require('glob');
6 | var RSVP = require('rsvp');
7 | var exec = RSVP.denodeify(require('child_process').exec);
8 | var AWS = require('aws-sdk');
9 | var ElasticBeanstalk = require('./aws/elastic-beanstalk');
10 | var Promise = require('ember-cli/lib/ext/promise');
11 | var DeployPlugin = require('ember-cli-deploy-plugin');
12 | var md5Hash = require('./md5-hash');
13 |
14 | const CONFIG_ENV_MAPPING = {
15 | FASTBOOT_EB_APPLICATION: 'applicationName',
16 | FASTBOOT_EB_ENVIRONMENT: 'environmentName',
17 | FASTBOOT_EB_BUCKET: 'bucket'
18 | };
19 |
20 | module.exports = DeployPlugin.extend({
21 | defaultConfig: {
22 | environment: 'production',
23 | outputPath: path.join('tmp', 'fastboot-dist'),
24 | zipPath: path.join('tmp', 'fastboot-dist.zip')
25 | },
26 |
27 | requiredConfig: ['environment', 'bucket'],
28 |
29 | configure: function() {
30 | var config = this.pluginConfig;
31 |
32 | // Copy environment variables to the config if defined.
33 | for (var key in CONFIG_ENV_MAPPING) {
34 | if (process.env[key]) {
35 | config[CONFIG_ENV_MAPPING[key]] = process.env[key];
36 | }
37 | }
38 |
39 | this._super.configure.apply(this, arguments);
40 | },
41 |
42 | build: function() {
43 | var outputPath = this.readConfig('outputPath');
44 | var self = this;
45 |
46 | return this.buildFastBoot(outputPath)
47 | .then(function(files) {
48 | return {
49 | fastbootDistDir: outputPath,
50 | fastbootDistFiles: files || []
51 | };
52 | })
53 | .catch(function(error) {
54 | self.log('build failed', { color: 'red' });
55 | return Promise.reject(error);
56 | });
57 | },
58 |
59 | buildFastBoot: function(outputPath) {
60 | var buildEnv = this.readConfig('environment');
61 |
62 | this.log('building fastboot app to `' + outputPath + '` using buildEnv `' + buildEnv + '`...', { verbose: true });
63 |
64 | process.env.EMBER_CLI_FASTBOOT = true;
65 |
66 | var Builder = this.project.require('ember-cli/lib/models/builder');
67 |
68 | var builder = new Builder({
69 | ui: this.ui,
70 | outputPath: outputPath,
71 | environment: buildEnv,
72 | project: this.project
73 | });
74 |
75 | return builder.build()
76 | .finally(function() {
77 | process.env.EMBER_CLI_FASTBOOT = false;
78 | return builder.cleanup();
79 | })
80 | .then(this._logSuccess.bind(this, outputPath));
81 | },
82 |
83 | didBuild: function(context) {
84 | // Rewrite FastBoot index.html assets
85 | try {
86 | var browserAssetMap = JSON.parse(fs.readFileSync(context.distDir + '/assets/assetMap.json'));
87 | var fastBootAssetMap = JSON.parse(fs.readFileSync(context.fastbootDistDir + '/assets/assetMap.json'));
88 | var prepend = browserAssetMap.prepend;
89 |
90 | var indexHTML = fs.readFileSync(context.fastbootDistDir + '/index.html').toString();
91 | var newAssets = browserAssetMap.assets;
92 | var oldAssets = fastBootAssetMap.assets;
93 |
94 | for (var key in oldAssets) {
95 | var value = oldAssets[key];
96 | indexHTML = indexHTML.replace(prepend + value, prepend + newAssets[key]);
97 | }
98 |
99 | fs.writeFileSync(context.fastbootDistDir + '/index.html', indexHTML);
100 | } catch(e) {
101 | this.log('unable to rewrite assets: ' + e.stack, { verbose: true });
102 | }
103 | },
104 |
105 | willUpload: function(context){
106 | var self = this;
107 | var zipPath = this.readConfig('zipPath');
108 | var dir = context.fastbootDistDir;
109 |
110 | zipPath = path.resolve(zipPath);
111 |
112 | this.log('zipping ' + dir + ' into ' + zipPath, { verbose: true });
113 |
114 | return exec("zip -r " + zipPath + " *", {
115 | cwd: path.dirname(dir)
116 | })
117 | .then(function(){
118 | var zipBuf = fs.readFileSync(zipPath);
119 | var hash = md5Hash(zipBuf);
120 | var hashedZip = path.join(path.dirname(zipPath), 'fastboot-dist-' + hash + '.zip');
121 |
122 | context.fastbootHashedZip = hashedZip;
123 |
124 | return fs.rename(zipPath, hashedZip)
125 | .then(function() {
126 | self.log("created " + hashedZip, { verbose: true });
127 | return {
128 | hashedZip: hashedZip
129 | };
130 | });
131 | });
132 | },
133 |
134 | upload: function(context) {
135 | var bucket = this.readConfig('bucket');
136 | var file = context.hashedZip;
137 |
138 | this.log('uploading ' + file + ' to ' + bucket, { verbose: true });
139 |
140 | var key = path.basename(file);
141 | context.elasticBeanstalkS3Key = key;
142 |
143 | var s3 = new AWS.S3({
144 | params: {
145 | Bucket: bucket
146 | }
147 | });
148 |
149 | return new Promise(function(resolve, reject) {
150 | var params = { Key: key };
151 | params.Body = fs.createReadStream(file);
152 | s3.upload(params, function(err, data) {
153 | if (err) {
154 | reject(err);
155 | }
156 |
157 | resolve(data);
158 | });
159 | });
160 | },
161 |
162 | didUpload: function(context) {
163 | var environmentName = this.readConfig('environmentName');
164 | var applicationName = this.readConfig('applicationName');
165 | var bucket = this.readConfig('bucket');
166 | var name = this.project.name();
167 | var key = context.elasticBeanstalkS3Key;
168 |
169 | var eb = new ElasticBeanstalk();
170 |
171 | this.log('activating build on Elastic Beanstalk environment ' + environmentName);
172 |
173 | this.log('settng FASTBOOT_APP_NAME to ' + name, { verbose: true });
174 | this.log('settng FASTBOOT_S3_BUCKET to ' + bucket, { verbose: true });
175 | this.log('settng FASTBOOT_S3_KEY to ' + key, { verbose: true });
176 |
177 | var env = {
178 | FASTBOOT_APP_NAME: name,
179 | FASTBOOT_S3_BUCKET: bucket,
180 | FASTBOOT_S3_KEY: key
181 | };
182 |
183 | return eb.updateEnvironment(applicationName, environmentName, env);
184 | },
185 |
186 | _logSuccess: function(outputPath) {
187 | var self = this;
188 | var files = glob.sync('**/**/*', { nonull: false, nodir: true, cwd: outputPath });
189 |
190 | if (files && files.length) {
191 | files.forEach(function(path) {
192 | self.log('✔ ' + path, { verbose: true });
193 | });
194 | }
195 | self.log('fastboot build ok', { verbose: true });
196 |
197 | return Promise.resolve(files);
198 | }
199 | });
200 |
201 |
--------------------------------------------------------------------------------