32694/Dockerfile.dev
2026-05-07 12:54:17 +03:00

95 lines
2.7 KiB
Docker

# Base image for Node.js dependencies
FROM node:20.19.0-alpine AS frontend-deps
RUN apk add --no-cache git
WORKDIR /app/frontend
COPY frontend/package.json frontend/yarn.lock ./
RUN yarn install --pure-lockfile
FROM node:20.19.0-alpine AS backend-deps
RUN apk add --no-cache git
WORKDIR /app/backend
COPY backend/package.json backend/yarn.lock ./
RUN yarn install --pure-lockfile
FROM node:20.19.0-alpine AS app-shell-deps
RUN apk add --no-cache git
WORKDIR /app/app-shell
COPY app-shell/package.json app-shell/yarn.lock ./
RUN yarn install --pure-lockfile
# Nginx setup and application build
FROM node:20.19.0-alpine AS build
RUN apk add --no-cache git nginx curl
RUN apk add --no-cache lsof procps
RUN yarn global add concurrently
RUN apk add --no-cache \
chromium \
nss \
freetype \
harfbuzz \
ttf-freefont \
fontconfig
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
RUN mkdir -p /app/pids
# Make sure to add yarn global bin to PATH
ENV PATH /root/.yarn/bin:/root/.config/yarn/global/node_modules/.bin:$PATH
# Copy dependencies
WORKDIR /app
COPY --from=frontend-deps /app/frontend /app/frontend
COPY --from=backend-deps /app/backend /app/backend
COPY --from=app-shell-deps /app/app-shell /app/app-shell
COPY frontend /app/frontend
COPY backend /app/backend
COPY app-shell /app/app-shell
COPY docker /app/docker
# Copy all files from root to /app
COPY . /app
# Copy Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Copy custom error page
COPY 502.html /usr/share/nginx/html/502.html
# Change owner and permissions of the error page
RUN chown nginx:nginx /usr/share/nginx/html/502.html && \
chmod 644 /usr/share/nginx/html/502.html
# Expose the port the app runs on
EXPOSE 8080
ENV NODE_ENV=dev_stage
ENV FRONT_PORT=3001
ENV BACKEND_PORT=3000
ENV APP_SHELL_PORT=4000
CMD ["sh", "-c", "\
set -e; \
echo 'Preparing repository before starting app processes...' ; \
yarn --cwd /app/app-shell init-repo; \
yarn --cwd /app/frontend dev & echo $! > /app/pids/frontend.pid; \
yarn --cwd /app/backend start & echo $! > /app/pids/backend.pid; \
APP_SHELL_SKIP_REPO_INIT=true yarn --cwd /app/app-shell start & echo $! > /app/pids/app-shell.pid; \
echo 'Waiting for frontend (port 3001) to be available...' ; \
while ! nc -z localhost ${FRONT_PORT}; do \
sleep 2; \
done; \
echo 'Waiting for backend (port 3000) to be available...' ; \
while ! nc -z localhost ${BACKEND_PORT}; do \
sleep 2; \
done; \
echo 'Waiting for app_shell (port 4000) to be available...' ; \
while ! nc -z localhost ${APP_SHELL_PORT}; do \
sleep 2; \
done; \
echo 'All app processes are up. Starting nginx...' ; \
exec nginx -g 'daemon off;'"]