Hi David,
so the problem is not .gitignore
file actually. It’s a bit more tricky. Let me please elaborate my understanding.
- Parse Server only publishes to github.com its
src/
folder.
-
src/
folder needs to be compiled with babel
to produce lib/
. This is described by the build
step in Parse Servers’ package.json
.
- The
build
step is invoked automatically by npm’s prepare
script that is run automatically at certain points of npm package’s lifecycle.
- For example
prepare
step is invoked by npm
when publishing the official package to npm registry. Thus for official releases, npm registry will only contain lib/
directory of parse-server and not its src/
.
- The
prepare
step it is also called automatically when npm installing parse-server dependency via git
, which is what is needed when you depend on forked parse-server version. For example like this:
npm install --save git+https://github.com/mman/parse-server#master
On a dev machine this works great, but it fails under docker.
The reason why it fails is nicely described here: Docker: Installing npm packages from github - burnedikt.
In short, npm install
when run as root (a fairly usual Dockerfile setup) will fallback to unprivileged user when running all scripts, and will emit an innocent invisible warning (sic!) message that prepare
script was not called at all, thus rendering the parse-server unusable.
Initially you think everything is fine:
npm verb prepareGitDep git+https://github.com/mman/parse-server.git#master: installing devDeps and running prepare script.
But then it fails:
npm sill prepareGitDep npm WARN lifecycle [email protected]~prepare: cannot run in wd [email protected] npm run build (wd=/root/.npm/_cacache/tmp/git-clone-f02a80e5)
The solution suggested by the poster to use npm install --unsafe-perm
did not work for me under docker either, and the only proper solution was to use non-privileged dedicated user to build the image. For official node
docker images there is a node
user with /home/node
home directory that can be used to build the custom package.
Here is my Dockerfile
for reference:
FROM node:14
MAINTAINER Martin Man <[email protected]>
EXPOSE 1337
USER root
RUN apt-get update && apt-get dist-upgrade -y
RUN apt-get update && apt-get install -y curl jq awscli
USER node
WORKDIR /home/node
RUN mkdir MyParseServer
WORKDIR MyParseServer
COPY package.json package.json
COPY package-lock.json package-lock.json
RUN npm install
COPY cloud cloud
COPY templates templates
COPY index.js index.js
COPY healthcheck.sh healthcheck.sh
CMD [ "npm", "start" ]
HEALTHCHECK CMD /home/node/MyParseServer/healthcheck.sh
I will be filing a PR to improve the contribution guide and clarify this step, as it seems that every now and then somebody gets bitten by it and the only solution I found within the fist 20 hours was to not .gitignore
the lib/
folder and push it to github.com, which is not nice and clean and complicates the creation of pull requests further down the line.