# 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 `Dockerfile`s 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