Developing in JavaScript in 2017

This is a bit of a rant…

Many people will be familiar with the funny article How it feels to learn JavaScript in 2016. The thing is, I don’t find it that funny anymore, because it’s pretty much the truth, and I’ve been through it.

In 2017 I’ve done a fair bit of JavaScript development, lots of learning and researching and coding too. You know what, after stepping back and looking at it - the JavaScript ecosystem is nuts. There’s no nice way of putting it, it’s a f**king mess. We’re not talking obscure stuff here, basic things you’d take for granted in any other language like just importing a library into your code can be a horrific journey into conflicting standards, syntaxes & systems.

Here’s just some of the stuff I had to learn, use & research in 2017…

Read More

  Running Docker

Running Docker, or specifically running Docker on your Windows 10 machine, sounds simple? Well yes in the most part it is, Docker provide an installer and setup to do just that.

So what’s the issue? Well, ‘Docker for Windows’ is pretty flaky; sometimes won’t start for no apparent reason and installing it often fails. Chatting to colleagues at work and on Twitter several people have had problems with it, usually just before they are running a live demo - the last thing you want to be worrying about before a demo is “will Docker fall over?”

Now I’m not sure what the root of these problems is, but I thought I’d examine some of the alternatives. These alternatives all forgo installing the regular ‘Docker for Windows’ setup on your machine. I will also be ignoring the need to run Windows Containers, as we’ve already got enough to discuss.

Docker Tools and CLI

The first challenge is getting the docker command line tools on your machine. Docker provide a nice installer for just the tools called ‘Docker Toolbox’.

The tools were are interested in are the following commands: docker, docker-compose and docker-machine

NOTE the default install options with ‘Docker Toolbox’ include a lot of rubbish you don’t need, like VirtualBox (blergh) and Kitematic, be sure to deselect those options and just install ‘Docker Client’, ‘Docker Compose’ and ‘Docker Machine’

Docker client tools for WSL bash

If you are using Windows Subsystem for Linux (WSL) and bash you will want to use the Docker tools from there too. There is no client only package that Docker provide for Linux, however the binaries are available.

Running the following snippet in a WSL bash terminal will download and install the tools you need.

