-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
35227e2
commit 2c1ad3a
Showing
1 changed file
with
35 additions
and
32 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 |
---|---|---|
@@ -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 <[email protected]>" \ | ||
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 |