Skip to content

Instantly share code, notes, and snippets.

@sinogermany
Created November 24, 2016 23:21
Show Gist options
  • Save sinogermany/0ed5e74737f05bec1411482d7126b450 to your computer and use it in GitHub Desktop.
Save sinogermany/0ed5e74737f05bec1411482d7126b450 to your computer and use it in GitHub Desktop.
docker-huddle-20161125.md

Docker Huddle - Reducing Build Time

Broadband Team - Daniel Deng (DiUS)

01. The problem

  • A very trivial commit to master would trigger a pipeline that takes 20+ minutes.
  • The feelback loop was very slow.
  • Long running pipeline is blocking other pipelines

02. About the broadband-funnel app

  • The broadband funnel consists of a backend-for-frontend bff and a front end fe
  • bff is a Ruby 2.3.1 / Rails 5 application, API only.
  • fe is React SPA

03. The previous docker solution

  • 2 docker images based on ruby:2.3.1 image, one for bff one for fe
  • Every time the pipeline runs, 2 docker images will be built.
  • It used to about 20 mintues to build both images

04. What are the Dockerfiles doing?

bff:

  • pull out ruby:2.3.1
  • run apt-get update && apt-get upgrade
  • install build time and runtime apt dependencies
  • copy the whole /bff directory over
  • switch WORKDIR
  • run bundle install
  • ENTRYPOINT / CMD

fe:

  • pull out nginx:latest
  • run apt-get update && apt-get upgrade
  • install build time and runtime apt dependencies
  • install node.js
  • npm install -g yarn
  • copy the whole /fe directory over
  • switch WORKDIR
  • yarn build to minimise the artefects
  • copy nginx.conf
  • ENTRYPOINT / CMD

05. Improvements

  • use alpine instead
  • combine to 1 docker image
  • have a base image for time-consuming yet stable operations (apt-get, bundle install etc.)
  • build the SPA artefect outside docker (e.g. in ci)
  • delete build time dependencies

06. Outcome

ci docker build step duration reduced from 20+ minutes to 3 minutes

07. Further improvements

  • non-root user
  • use ENTRYPOINT more
  • utilise caching further with the price of more layers
  • update system packages even if Gemfile.lock doesn't change

08. Q&A / Comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment