From 2c1ad3a4634b3e4cd95632146f32a6331f961787 Mon Sep 17 00:00:00 2001 From: Bill Chirico Date: Mon, 6 Nov 2023 10:00:34 -0500 Subject: [PATCH] Update Dockerfile --- Dockerfile | 67 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index f2c1ca2..f6e2cb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,38 @@ -# Stage 1: Install dependencies -# Use an official Node.js runtime as a parent image -FROM node:lts-alpine AS deps -# Set the working directory in the container to /opt/app -WORKDIR /opt/app -# Copy package.json and package-lock.json to the working directory -COPY package.json package-lock.json ./ -# Install production dependencies only -RUN npm ci --only=production +FROM node:lts-alpine -# Stage 2: Build the application -FROM node:lts-alpine AS builder -# Set environment variables -ENV NODE_ENV=production +LABEL name="Docusaurus on docker latest-stable" \ + maintainer="VolvoxLLC " \ + version="1.0.0" \ + release="latest" \ + url="https://github.com/VolvoxLLC/Volvox.Apollo.Docs" \ + summary="Docusaurus v3 for Docker \ + on Node 20.x, lts-alpine" \ + description="Volvox.Apollo Docs \ + on Node 20.x, lts-alpine" -WORKDIR /opt/app -# Copy all files from the current directory to the working directory in the container -COPY . . -# Copy node_modules from the "deps" stage -COPY --from=deps /opt/app/node_modules ./node_modules -# Build the application -RUN npm run build +# add curl for healthcheck +RUN apk add --no-cache --update \ + curl \ + libc6-compat -# Stage 3: Create the production image -FROM node:lts-alpine AS runner -# Set the working directory in the container to /opt/app -WORKDIR /opt/app -# Set environment variable -ENV NODE_ENV=production -# Copy necessary files from the "builder" stage -COPY --from=builder /opt/app/public ./public -COPY --from=builder /opt/app/next.config.js ./ -COPY --from=builder /opt/app/node_modules ./node_modules -# Define the command to run the application -CMD ["node_modules/.bin/next", "start"] +# run as our node user from base image +# we delete the dockerfiles we don't need +# this leaves us with a default v1 docusarus install +# we can mount our own into the container +USER node +RUN mkdir ~/npm-global \ + && npm config set prefix '~/npm-global' \ + && echo 'export PATH=~/npm-global/bin:$PATH' > ~/.profile \ + && mkdir -p /home/node/docs \ + && cd /home/node/docs \ + && npm install --global docusaurus-init \ + && sh -l -c docusaurus-init \ + && rm Dockerfile \ + && rm docker-compose.yml + +EXPOSE 5001/tcp +USER node +WORKDIR /home/node/docs + +CMD ["sh", "-l", "-c", "npm start"] +HEALTHCHECK CMD curl -f -L http://localhost:5001/ || exit 1