Skip to content

Commit

Permalink
Refactor Dockerfile docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevan-Y committed Mar 24, 2022
1 parent b412cd0 commit 279fa6d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
2 changes: 2 additions & 0 deletions src/docs/.dockerignore
@@ -1,2 +1,4 @@
build/
node_modules/
.gitignore
.eslintrc.js
59 changes: 28 additions & 31 deletions src/docs/Dockerfile
@@ -1,42 +1,39 @@
## Base ########################################################################
# Use a larger node image to do the build for native deps (e.g., gcc, python)
FROM node:lts as 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

# We'll run the app as the `node` user, so put it in their home directory
WORKDIR /home/node/app
# Install pnpm
RUN npm install -g pnpm
# Copy the source code over
COPY --chown=node:node . /home/node/app/

## 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)

WORKDIR /app

## Dependencies ###################################################################
# Stage for installing prod dependencies
FROM base as dependencies-dev

COPY package.json ./

RUN pnpm install
# Switch to the node user vs. root
USER node
# Expose port 4631
EXPOSE 4631
# Start the app in debug mode so we can attach the debugger
CMD ["pnpm", "start"]

## Production ##################################################################
# Also define a production target which doesn't use devDeps
FROM base as production
WORKDIR /home/node/app
COPY --chown=node:node --from=development /home/node/app/node_modules /home/node/app/node_modules
# Build the Docusaurus app

# Builder ########################################################################
# Stage for building our app
FROM base as builder

COPY --from=dependencies-dev /app/node_modules ./node_modules

COPY . .

RUN pnpm build

## Deploy ######################################################################
# Use a stable nginx image
FROM nginx:stable-alpine as deploy
WORKDIR /home/node/app
# Copy what we've installed/built from production
COPY --chown=node:node --from=production /home/node/app/build /usr/share/nginx/html/
# Use 1.20.2-alpine nginx image
FROM nginx:1.20.2-alpine as deploy

COPY --from=builder /app/build /usr/share/nginx/html/

# Add Healthcheck
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl --fail localhost:80 || exit 1

0 comments on commit 279fa6d

Please sign in to comment.