cms/strapi/Dockerfile

61 lines
1.4 KiB
Docker

FROM node:18-alpine as build
ARG APP_DIRECTORY
ARG NODE_ENV
# Set working directory
WORKDIR ${APP_DIRECTORY}
# Upgrade & install system dependencies
RUN apk update
RUN apk add --no-cache \
build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git \
> /dev/null 2>&1
# Copy dependency files
COPY package.json package-lock.json ./
# Install production dependencies
RUN npm config set registry https://registry.npmjs.org/
RUN npm install -g node-gyp
RUN npm ci --omit=dev --loglevel verbose
# Add node_modules/.bin to PATH
ENV PATH ${APP_DIRECTORY}/node_modules/.bin:$PATH
# Copy source files and build
WORKDIR ${APP_DIRECTORY}/app
COPY . .
RUN npm run build
FROM node:18-alpine as production
ARG APP_DIRECTORY
ARG NODE_ENV
ENV TIMEZONE "UTC"
# Set local timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
# Upgrade & install image processing dependency
RUN apk upgrade --no-cache && \
apk add --no-cache vips-dev
# Copy node_modules over to the parent directory
WORKDIR ${APP_DIRECTORY}
COPY --from=build ${APP_DIRECTORY}/node_modules ./node_modules
# Copy app files
WORKDIR ${APP_DIRECTORY}/app
COPY --from=build ${APP_DIRECTORY}/app .
# Add node_modules/.bin to PATH
ENV PATH ${APP_DIRECTORY}/node_modules/.bin:$PATH
# Set user and group rights
RUN chown -R node:node ${APP_DIRECTORY}/app
# Run as node
USER node
CMD ["npm", "run", "develop"]