curl -L https://download.docker.com/linux/static/stable/x86_64/docker-17.09.0-ce.tgz -o /tmp/docker.tgz
tar -zxvf /tmp/docker.tgz docker/docker
chmod +x docker/docker
sudo mv docker/docker /usr/local/bin/docker
rmdir docker/
curl -L https://github.com/docker/machine/releases/download/v0.13.0/docker-machine-`uname -s`-`uname -m` -o /tmp/docker-machine
chmod +x /tmp/docker-machine
sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` -o /tmp/docker-compose
chmod +x /tmp/docker-compose
sudo cp /tmp/docker-machine /usr/local/bin/docker-compose

Running a Docker host

OK with the client tools installed, we need some machine or VM running the Docker engine (I’ll refer to this as a Docker host)

Your choices here fall into two options; run a VM locally or run a VM in the cloud, we’ll discus both here.

Your next decision is how to build the VM and install Docker, as we’re in DIY mode, the temptation is to create the Linux VM yourself (e.g. Ubuntu) and then install Docker on it. DO NOT DO THIS! This is way, way more pain than it worth, you will spend an inordinate amount of time with configuration; iptables, daemon.json, etc and at the end of it all have an insecure Docker instance.

The ‘Docker Machine’ tool was created for a good reason, so we should use it. Docker Machine will create the Docker host VM for us, install the Docker engine securely and give us a clean simple way to point our tools to the new VM

Running Docker Machine

Docker Machine will let us create our host either in the cloud or locally. This is done via different drivers, there are a wide range of drivers we will look at two, Azure and Hyper-V

Creating Docker host in Azure

This is a simple process, just a single command docker-machine create -d azure. You will need your Azure subscription ID (easily found in the Azure portal) and that’s about it. The following is a bare bones but functioning example

docker-machine create -d azure --azure-subscription-id 12345678-aaaa-bbbb-cccc-abcdef123456 myNewHost

The last parameter mynewhost is the name of the host & VM, so you can pick anything you like, but uppercase and hyphens tend to cause problems dock

You will likely want a bit more control over how the VM is created, and you can do this with additional parameters provided to the create command. Some parameters worthy of attention are:

  • --azure-location - Azure region/location
  • --azure-resource-group - Name of the resource group
  • --azure-size - VM size, e.g. Standard_A4_v2 or Standard_F8s_v2
  • --azure-static-public-ip - Assign static public IP
  • --azure-open-port - List of ports to open on the NSG that is created
  • --azure-dns - DNS prefix for the public IP

A full list is available here

docker-machine create -d azure --azure-subscription-id 12345678-aaaa-bbbb-cccc-abcdef123456 \
--azure-resource-group Temp.Docker --azure-size Standard_F4s_v2 --azure-static-public-ip \
--azure-dns bensdocker --azure-location westeurope --azure-open-port 3000-8080 bensdocker
docker-machine create -d hyperv --hyperv-cpu-count 2 --hyperv-memory 1024 --hyperv-disk-size 8000 localdocker

Sharing Docker Machine config

If you are going to switching between PowerShell and WSL as I often do, then you might want the docker CLI to work in both against your remote Docker Machine created host.

Docker Machine stores its config in the .docker/ folder in your home or user profile directory

  Containers & Docker - Tech Primer

My second technical primer, this one covers containers & Docker. Aimed at people that want to understand containers, what they are, how to use them and also get started with Docker. The guide goes into medium technical depth, examples of commands but is not intended as a comprehensive end to end reference.

As usual, these can be used for presentations, used in labs & exercises but also given as handout/reading material.

Access and download: Docker & Containers - Tech Primer

  Node.js with App Service on Linux

This is a follow up to my first post on running Node.js in Azure App Service, this time I want to cover the newly GA’ed App Service on Linux.
In most regards App Service on Linux works the same way as the regular (Windows) App Service, is has the same core features and operate mostly the same.

The main difference (aside from the blindingly obvious; the host OS is Linux!) is App Service on Linux uses Docker containers to host & run your webapp. This provides a heap of advantages when it comes to deploying your app, and IMO containers also make an ideal way to run Node based apps. There’s many lightweight and robust Docker images you can use, the Alpine Linux image notably weighing in at a tiny 23MB.

You have two fundamental ways of working with App Service on Linux:

  • Use one of the provided application stack images
    Referred to as “App Service on Linux” or “Linux Web Apps”
  • Run a custom image, either one of your own Docker images or one pulled from Dockerhub.
    Referred to as “Web App for Containers”

We’ll cover using both approaches to host and run Node apps

Read More

  Azure Resource Manager - Tech Primer

I’ve decided to put a few of my technical guides online, I’ve called these guides “technical primers”, created with technical folks in mind, that might be new to a particular topic or domain. I wanted to solve several things with these primers, combining both introductory overview content, but also technical reference material and deeper dives into various key areas.
These can be used for presentations, used in labs & exercises but also given as handout/reading material.

The first of these guides is on Azure Resource Manager - View & Download

  Running Node.js in Azure App Service

I’ve been using Node.js quite a lot lately as I find it a nice quick way to get web projects started easily, and one of the things I’ve been doing is deploying and running my Node.js apps in Azure. Azure provides a number of ways of to run Node.js code within the platform, but I’ll be focusing on the PaaS Azure App Services or Web Apps (more info), rather than VMs or anything strange.

Why write a blog about this? Isn’t using Node.js with Azure Web Apps all easy and already documented? Well… kinda, there is documentation but there’s also a lot of gotchas, semi-hidden features and things I stumbled across which made me feel like gathering all these nuggets of info into one place

Read More

  Azure DevOps - Hands On Labs

I’ve recently put together a couple of training labs / hackathon exercises. One is based on the .NET Core series of posts but updated slightly and made into more of a single logical flow, it also adds CI/CD to the process using Visual Studio Team Services (VSTS).
The basic premise behind both is the same; starting from scratch writing a web application and getting it deployed into Azure via VSTS. The second lab uses Node.js as the application stack instead of .NET Core, and deploys into Azure Linux Web Apps (rather than Docker Machine) via Docker containers.

These guides can be used a number of ways; run as a demo, given to people to run through at a hackathon or as a training exercise

Both guides are on GitHub

End to end DevOps exercise with .NET Core, Docker, VSTS in Azure

Hands on lab exercise for DevOps in Azure with OpenSource

  Securing Wordpress in Azure App Service

Since I moving my blog into Azure (as detailed in a previous post), I had started to see a series of odd alerts being fired out, with lots of random 500 errors at odd times of the day & night. When I checked the website was fine. At first thought this was related to the Azure App Service I was hosting my site in, but it occurred to me that it could have been happening before, but I just didn’t know - Azure & the App Service was alerting me to stuff I previously had no visibility into

Read More

  Migrating & Running Wordpress in Azure

Recently I decided to move my Wordpress blog from where it is hosted in a virtual shared Linux environment (TSO Host) into Azure. The current hosting is fine and has served me well over the years, but seeing as my current job is working with Azure I wanted to experiment. In particular my role is focused on the PaaS web & app hosting services in Azure, so I wanted to see first hand what the experience was like, particularly for a non enterprise user.

The migration has been successful (hopefully this page loaded without errors!), so I’ve decided to capture my thoughts on the process and some of the challenges I encountered along the way

Read More