mnemo_cards/mnemo_cards_backend/Dockerfile
Dmitry bfc13ecfd5
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
server
2025-12-11 22:30:02 +03:00

70 lines
2.7 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# syntax=docker/dockerfile:1.7
# --- Build stage ------------------------------------------------------------
# Note: This Dockerfile should be built from the parent directory:
# docker build -f mnemo_cards_backend/Dockerfile -t mnemo_cards_backend .
FROM dart:stable-sdk AS build
WORKDIR /app
# Copy all sources at once (simpler and more efficient)
COPY mnemo_cards_common /app/mnemo_cards_common
COPY mnemo_cards_common_backend /app/mnemo_cards_common_backend
COPY mnemo_cards_backend /app/mnemo_cards_backend
# Get dependencies (path dependencies will resolve correctly)
WORKDIR /app/mnemo_cards_common
RUN dart pub get
WORKDIR /app/mnemo_cards_common_backend
RUN dart pub get
WORKDIR /app/mnemo_cards_backend
RUN dart pub get
# Compile to native executable
RUN dart compile exe lib/main.dart -o /app/server
# --- Runtime stage ----------------------------------------------------------
FROM debian:bookworm-slim AS runtime
WORKDIR /app
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates openssl curl wget \
&& rm -rf /var/lib/apt/lists/*
# App binary
COPY --from=build /app/server /app/server
# Static/assets needed at runtime
COPY --from=build /app/mnemo_cards_backend/public /app/public
COPY --from=build /app/mnemo_cards_backend/data /app/data
# Writable dirs for isar/backups by default
RUN mkdir -p /app/isar /app/backups && \
chmod -R 755 /app/isar /app/backups
ENV PORT=3000 \
SERVER_ADDRESS=0.0.0.0 \
ISAR_DIR=/app/isar \
BACKUP_DIR=/app/backups \
WORK_DIR=/app \
DEBUG=false \
CERTS_PATH= \
DUAL_MODE=false \
ADMIN_IDS=
EXPOSE 3000
# Healthcheck - проверка доступности сервера
# Increased start-period to 90s to allow server initialization (Isar DB, cron jobs, etc.)
# Isar может долго инициализироваться при первом запуске или при большом объеме данных
# Используем 127.0.0.1 для healthcheck (внутри контейнера работает даже если сервер слушает на 0.0.0.0)
# Сервер работает по HTTPS, поэтому проверяем https:// с флагом -k для игнорирования проверки сертификата
# Пробуем curl, если не работает - используем wget как fallback
HEALTHCHECK --interval=15s --timeout=10s --start-period=90s --retries=3 \
CMD curl -f -sS -k --max-time 8 --connect-timeout 3 https://127.0.0.1:${PORT:-3000}/health > /dev/null 2>&1 || \
wget --quiet --no-check-certificate --tries=1 --timeout=8 --spider https://127.0.0.1:${PORT:-3000}/health || exit 1
# Start server - все настройки читаются из environment variables
CMD ["/app/server"]