visit
In the "Here's How I Moved from AWS to Heroku" article, I provided an introduction of the application I wanted to migrate from Amazon's popular AWS solution to .
Subsequently, the ": Changing my Tech Stack" article illustrated the establishment of a new Heroku account and focused on introducing a Java API (written in Spring Boot) connecting to a ClearDB instance within this new platform-as-a-service (PaaS) ecosystem.amhs-angular
ApplicationFollowing the same base steps in the "Destination Heroku" article, I created an application called
amhs-angular
to house the Angular client code.heroku create amhs-angular
Next, I added the
amhs-angular
Heroku project as a remote in the git repository for the AMHS Angular client using the following command:heroku git:remote -a amhs-angular
Which responded with the following output:set git remote heroku to //git.heroku.com/amhs-angular.git
The following git command validated the remote was set up properly:$git remote -v
1. Build the distribution for Angular using the
ng build --prod
command2. Navigate to AWS | Storage | S3Single-click the AMHS bucket3. Drag all the files under the
/dist
folder into the main file screen in AWS4. Select all the files and grant the appropriate level of securityWith Heroku, the plan is to use a Node.js Express server to host these files. Within the terminal of the AMHS Angular client project, I executed the following command to include the express sever:$ npm install express --save
Next, I needed to update the
package.jso
n to "start": "node server.js"
and also included a "postinstall":
"ng build --output-path dist"
to perform the Angular build.Below, is a copy of the
package.json
after it was updated:"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --output-path dist"
},
I also needed to include an
"engines"
attribute, at the same level as "scripts"
to the package.json
:},
"engines": {
"node": "11.15.0",
"npm": "6.7.0"
}
Next, a generic
server.js
file (referenced above) needed to be created. The contents are listed below:const express = require('express');
const path = require('path');
const app = express();
app.use(express.static('./dist'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname,'/dist/index.html'));
});
app.listen(process.env.PORT || 8080);
Finally, I needed to update the
environment.prod.ts
Angular file to reference the correct call-back URL and the API created in the "Destination Heroku" article:api: '//amhs.herokuapp.com',
redirectUrl: '//amhs-angular.herokuapp.com/implicit/callback'
At this point, when the client is deployed, it is ready to utilize a Node.js Express server to host the files in the
/dist
folder, calling the /dist/index.html
file when the //amhs-angular.herokuapp.com URL is called.With the code in the AMHS Angular client repository checked and the Heroku remote setup for the
amhs-angular
project, the code was deployed to Heroku using the following command:git push heroku
The following command provided updates regarding the deployment:-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): 11.15.0
engines.npm (package.json): 6.7.0
Resolving node version 11.15.0...
Downloading and installing node 11.15.0...
npm 6.7.0 already installed with node
-----> Restoring cache
- node_modules
-----> Installing dependencies
Installing node modules
> [email protected] install /tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/fsevents
> node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp http GET //nodejs.org/download/release/v11.15.0/node-v11.15.0-headers.tar.gz
gyp http 200 //nodejs.org/download/release/v11.15.0/node-v11.15.0-headers.tar.gz
gyp http GET //nodejs.org/download/release/v11.15.0/SHASUMS256.txt
gyp http 200 //nodejs.org/download/release/v11.15.0/SHASUMS256.txt
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/tmp/build_d2400638d424ad7a3269162acc30fb7e/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/fsevents/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/tmp/build_d2400638d424ad7a3269162acc30fb7e/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/app/.node-gyp/11.15.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/app/.node-gyp/11.15.0',
gyp info spawn args '-Dnode_gyp_dir=/tmp/build_d2400638d424ad7a3269162acc30fb7e/.heroku/node/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/app/.node-gyp/11.15.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/fsevents',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/fsevents/build'
SOLINK_MODULE(target) Release/obj.target/.node
COPY Release/.node
make: Leaving directory '/tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/fsevents/build'
gyp info ok
> [email protected] install /tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/node-sass
> node scripts/install.js
Downloading binary from //github.com/sass/node-sass/releases/download/v4.14.0/linux-x64-67_binding.node
Download complete
Binary saved to /tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/node-sass/vendor/linux-x64-67/binding.node
> [email protected] postinstall /tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/node-sass
> node scripts/build.js
Binary found at /tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/node-sass/vendor/linux-x64-67/binding.node
Testing binary
Binary is fine
> [email protected] postinstall /tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/ejs
> node ./postinstall.js
Thank you for installing EJS: built with the Jake JavaScript build tool (//jakejs.com/)
> [email protected] postinstall /tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
Thank you for using core-js ( //github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> //opencollective.com/core-js
> //www.patreon.com/zloirock
Also, the author of core-js ( //github.com/zloirock ) is looking for a good job -)
> [email protected] install /tmp/build_d2400638d424ad7a3269162acc30fb7e/node_modules/uws
> node-gyp rebuild > build_log.txt 2>&1 || exit 0
> [email protected] postinstall /tmp/build_d2400638d424ad7a3269162acc30fb7e
> ng build --output-path dist
Date: 2020-04-29T14:51:08.447Z
Hash: 3d551622b66d1beb5645
Time: 16403ms
chunk {main} main.js, main.js.map (main) 238 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 428 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 60.8 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 4.96 MB [initial] [rendered]
added 1304 packages in 78.585s
-----> Build
Running build
> [email protected] build /tmp/build_d2400638d424ad7a3269162acc30fb7e
> ng build --prod
Date: 2020-04-29T14:52:24.535Z
Hash: 459ef7d3fda55011a399
Time: 72281ms
chunk {0} runtime.06daa30a2963fa413676.js (runtime) 1.44 kB [entry] [rendered]
chunk {1} main.478fe235ec2084c25ab2.js (main) 867 kB [initial] [rendered]
chunk {2} polyfills.aeab97ddd8f1df8ccaa1.js (polyfills) 103 kB [initial] [rendered]
chunk {3} styles.495d5a4089b8a2584a59.css (styles) 30.9 kB [initial] [rendered]
-----> Caching build
- node_modules
-----> Pruning devDependencies
removed 1204 packages and audited 182 packages in 18.694s
found 3 vulnerabilities (1 low, 1 moderate, 1 high)
run `npm audit fix` to fix them, or `npm audit` for details
-----> Build succeeded!
-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> web
-----> Compressing...
Done: 53.1M
-----> Launching...
Released v1
//amhs-angular.herokuapp.com/ deployed to Heroku
git push heroku
In fact, using the CI/CD functionality within GitLab (where the AMHS source code is housed), the process can be automated using a very basic pipeline that is fired when the master branch of the repository changes.While I am sure there is a way to automate the same steps in AWS S3, more time would time would have been required for learn aspects of technology which is not focused on providing features and functionality to my client.In the final article of this series, I will cover the following points: