schon/Dockerfiles/storefront.Dockerfile
Egor fureunoir Gorbunov b68911006b Features: 1) Add Dockerfile for building and running storefront application; 2) Introduce multi-stage build with separation of development and runtime environments; 3) Include environment variable management and non-root user setup;
Fixes: 1) Update dependencies in `package-lock.json` with the latest versions to address compatibility issues;

Extra: 1) Remove unused dependencies and redundant package references from `package-lock.json` for optimization; 2) Improve scripts and permission setups in Dockerfile for clarity and security.
2025-09-13 14:13:26 +03:00

36 lines
No EOL
1,010 B
Docker

# syntax=docker/dockerfile:1
FROM node:22-bookworm-slim AS build
WORKDIR /app
ENV NODE_ENV=development
COPY ./storefront/package.json ./storefront/package-lock.json ./
RUN npm ci --include=optional
COPY ./storefront ./
RUN npm run build
FROM node:22-bookworm-slim AS runtime
WORKDIR /app
ENV HOST=0.0.0.0
ENV PORT=3000
ENV NODE_ENV=production
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
RUN addgroup --system --gid 1001 nodeapp \
&& adduser --system --uid 1001 --ingroup nodeapp --home /home/nodeapp nodeapp
USER nodeapp
COPY --from=build /app/.output/ ./
RUN install -d -m 0755 -o nodeapp -g nodeapp /home/nodeapp \
&& printf '#!/bin/sh\nif [ \"$DEBUG\" = \"1\" ]; then export NODE_ENV=development; else export NODE_ENV=production; fi\nexec node /app/server/index.mjs\n' > /home/nodeapp/start.sh \
&& chown nodeapp:nodeapp /home/nodeapp/start.sh \
&& chmod +x /home/nodeapp/start.sh
USER nodeapp
CMD ["sh", "/home/nodeapp/start.sh"]