feat: new fixed Dockerfiles for deployment in separate folders, docker compose for composing the stack

This commit is contained in:
theoleuthardt 2025-02-15 11:19:44 +01:00
parent 6767782613
commit be3ab2bcaf
4 changed files with 91 additions and 13 deletions

54
backend/Dockerfile Normal file
View file

@ -0,0 +1,54 @@
# Basis-Image
FROM node:18-alpine AS base
# Install system dependencies
RUN apk add --no-cache libc6-compat libreoffice ttf-liberation
WORKDIR /app
# Dependencies installieren
FROM base AS deps
COPY package.json package-lock.json* yarn.lock* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn install --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm install --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Build stage
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . /app
RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi
# Production image
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 fastify
# Copy built application
COPY --from=builder --chown=fastify:nodejs /app/dist ./dist
COPY --from=deps --chown=fastify:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=fastify:nodejs /app/package.json ./package.json
USER fastify
EXPOSE 4000
ENV PORT=4000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "dist/server.js"]

View file

@ -3,7 +3,7 @@
"target": "ES6",
"module": "CommonJS",
"outDir": "./dist",
"rootDir": "./src",
"rootDir": ".",
"strict": true,
"allowSyntheticDefaultImports": true
}