Building for Beanstalk – Part 1 of 3

Make all the Things – Part 1 of 3 (Building)

In our development workflow, we require a few things; make build builds the project into a deployable artifact, make test runs our tests against the build, make deploy deploys our artifact to an environment. How do we make these three simple commands work with a complex environment of Vagrant, Docker, Jenkins, Elastic Beanstalk, multiple Amazon Web Service accounts, and multiple client projects going on at the same time? That’s what this article is about.

First, let’s go into the toolchain we’re using at Raster Media. Our custom applications use Spring Boot as their foundation, SASS for stylesheets, CoffeeScript for front end scripting and Gulp task definitions, Gulp for asset compilation, aws-cli for most AWS interaction, and AWS command line Apis for the nitty gritty of communicating with AWS services. That’s a lot to integrate into three simple commands. Tying it all together we could use Gulp or Rake, but we chose the simple, but powerful, Make.

Why Make? The file format is simple, easy to understand, and executes commands in an expected way. There is no fluff, no programming language quirkiness, and most of all, Make just works.

Make Build

Let’s begin with the build. What do we need to create our deployable project artifact? We need to start with a clean workspace and we need our assets. Here’s how we define that in the makefile.

build: clean assets

That’s it. In the makefile, that’s all you need to describe your target build and its dependencies, clean and assets. Now let’s define the clean and assets targets.

The clean target will remove the target, build, and dist directories and the assets target will run our build-assets target in gulp. The @ symbol in front just tells Make not to echo the command when it executes said command. First we tell the developer what we’re doing and then we do it, simple.

You probably noticed that the assets target has a dependency, include-gulp. At this point, you’re probably telling yourself, “just npm install gulp” and you’d be right.

include-gulp:
@npm install gulp

Makefiles can get large quickly due to the number of dependencies required to build a modern project. We use comments to section our Makefiles into logical areas like this.

Now each of our logical build steps are clearly defined and documented. This took less than a minute to write, and if you have a standard project template you fork from, you only need to do this once.

In the next article, we’ll cover make test. The @mvn compile step already runs unit tests using Maven, but we also need to run integration tests against a running instance of our project, which is what the test target will do. Stay tuned! Part 2!Part 3!