Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A debian-base image is used for cloning the repository and installing the
- # dependencies.
- FROM node:dubnium AS build
- WORKDIR /var/node
- ARG TAG
- ARG SSH_PRIVATE_KEY
- # 1) An SSH key is needed to clone the repoository, and github needs to be a
- # known host so that ssh doesn't prompt for key verification.
- # 2) The repo is cloned, then the TAG is checked out.
- # 3) Install the dependencies and build.
- # 4) Remove dev dependencies and install prod.
- RUN mkdir /root/.ssh/ \
- && echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa \
- && chmod 600 /root/.ssh/id_rsa \
- && touch /root/.ssh/known_hosts \
- && ssh-keyscan github.com >> /root/.ssh/known_hosts \
- && git clone git@github.com:<MY_PRIVATE_REPO_HERE>.git . \
- && git checkout ${TAG} \
- && npm install \
- && npm run build \
- && rm -rf node_modules \
- && npm install --only=production
- # An alpine image is used for the resulting image. It has the built
- # application and dependencies needed to run it, but not much else. It does
- # not contain the SSH key in the image's history.
- FROM node:dubnium-alpine
- WORKDIR /var/node
- # Copy the production assets.
- COPY --from=build ["/var/node/package.json", "./package.json"]
- COPY --from=build ["/var/node/connections.json", "./connections.json"]
- COPY --from=build ["/var/node/dist/", "./"]
- COPY --from=build ["/var/node/node_modules", "./node_modules"]
- RUN npm install -g forever
- # The application runs under the node user.
- USER node
- EXPOSE 3000
- ENTRYPOINT ["forever", "--minUptime", "1000", "--spinSleepTime", "1000"]
- CMD ["main.js"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement