The Dockerfile runs npm install, but postinstall fails because it requires write permissions, and by default, npm runs scripts with UID set to nobody. We can fix this by running npm install with the unsafe-perms flag.
However, to optimize the docker container build, rather than copying the whole repository to the container before running npm install, we just copy package.json to the container, then run npm install. But our postinstall script depends on some of the source code being available (like the scripts/createSymlinks module). We don't want to pre-copy the source code because then we lose Docker's automatic caching of the results of npm install, which is a huge time savings for building the container. To work around this, we could run npm install with the ignore-scripts flag set, then run postinstall only after we copy the source code over.
Codeship does not yet support Docker Compose Version 2 syntax or Version 2-specific features such as build arguments. We are currently working on support for Compose features up to the latest version and will announce as soon as full support is available to all users.
Ideally, what we want is a Dockerfile that looks something like this:
FROM node:5.10
MAINTAINER jeffrey@learnersguild.org
WORKDIR /app
COPY package.json ./
RUN npm install --ignore-scripts
COPY . ./
ARG NPM_AUTH_TOKEN
RUN npm postinstall --unsafe-perms
... and a codeship-services.yml file that looks something like this:
@jeffreywescott commented on Tue Aug 16 2016
There are a cascading set of issues with this:
Dockerfile
runsnpm install
, butpostinstall
fails because it requires write permissions, and by default,npm
runs scripts with UID set tonobody
. We can fix this by runningnpm install
with theunsafe-perms
flag.npm install
, we just copypackage.json
to the container, then runnpm install
. But ourpostinstall
script depends on some of the source code being available (like thescripts/createSymlinks
module). We don't want to pre-copy the source code because then we lose Docker's automatic caching of the results ofnpm install
, which is a huge time savings for building the container. To work around this, we could runnpm install
with theignore-scripts
flag set, then runpostinstall
only after we copy the source code over..npmrc
file in our source code repository that depends on anNPM_AUTH_TOKEN
variable being set, and right now, Codeship doesn't yet support the Docker Compose Version 2 syntax. From [the docs]:Ideally, what we want is a
Dockerfile
that looks something like this:... and a
codeship-services.yml
file that looks something like this:But we need to wait for Codeship.