diff --git a/dockerfiles/billing-development.dockerfile b/dockerfiles/billing-development.dockerfile index 7794303..72bdc23 100644 --- a/dockerfiles/billing-development.dockerfile +++ b/dockerfiles/billing-development.dockerfile @@ -1,18 +1,36 @@ FROM storjlabs/node-storj:latest +# We use dumb-init since Node.js is pretty terrible at running as PID 1 +RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 \ + && chmod +x /usr/local/bin/dumb-init + +# wait.sh forces our app to wait for other containers to come up before starting +# Should pull this into the repo to cache it or use the included wait scritp that comes with newer docker +# We shouldn't have to do this at all however. Our services should wait for other services until they are alive. +RUN wget -O /usr/local/bin/wait.sh https://raw.githubusercontent.com/Storj/storj-sdk/master/scripts/wait.sh + EXPOSE 3000 -RUN mkdir /billing -WORKDIR /billing +RUN mkdir /opt/billing +# Map `/opt/app` to this services project root +RUN ln -s /opt/billing /opt/app +WORKDIR /opt/billing RUN yarn global add nodemon -COPY ./package.json /billing/package.json +COPY ./package.json /opt/billing/package.json RUN yarn install --ignore-engines -COPY ./bin /billing/bin -COPY ./lib /billing/lib -COPY ./index.js /billing/index.js -COPY ./test /billing/test +COPY ./bin /opt/billing/bin +COPY ./lib /opt/billing/lib +COPY ./index.js /opt/billing/index.js +COPY ./test /opt/billing/test + +# Add setup script which takes care of vendored modules +ADD ./setup.sh /usr/local/bin/setup.sh + +# Pass everything through dumb-init and wait.sh first, making sure our process handles the responsibilities of PID 1 and waits for services it depends on to start before coming up. +ENTRYPOINT ["dumb-init", "--"] -CMD npm run start-dev +# The default command this container will run is the billing server, but the user can pass in their own commands which get handled by wait.sh and dumb-init. +CMD ["/bin/bash", "/usr/local/bin/wait.sh", "/usr/local/bin/setup.sh", "npm run start-dev"] diff --git a/dockerfiles/billing-importer.dockerfile b/dockerfiles/billing-importer.dockerfile index 0034983..cae777a 100644 --- a/dockerfiles/billing-importer.dockerfile +++ b/dockerfiles/billing-importer.dockerfile @@ -1,5 +1,14 @@ FROM node:6 +# We use dumb-init since Node.js is pretty terrible at running as PID 1 +RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 \ + && chmod +x /usr/local/bin/dumb-init + +# wait.sh forces our app to wait for other containers to come up before starting +# Should pull this into the repo to cache it or use the included wait scritp that comes with newer docker +# We shouldn't have to do this at all however. Our services should wait for other services until they are alive. +RUN wget -O /bin/wait.sh https://raw.githubusercontent.com/Storj/storj-sdk/master/scripts/wait.sh + COPY ./dockerfiles/files/billing-queries.package.json /root/package.json WORKDIR /root @@ -15,4 +24,11 @@ COPY ./lib/config.js /root/lib/config.js ENV BILLING_URL http://billing RUN chmod +x /root/bin/billing-queries.js -CMD npm run start-importer +# Add setup script which takes care of vendored modules +ADD ./setup.sh /bin/setup.sh + +# Pass everything through dumb-init and wait.sh first, making sure our process handles the responsibilities of PID 1 and waits for services it depends on to start before coming up. +ENTRYPOINT ["dumb-init", "--"] + +# The default command this container will run is the billing-importer, but the user can pass in their own commands which get handled by wait.sh and dumb-init. +CMD ["/bin/bash", "/bin/wait.sh", "/bin/setup.sh", "npm run start-importer"] diff --git a/dockerfiles/billing-production.dockerfile b/dockerfiles/billing-production.dockerfile index cde6460..d059801 100644 --- a/dockerfiles/billing-production.dockerfile +++ b/dockerfiles/billing-production.dockerfile @@ -1,5 +1,14 @@ FROM node:6.10 +# We use dumb-init since Node.js is pretty terrible at running as PID 1 +RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 \ + && chmod +x /usr/local/bin/dumb-init + +# wait.sh forces our app to wait for other containers to come up before starting +# Should pull this into the repo to cache it or use the included wait scritp that comes with newer docker +# We shouldn't have to do this at all however. Our services should wait for other services until they are alive. +RUN wget -O /bin/wait.sh https://raw.githubusercontent.com/Storj/storj-sdk/master/scripts/wait.sh + # TODO: use `production` but first we have to fix packages `engines` to be all compatible with 6.x #ENV THOR_ENV production ENV THOR_ENV development @@ -15,4 +24,12 @@ WORKDIR /billing RUN yarn --ignore-engines +## Add setup script which takes care of vendored modules +#ADD ./setup.sh /bin/setup.sh +# +## Pass everything through dumb-init and wait.sh first, making sure our process handles the responsibilities of PID 1 and waits for services it depends on to start before coming up. +#ENTRYPOINT ["dumb-init", "--"] +# +## The default command this container will run is the bridge, but the user can pass in their own commands which get handled by wait.sh and dumb-init. +#CMD ["/bin/bash", "/bin/wait.sh", "/bin/setup.sh", "npm run start-prod"] CMD npm run start-prod diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..011048a --- /dev/null +++ b/setup.sh @@ -0,0 +1,15 @@ +cd /opt/app + +for dir in /usr/src/vendor/* ; do + if [[ -d $dir ]]; then + echo "Manually linking $dir" + dir_name=$(basename $dir) + rm -rf /opt/app/node_modules/$dir_name + cp -rp $dir /opt/app/node_modules/$dir_name + fi + + echo "Rebuilding linked modules" + npm rebuild +done + +/bin/bash -c -- "$@"