Publishing a Static AngularJS Application with Docker

Introduction

The most common use for JavaScript frameworks is to provide dynamic client-side user interface functionality for a web site. There are situations where a JS application does not require any services from its host server (see example unhosted apps). One of the challenges for this type of application is how to distribute it to end users.

This post will walk through creating a static AngularJS application (i.e. no back-end server) and how to create and publish a lean Docker container that serves the application content.  I will mention some tooling but discussion of setting up a JS development environment is beyond the scope of this article. There are many resources that cover those topics.

Also note that even though I’m using AngularJS, any static web content can be distributed with this method.

Side Note on AngularJS

One of the major advantages of using AngularJS over the many JavaScript framework alternatives is its overwhelming popularity. Any question or issue you may encounter will typically be answered with a simple search (or two).

angularjs-trends

With the recent AngularJS 2.0 controversy it will be interesting to see it this trend continues.

Creating an AngularJS application

The easiest way to create a full-featured Angular application is with Yeoman.  Yeoman is a Node.js module (npm) and along with its Angular generator creates a project that includes all of the build and test tools you’ll need to maintain an application.

Generate the Angular application with yo. Accepting all the defaults will include “Bootstrap and some AngularJS recommended modules.”  There’s probably more functionality included then you’ll need, but modules can be removed later.

The yo command will take a little while to complete because it has to download Angular and all of the modules and dependencies.

Start the server with Grunt (which needs to be installed separately).

The application can be viewed in a browser at http://localhost:9000/#/:

yeoman-default

Building the Application Distribution

After removing the ‘Allo, Allo’ cruft and creating your custom application create a distribution with:

This will create a dist directory that contains the static application content.

Creating and Publishing the Docker Container

The prerequisite is of course to install Docker and create a Docker Hub account (free). See Docker Installation Documentation.

A typical Ubuntu Docker container requires more than a 1GB download. A leaner Linux distribution is CoreOs. The coreos/apache container has a standard Apache server and is only ~250MB.

Add a Dockerfile file to the myapp directory:

The key here is the COPY command which copies the content of the dist directory to the container /var/www directory. This is where the Apache server will find index.html and serve it on port 80 by default.  No additional Apache configuration is required.

Create the docker container:

Output:

docker-build

Now push the container to your Docker hub account:

The dockeruser/myapp Docker container is now available for anyone to pull and run on their local machine or a shared server.

Starting the Application with Docker

The application can be started on a client system by downloading the running the dockeruser/myapp container.

The run command will download the container and dependencies if needed. The -d option runs the Docker process in the background while apache2ctrl is run in the container in the foreground. The application will be running on http://localhost:9001/#/.

To inspect the Apache2 logs on the running Docker instance:

To stop the server:

If you’ve pushed a new version of the application to Docker hub, users can update their local version with:

This example shows how Docker containers can provide a consistent distribution medium for delivering applications and components.

Americans Killed by Medical Errors Today

Current events have sparked popular tweets like this:

deaths-today

As referenced by the West Health To Err is Human: Interoperability is Divine article, based on a 300,000 annual death rate, the following could be added to the list:

Americans killed by medical errors today: 822

This shocking statistic positions medical errors as the third leading cause of death in the United States, behind heart disease and cancer.

Also see Deaths by medical mistakes hit records. Pretty depressing.

This is a complex problem to solve, but reducing preventable deaths with improved patient safety technology should be a priority. No duh!

The Bumpy Road to a New Development Laptop

My 6 year old Lenovo T400 finally gave up the ghost. It didn’t totally die (it probably never will, thank you IBM), but the screen was starting to flicker and it reliably rebooted itself whenever I was doing something useful. Very annoying.

Grief

I went though the standard 5 stages of grief:

  1. Denial: All T400’s do this.
  2. Anger: “Damn it, why does this thing keep crashing? I’m sick of this sh*t!”.
  3. Bargaining: Maybe if I update to 14.04 it will stop doing this.
  4. Depression: “This sucks!”
  5. Acceptance: OK, time to buy a new laptop.

I’m fine now, but that was a rough 30 minutes!

Decision Process

