Web applications should be deployed in a production environment, which tends to require a special configuration.
We start by upgrading the Webpack specification to support a production version of the system.
Make a copy of your solution for the previous lab and store it under
lab11
. Note that as with previous labs, some of the
configuration in this lab is version-dependent so we suggest that you
integrate the package.json
file provided in the course repo
lab 11 as you did in lab 9.
Now, add a production configuration using Webpack as follows.
You can skip this step if you’ve integrated the suggested
lab 11 package.json
fild discussed above. If still
necessary, install some new tools using the Node Package Manager
(npm).
npm install autoprefixer extract-text-webpack-plugin --save
Add a separate Webpack config file for production by copying
webpack.config.js
to a new file, webpack.production.config.js
,
and making the following updates.
Note that this:var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin') var ExtractTextPlugin = require('extract-text-webpack-plugin'); module.exports = { entry: [ … ], output: { … }, module: { … }, postcss: [ require('autoprefixer') ], plugins: [ new webpack.DefinePlugin({ 'process.env':{ 'NODE_ENV': JSON.stringify('production') } }), new HtmlWebpackPlugin({template: __dirname + "/app/index.tmpl.html"}),new webpack.HotModuleReplacementPlugin()new webpack.optimize.OccurenceOrderPlugin(), new webpack.optimize.UglifyJsPlugin(), new ExtractTextPlugin("[name]-[hash].css") ] remove the development server configuration... };
Add scripts to package.json
for production mode.
Note that these scripts use default npm names, so they can be run by saying{ "name": "server", old settings... "scripts": { "build": "webpack --progress", "dev": "node server.js & webpack-dev-server --progress", "install": "webpack --progress --config ./webpack.production.config.js", "start": "node server.js" }, old settings... }
npm install
and npm start
. Note
also that the install script will still install the module
dependencies as needed.
If necessary, (re)set the MongoDB password in the environment variable as you did in the previous lab.
The server and application should run as they did before and the new install/start scripts should run a production version of the system. When you’ve confirmed that they do, consider the following:
Save (one-to-two-sentence summaries of) your answers to these questions
in a lab11.txt
file in the root of your lab repo.
You can compare your solution with the one in the course repo.
We now auto-deploy the production version of your application from GitHub to Heroku.
Prepare and deploy your application as follows.
Auto-deploys are easy to configure, but Heroku requires that your
app be stored in the root directory of your repo, which currently
isn’t the case with your cs336
repo. To address
this issue, use Git subtree branches by doing the following from the
root directory of your cs336
GitHub repo.
Copy your .gitignore
file into your lab11
sub-directory. This is not strictly necessary, but it will
allow you to test your production branch locally before
deploying it.
Create a new production branch for this lab (production11
)
in your repo based (only) on your solution sub-directory for
this lab.
git subtree split --branch production11 --prefix your-lab11-sub-directory/
Push your updated repo, including the new branch, to GitHub.
git push origin --all
Note that the copied .gitignore
file will
prevent dependent files/directories from being committed
to the repo.
You should now be able to see the new branch on GitHub. Switch to
it and verify that only the lab11
files/folders are in the root. You can check this locally as
well by checking out the new branch
(git checkout production11
) and listing the
directory. Be sure to go back to the master
branch before making updates, etc. (git checkout
master
).
Create a new NodeJS application on Heroku and configure it as follows.
Go to the application “Settings” tab and set the MongoDB password as a config variable. Give it the same name that you used in UNIX in the previous lab.
Configure your Heroku configuration to pull your app from GitHub as follows.
production11
) or do the deploys
manually.
Henceforth, any new code pushed to the
production11
branch will be auto-deployed
to
Heroku.
Save the URL of your Heroku deployment so that you can include it
in your lab11.txt
below.
Heroku should now see the new pushed code on GitHub and deploy it to your assigned Heroku URL. Verify that the new deployment works in the same way and uses the same database. Note that it can take several minutes to auto-deploy new changes to the production branch. When you’ve confirmed that it does, consider the following:
Save (one-to-two-sentence summaries of) your answers to these questions
in your lab11.txt
file.
If the Heroku deploy doesn’t work, double check the following:
To update your production branch, we suggest that you make changes to your master branch first, test them out locally and then merge them into your subtree branch. Do this as follows.
git checkout master (if necessary...) … (make/add/commit changes to the local master branch, testing as necessary...) git checkout production11 git merge master -s subtree -m "merge comment..." git push origin --all (pushes all branches...)
If you have auto-deploys configured, Heroku should pull and deploy the new changes. Otherwise you will need to do another manual deploy.
We will grade your work according to the following criteria:
lab11.txt
file.