Skip to content

Commit

Permalink
Improve docker layer caching and build times
Browse files Browse the repository at this point in the history
Currently, the apt-get package install layer is invalidated anytime we
update npm dependencies. This commit splits package installation and npm
dependency installation into separate steps, which should improve docker
layer caching and speed up build times.

This commit also extracts the inline docs installation into a separate
bin script.
  • Loading branch information
dblandin committed Mar 20, 2017
1 parent de25dcd commit aec899f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
40 changes: 17 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
FROM node:6.10.0-slim
MAINTAINER Code Climate <[email protected]>
LABEL maintainer "Code Climate <[email protected]>"

RUN apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg && \
echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -y yarn
apt-get update

WORKDIR /usr/src/app
COPY package.json yarn.lock /usr/src/app/

RUN yarn install

RUN apt-get update && \
apt-get install -y git jq && \
git clone https://github.com/eslint/eslint.git && \
ESLINT_DOCS_VERSION=`npm -j ls eslint | jq -r .dependencies.eslint.version` && \
cd eslint && \
git checkout v$ESLINT_DOCS_VERSION && \
cd .. && \
mkdir -p /usr/src/app/lib/docs/rules/ && \
cp ./eslint/docs/rules/* /usr/src/app/lib/docs/rules/ && \
rm -rf eslint && \
apt-get purge -y git jq && \
apt-get autoremove -y

RUN adduser -u 9000 --gecos "" --disabled-password app
COPY . /usr/src/app
RUN chown -R app:app /usr/src/app
COPY bin/docs ./bin/docs
COPY engine.json package.json yarn.lock ./

RUN apt-get install -y git jq yarn && \
yarn install && \
version="v$(npm -j ls eslint | jq -r .dependencies.eslint.version)" && \
bin/docs "$version" && \
cat engine.json | jq ".version = \"$version\"" > /tmp/engine.json && \
apt-get purge -y git jq yarn && \
apt-get autoremove --yes

RUN adduser --uid 9000 --gecos "" --disabled-password app
COPY . ./
RUN chown -R app:app ./ && \
mv /tmp/engine.json ./

USER app

Expand Down
12 changes: 12 additions & 0 deletions bin/docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

version=$1
printf "Pulling docs from ESlint %s\n" "$version"

git clone https://github.com/eslint/eslint.git /tmp/eslint
(cd /tmp/eslint && git reset --hard "$version")
mkdir --parents ./lib/docs
cp --recursive /tmp/eslint/docs/rules ./lib/docs/rules
rm --force --recursive /tmp/eslint

0 comments on commit aec899f

Please sign in to comment.