I’m not going to detail all of my system requirements or decision making process, but here’s a high level outline:

  • I primarily need a Ubuntu development machine. My T400 is a dual boot 12.04/XP.  In recent years I’ve rarely used Windows, but there are some tools that are nice to have around (e.g. Visual Studio).
  • I looked hard at the MacBook Pro but at the end of the day I just couldn’t bring myself to go that route. Besides the higher hardware cost/performance ratio re: the alternatives, I guess I’m just not a Mac person.
  • I really wanted to get an Ultrabook form factor. Not only for the portability, but I’m not ashamed to say that the ‘cool factor’ played a part in the decision.
  • I looked at all of the standard Ultrabook offerings: Lenovo, ASUS, Dell, System76, Acer, etc. No touch, no ‘convertible’ (if you need a tablet, buy a tablet), no Windows 8. The deciding factor for me was reliability. Besides the T400, I have a T60 in the closet that still runs fine.
  • So Lenovo it is. The history of the X1 Carbon (see The 2014 Lenovo X1 Carbon: Lenovo Giveth, And Lenovo Taketh Away and Lenovo ThinkPad X1 Carbon 2014 review)  goes back to 2011. The latest version (2014, or Carbon 2) has taken a lot of heat over the keyboard, function keys, and trackpad changes. I’m sure these opinions have merit, but I just want a fast machine that works!

Buying Experience (not good!)

Beware of the Lenovo Outlet. I purchased a ‘ThinkPad X1 Carbon 2 – New':

x1-carbon-2-new

Here’s the condition definition (my highlight):

Products that are discontinued, overstocked, or returned unopened. These items are in their original factory sealed packaging and have never been used or opened.

Boy was I disappointed when the package arrived! First, the only thing in the box was the laptop. No AC power adapter, no docs, no nothing. To my amazement, the machine was in suspend mode. When I opened the lid it came out of hibernation to a Win7 user password prompt! I didn’t even try to guess a password. I couldn’t believe it!

The machine was in pretty good shape physically, a little dirty and missing a foot pad, but no dents or scratches. Certainly opened and used!  At least the BIOS confirmed that I got the correct hardware (i7, 8G RAM, 256G SSD).

After many calls to multiple Lenovo service centers I got nowhere. No return, no exchange. Maybe I should write a letter to The Haggler, but even then I probably wouldn’t return the machine anyway. I got a great price (much better than what I could find on eBay) and the Lenovo Outlet no longer has any i7 X1 Carbon’s listed.  Also, I’m a techie so disk partitioning and re-installed OS’s is not a problem.

I’m thinking now that Lenovo might have screwed up a repair shipment and I ended up wiping some poor schmuck’s SSD. Oh well.

Anyway, as unpleasant as this was, I now have a development laptop that should meet my needs for many years to come.

Installation Notes

  • Dual boot. Here’s the right way: WindowsDualBoot, but because I installed Ubuntu first (mistake) here’s what I did:
    1. Used GParted  to partition the disk to my liking. Don’t forget to add a Linux swap partition (8G for me). The Ubuntu installer will complain if it’s not there and find it automatically if it is.
    2. Created a Ubuntu 14.04 bootable USB stick: How to create a bootable USB stick on Windows. Install Ubuntu on the ext4 partition.
    3. Created a bootable Windows 7 USB stick. The Universal USB Installer above works fine for this. Install Windows 7 on the Windows partition.
    4. After Step #3 the system will only boot Windows. Use Boot-Repair (option #2) to re-install GRUB.
  • Ubuntu 14.04 seems to work flawlessly on the X1. There were only two hardware compatibility issues that I read about:
    1. Not waking up from suspend mode. This is resolved by updating the BIOS firmware.  Upgrading from v1.09 to v1.15 fixed it for me. The Lenovo firmware only comes as a CD image (.iso) or a Windows update application. Because the X1 does not have a CDROM drive the only reasonable way to upgrade is via Windows. People have upgraded the firmware via USB (see BIOS Upgrade/X Series), but it’s really ugly.
    2. Fingerprint reader. Haven’t tried to use it, and probably won’t.

Happy Ending (I hope)

Like most things in life, nothing is ever perfect. This experience was no exception.

I have a JRuby/Rails project with some Rspec tests that take 80 seconds to complete on the T400 and 20 seconds on the X1. I can live with that improvement. :-)

Hopefully the X1 will last as long the T400 did.

Brain-Like Chip With 4000 Processor Cores

