How do I update my MEAN application with Stacksmith

Jose Fuentes

Jose Fuentes


Advanced Engineer


Share this article

As we mentioned in the first part of this article, "Target the cloud effortlessly with your MEAN application and Stacksmith", Stacksmith monitors the application components for updates and security patches. It provides a simple way to repackage your application making updates easy to incorporate.

In this post, I will walk you through the process of updating both dependencies and application code, to deploy the new version on AWS or Kubernetes. This article assumes that your MEAN application is now live, and there are some new features and new versions of dependent packages released so you want to update it.

There are typically two types of updates you'll want to perform: updating the packages your application is dependent on and/or updating your application code. Step 1 discusses the first case and Step 2 the second. Step 3 shows you how to redeploy your updated application to AWS or Kubernetes. Let's start at the beginning:

Step 1: Update dependencies

On the application details page in Stacksmith, you will see a list of the packages included in the image.

System packages

When the image gets outdated, new versions available for your installed packages will appear here automatically.

System packages update available

Rebuilding your application with the latest dependencies is a simple one-click process— just hit the "Repackage" button. This repeats the build process with the same version of your codebase, but with fresh system packages.·

In this example, it will also get fresh npm dependencies. Depending on your release process, you might prefer to use the shrinkwrap feature of npm, so the versions of the dependencies remain locked. That is as easy as adding the npm-shrinkwrap.json to your project.

Step 2: Update application code

Let's suppose that you want to package a new version of the app. To generate this new version, you can apply the patch provided in the repo that changes the color of the counter in the app from blue to orange:

cd stacksmith-examples/nodejs-with-nosql/todo
git apply ./change_color.patch
tar czf app.orange.tar.gz app

Or just download the provided tarball called app.orange.tar.gz instead.

To package a new version of the app, follow these steps:

  • Click the "Edit configuration" button within your app details page.

Edit app

  • You will see a form with the definition of the application already filled.
  • To update the application, change the version tag to another one, (from 1 to 2 in this example).
  • Delete the previous version of the application files by clicking on the bin icon, and upload the new one.
  • Click on "Update" and wait for the new version to be built.

Step 3: Deploy the new version

This process differs depending on whether you have deployed the application in AWS or Kubernetes.

Upgrade the stack running in AWS

Once the new version is ready:

  • Copy the "CloudFormation template URL" to the clipboard.

New version of Cloud Formation template

  • In the AWS console, go to the details of your stack.
  • Click on "Update Stack".

Update stack in AWS

  • Paste the URL on the "Specify an Amazon S3 template URL".

Select new template in AWS

  • Click "Next" and complete the wizard. It is likely you won't need to change anything else.
  • At the end, it will show you a preview of the changes that it will apply. Click on "Update".

Stack update in progress

This will spin up a new instance with the new version of the app, and when it is ready, it will destroy the old one. After a while, the operation will finish. That means that the changes are now deployed.

Upgrade the release running in Kubernetes

  • Download the new chart by clicking on "Download Helm chart" on the new version that has been built for Kubernetes.

New version of Helm chart

  • Use the name you gave to the helm release to run the following command:

    $ helm upgrade my-todo-app ./my-to-do-application-2-docker-977028011.tgz
    

Check the result

After the upgrade has finished, refresh the page where your app was being served (or open it again).

New version of the app running

You will notice that the counter has changed the color from blue to orange—proof that the new version has been deployed.

This is a really simple and convenient way of building, deploying, and maintaining your applications on AWS and Kubernetes. You can easily deploy your application to your desired platform targets, and release new versions smoothly.

Stacksmith supports other sets of runtimes—check out the different templates. And there are more to come.

Package, deploy, and maintain your own Node.js application today. And if you have any feedback, let us know in our community forum. We look forward to hearing from you!