Skip to content

Commit

Permalink
Update Dockerfile adding back in public directory (Automattic#8603)
Browse files Browse the repository at this point in the history
* Update Dockerfile adding back in `public` directory

See Automattic#8516

In the build I mistakenly prevented copying in the `public` directory
thinking that it was generated during the build process.

Actually it held our static assets and needed to be there. Images were
missing, for example.

The same Dockerfile has been updated again but this time I have not
prevented Docker from incorporating the `public` directory

* Split into three main layers

This should cache better than the monolith from earlier

* Move cleanup around to actually save on space
  • Loading branch information
dmsnell authored Oct 19, 2016
1 parent 34939a8 commit 37c5501
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 47 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.git
node_modules
build
108 changes: 61 additions & 47 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,63 @@
FROM debian:wheezy

FROM node:6.9.0-slim
MAINTAINER Automattic

WORKDIR /calypso

RUN mkdir -p /tmp
COPY ./env-config.sh /tmp/
RUN bash /tmp/env-config.sh
RUN apt-get -y update && apt-get -y install \
wget \
git \
python \
make \
build-essential

ENV NODE_VERSION 6.9.0

RUN wget https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz && \
tar -zxf node-v$NODE_VERSION-linux-x64.tar.gz -C /usr/local && \
ln -sf /usr/local/node-v$NODE_VERSION-linux-x64 /usr/local/node && \
ln -sf /usr/local/node/bin/npm /usr/local/bin/ && \
ln -sf /usr/local/node/bin/node /usr/local/bin/ && \
rm node-v$NODE_VERSION-linux-x64.tar.gz

# npmrc is created by env-config.sh. For local testing, an empty one is generated
RUN touch /usr/local/etc/npmrc && \
mkdir /usr/local/node/etc && \
cp /usr/local/etc/npmrc /usr/local/node/etc/npmrc

ENV NODE_PATH /calypso/server:/calypso/client

# Install base npm packages to take advantage of the docker cache
COPY ./package.json /calypso/package.json
COPY ./npm-shrinkwrap.json /calypso/npm-shrinkwrap.json
# Sometimes "npm install" fails the first time when the cache is empty, so we retry once if it failed
RUN npm install --production || npm install --production

COPY . /calypso

# Build javascript bundles for each environment and change ownership
RUN CALYPSO_ENV=wpcalypso make build-wpcalypso && \
CALYPSO_ENV=horizon make build-horizon && \
CALYPSO_ENV=stage make build-stage && \
CALYPSO_ENV=production make build-production && \
chown -R nobody /calypso

USER nobody
CMD NODE_ENV=production node build/bundle-$CALYPSO_ENV.js
WORKDIR /calypso


ENV NODE_PATH=/calypso/server:/calypso/client

# Build a "base" layer
#
# This layer should never change unless env-config.sh
# changes. For local development this should always
# be an empty file and therefore this layer should
# cache well.
#
# env-config.sh
# used by systems to overwrite some defaults
# such as the apt and npm mirrors
COPY ./env-config.sh /tmp/env-config.sh
RUN true \
&& bash /tmp/env-config.sh \
&& apt-get -y update \
&& apt-get -y install \
git \
make \
&& apt-get autoremove -y \
&& rm -rf /tmp/* \
&& rm -rf /var/tmp/* \
&& rm -rf /usr/share/{doc,doc-base,info,locale,man}/* \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/dpkg/info/* \
&& true

# Build a "dependencies" layer
#
# This layer should include all required npm modules
# and should only change as often as the dependencies
# change. This layer should allow for final build times
# to be limited only by the Calypso build speed.
#
# Sometimes "npm install" fails the first time when the
# cache is empty, so we retry once if it failed
COPY ./package.json ./npm-shrinkwrap.json /calypso/
RUN true \
&& npm install --production || npm install --production \
&& rm -rf /root/.npm \
&& true

# Build the final layer
#
# This contains built environments of Calypso. It will
# change any time any of the Calypso source-code changes.
COPY . /calypso/
RUN true \
&& CALYPSO_ENV=wpcalypso make build-wpcalypso \
&& CALYPSO_ENV=horizon make build-horizon \
&& CALYPSO_ENV=stage make build-stage \
&& CALYPSO_ENV=production make build-production \
&& chown -R nobody /calypso \
&& true

USER nobody
CMD NODE_ENV=production node build/bundle-$CALYPSO_ENV.js

0 comments on commit 37c5501

Please sign in to comment.