Create your own CI Docker image for AWS S3 + CloudFront with Node 11 and Yarn

Jonathan Irwin
SovTech Insights
Published in
2 min readFeb 2, 2019

Finding the perfect Docker image to use on your CI can be tough — most stock ones don’t come with all the tools you require and custom ones with the right tools are created and controlled by people you don’t know. Luckily creating your own image is easy and can be done in a few minutes — let’s look at how.

Photo by Yulia Agnis on Unsplash
  1. Download and install Docker Desktop if you haven’t already. Links to the apps can be found on their getting started page.
  2. Create a Docker account — you will need this to upload your image to the Docker Hub.
  3. Find a suitable starting image — in our case we went with node:11.9.0-alpine

Note that for now we only need to know the name of the image that we want. The Node image tags can be found on the Node page on Docker Hub.

This image was chosen because it is official and at the time of writing Node 11.9.0 was the latest available version of Node. The Alpine Linux variant was chosen because it is lightweight. This image comes with Yarn pre-installed.

4. Create a file called “Dockerfile” with the following content:

FROM node:11.9.0-alpineLABEL maintainer="YOUR_NAME<YOUR_EMAIL>"# Install base and dev packagesRUN apk updateRUN apk add --no-cache --virtual .build-depsRUN apk add bash# Install build packagesRUN apk add make && apk add curl && apk add openssh && apk add git# Set timezone to UTC by defaultRUN ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime# Install aws-cliRUN apk -Uuv add groff less python py-pipRUN pip install awscliRUN apk --purge -v del py-pipRUN rm /var/cache/apk/*CMD ["/bin/bash"]

5. In your terminal rundocker build . -t your_docker_user/your_image_name

docker build . -t your_docker_user/your_image_name

Your Docker image should build now. The -t is to tag your image — this is how we will reference it later in our CI. After the image has built running docker images should show you a list of images, including the base image and the one we just built.

6. Publish the image to Docker Hub by running

docker push your_docker_user/your_image_name

7. Make use of the image in your CI 🙌 🎉

For example in Bitbucket Pipelines set the first line of your bitbucket-pipelines.yml file to image: your_docker_user/your_image_name

--

--

Jonathan Irwin
SovTech Insights

I scream.. You scream.. The police come.. It’s awkward..