forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Dockerfile adding back in
public
directory (Automattic#8603)
* 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
Showing
2 changed files
with
62 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.git | ||
node_modules | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |