59 lines
1.3 KiB
Docker
59 lines
1.3 KiB
Docker
# Build stage
|
|
FROM node:18-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
COPY yarn.lock* ./
|
|
|
|
# Install all dependencies (including dev for build)
|
|
RUN yarn install --frozen-lockfile && yarn cache clean
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN yarn build
|
|
|
|
# Clean dev dependencies
|
|
RUN yarn install --production --frozen-lockfile
|
|
|
|
# Production stage
|
|
FROM node:18-alpine AS production
|
|
|
|
# Install ffmpeg from Alpine packages (architecture-aware)
|
|
RUN apk update && apk add --no-cache ffmpeg
|
|
|
|
# Set ffmpeg paths
|
|
ENV FFMPEG_PATH=/usr/bin/ffmpeg
|
|
ENV FFPROBE_PATH=/usr/bin/ffprobe
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy built application and dependencies
|
|
COPY --from=builder /app/dist ./dist
|
|
COPY --from=builder /app/node_modules ./node_modules
|
|
COPY --from=builder /app/public ./public
|
|
COPY --from=builder /app/package*.json ./
|
|
|
|
# Create necessary directories
|
|
RUN mkdir -p downloads database
|
|
|
|
# Create non-root user
|
|
RUN addgroup -g 1001 -S nodejs
|
|
RUN adduser -S quixotic -u 1001
|
|
|
|
# Change ownership of app directory
|
|
RUN chown -R quixotic:nodejs /app
|
|
USER quixotic
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD node -e "require('http').get('http://localhost:3000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
|
|
|
|
# Start the application
|
|
CMD ["node", "dist/server.js"] |