left-right-brainIBM Unveils a ‘Brain-Like’ Chip With 4,000 Processor Cores. The TrueNorth chip mimics 1 million neurons and 256 million synapses that IBM calls “spiking neurons.”

…the chip can encode data as patterns of pulses, which is similar to one of the many ways neuroscientists think the brain stores information.

IBM Research: Neurosynaptic chips provides more information on the low power system architecture and potential applications:

Neurosynaptic-chips

This is similar to Qualcomm’s Brain-Inspired Computing effort.

Connectivity Standards

I had been reading about “internet of things” (IoT) connectivity standards groups (links below) when I came across Bridget Moorman’s post Connectivity Standards Adoption Over Time.

I made an off-the-cuff comment because of the contrast I saw between the way other industries approach standards vs. the medical device industry.  Bridget and Tim kindly responded with informative feedback.

Standards are hard, so I guess it’s not easy for anyone.

 

An Unhealthy Lack Of Standards

apple-healthkitThe reality of healthcare interoperabilty is going mainstream: Apple Launches HealthKit To Share Vital Stats With Nike, Mayo Clinic:

The problem Apple will run into: No one agrees on how to measure even very simple health metrics, …

TL;DR:  iOS 7.1 to iOS 8.0 API Differences (search for ‘HealthKit’ on the page).

UPDATE (8/18/14);  Apple – iOS 8 – Health

FDASIA Health IT Report

health-it-catagoriesThe Food and Drug Administration Safety and Innovation Act (FDASIA) required the FDA to develop:

a report that contains a proposed strategy and recommendations on an appropriate, risk-based regulatory framework pertaining to health information technology, including mobile medical applications, that promotes innovation, protects patient safety, and avoids regulatory duplication.

Here’s the report: FDASIA Health IT Report (warning: PDF).

It looks like EMR/EHR vendors (administrative and health management functionality) don’t have to worry about FDA regulatory oversight. The medical device category (of course) does:

FDA would focus its oversight on medical device functionality because, in general, these functions, such as computer aided detection software and remote display or notification of real-time alarms from bedside monitors, present greater risks to patient safety than health IT with administrative or health management functionality.

 

Interoperable Healthcare

icu-interopThis is a good read: Healthcare Innovation Day 2014: Igniting an Interoperable Healthcare System (warning: PDF).

Healthcare is the one industry that’s been the slowest to adopt the intelligent methods we have in most other parts of our lives. How did the communications revolution that transformed industries such as banking, entertainment and telecom somehow leave healthcare behind?

Great question!

Here’s the ‘Call to Action’ list:

  1. Recognize that the lack of interoperability is a crisis and advocate for rapid change.
  2. Frame the interoperability problem correctly: Everyone is in the business of gathering and sharing data to best serve patients.
  3. Accelerate the full adoption of unambiguous, open standards for interoperability.
  4. Align stakeholder incentives to drive interoperability.
  5. Ensure validity, privacy, and security of data.
  6. Reduce technical complexity for hospitals, health systems, and healthcare workers.
  7. Develop new ways to use data streams that will result from interoperability to drive an adaptive system that will improve patient health.
  8. Guarantee secure access to data for patients, researchers.

There is a lot to do…

Services, Not Sensors

internetofthingsThe Internet Of Things: The Real Money Is The Internet, Not The Things (my highlight):

The trick will be whether hardware companies will push hard enough for standardization so they can capitalize on services revenue. Companies that see themselves as pure hardware manufacturers are likely doomed, but those that see beyond the “things” to instead focus on the services built on the “Internet,” the future is very bright.

Is this the new reality for the medical device industry as well?  If data and interoperability are the future, maybe it should be!

Predicting Heart Attacks and Electric Cars

tesla_model_sWhat do these two things have in common? Apple exploring cars, medical devices to reignite growth. That’s right, Apple!

… Apple is exploring ways to measure noise “turbulence” as it applies to blood flow. The company wants to develop software and sensors that can predict heart attacks by identifying the sound blood makes as it tries to move through an artery clogged with plaque, …

The first 5 pages of search result on this topic turn up the above quote and Elon Musk. And of course the media hype kicks into full gear: Apple’s iWatch could save your life.

Fortunately, sanity does prevail: No, An Apple Device Won’t Tell You If You’re Having A Heart Attack.  Even Eric Topol weighs in:

eric-topol-tweet

Subscribe

Categories

Twitter Updates