-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
26 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 |
---|---|---|
|
@@ -4,3 +4,6 @@ npm-debug.log | |
Dockerfile | ||
.git | ||
.gitignore | ||
jest* | ||
.env* | ||
test/ |
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,47 +1,64 @@ | ||
## Base ######################################################################## | ||
# Use a larger node image to do the build for native deps (e.g., gcc, pytyhon) | ||
FROM node:lts as base | ||
## Base ########################################################################### | ||
# Set up the base layer | ||
FROM node:16-alpine3.15 as base | ||
|
||
# Reduce npm log spam and colour during install within Docker | ||
ENV NPM_CONFIG_LOGLEVEL=warn | ||
ENV NPM_CONFIG_COLOR=false | ||
|
||
RUN npm i -g pnpm | ||
|
||
# We'll run the app as the `node` user, so put it in their home directory | ||
WORKDIR /home/node/app | ||
# Copy the package.json and lock file over | ||
COPY package*.json /home/node/app/ | ||
|
||
## Dependencies-dev ############################################################### | ||
# Stage for installing dev dependencies | ||
FROM base as dependencies-dev | ||
|
||
COPY package.json ./ | ||
|
||
RUN pnpm install | ||
|
||
## Dependencies ################################################################### | ||
# Stage for installing prod dependencies | ||
FROM base as dependencies | ||
|
||
COPY package.json ./ | ||
|
||
RUN pnpm install --prod | ||
|
||
## Development ################################################################# | ||
# Define a development target that installs devDeps and runs in dev mode | ||
FROM base as development | ||
WORKDIR /home/node/app | ||
# Install (not ci) with dependencies, and for Linux vs. Linux Musl (which we use for -alpine) | ||
RUN npm install | ||
# Copy development node_modules from dependencies-dev | ||
COPY --chown=node:node --from=dependencies-dev /home/node/app/node_modules ./node_modules | ||
|
||
# Copy the source code over | ||
COPY --chown=node:node . /home/node/app/ | ||
COPY --chown=node:node . . | ||
|
||
# Switch to the node user vs. root | ||
USER node | ||
# Start the app in debug mode so we can attach the debugger | ||
CMD ["npm", "run", "dev"] | ||
|
||
## Production ################################################################## | ||
# Also define a production target which doesn't use devDeps | ||
FROM base as production | ||
WORKDIR /home/node/app | ||
# We'll install production only deps | ||
RUN npm install --production | ||
# Start the app in debug mode so we can attach the debugger | ||
CMD ["pnpm", "dev"] | ||
|
||
## Deploy ###################################################################### | ||
# Use a smaller node image (-alpine) at runtime | ||
FROM node:lts-alpine as deploy | ||
# https://github.com/krallin/tini | ||
RUN apk --no-cache add tini | ||
WORKDIR /home/node/app | ||
# Copy what we've installed/built from production | ||
COPY --chown=node:node --from=production /home/node/app/node_modules /home/node/app/node_modules/ | ||
# Stage for that run our app | ||
FROM base as deploy | ||
# Copy prodduction node_modules from dependencies | ||
COPY --chown=node:node --from=dependencies /home/node/app/node_modules ./node_modules | ||
|
||
# Copy the source code | ||
COPY --chown=node:node . /home/node/app/ | ||
COPY --chown=node:node . . | ||
|
||
# Switch to the node user vs. root | ||
USER node | ||
|
||
ENV SSO_PORT=7777 | ||
|
||
# Docker Healthcheck | ||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ | ||
CMD wget --no-verbose --tries=1 --spider localhost:${SSO_PORT}/healthcheck || exit 1 | ||
|
||
# Start the app | ||
CMD ["tini", "node", "src/server.js"] | ||
CMD ["node", "src/server.js"] |