Port? What port?

Recently I was playing around with building an express.js app and running it in Docker. I used the standard npm init to create my app, wrote my code, tested it, and was happy.

Then I tried to deploy it in Marathon. No matter what I did, I couldn’t get it to load. It was as if the port forwarding just didn’t work. I even docker-enter‘ed into the container, and couldn’t connect to Node – but it was running.

As a last resort, I went poking around the auto-generated code that express creates, and I saw this line:

/**
 * Get port from environment and store in Express.
 */

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

and the light bulb finally went off.

Marathon sets the PORT environment variable when launching a Docker container so that the app knows which port it’s proxying to (helpful for service registration, etc). In this case, Express was using that environment variable and listening on that port instead of the expected 3000. I just removed that check and we’re good to go!

Using Ansible for Marathon/Chronos deployments

Here at Motus, Ansible has long been our tool of choice for application deployments and bulk ad-hoc sysadmin commands (we use Puppet for configuration management). As we have moved from “traditional” application deployments – where we ship binaries to multiple servers, perform local deployment commands, and verify – to deployments on Marathon and Chronos – where we deploy using HTTP commands – we have had to tweak our Ansible usage somewhat. This post covers some of the things that we’ve done to allow Ansible to work well in this environment.

Continue reading “Using Ansible for Marathon/Chronos deployments”