-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (38 loc) · 1.36 KB
/
Copy pathDockerfile
File metadata and controls
51 lines (38 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Stage 1: Builder stage (full build environment)
FROM node:22-slim AS builder
LABEL org.opencontainers.image.title="AuthCompanion"
LABEL org.opencontainers.image.version="5.0.0-beta.1"
LABEL org.opencontainers.image.description="An admin-friendly, User Management Server (with Passkeys & JWTs)"
LABEL org.opencontainers.image.authors="Paul Fischer"
LABEL org.opencontainers.image.source=https://github.com/authcompanion/authcompanion2
WORKDIR /app
# Copy package files first for caching
COPY package*.json ./
# Install all dependencies including devDependencies
RUN npm install --include=dev
# Copy all project files
COPY . .
# Build the application
RUN npm run build
# Stage 2: Production stage (lean image)
FROM node:22-slim
# Create non-root user and set directory permissions
RUN groupadd -r nodejs && \
useradd -g nodejs -s /bin/bash -d /home/nodejs -m nodejs && \
mkdir -p /home/nodejs/app && \
chown -R nodejs:nodejs /home/nodejs/app
RUN mkdir -p /data && \
chown nodejs:nodejs /data && \
chmod 755 /data
WORKDIR /home/nodejs/app
# Copy application files with correct ownership
COPY --from=builder --chown=nodejs:nodejs /app .
# Set environment variables directly in Dockerfile
ENV NODE_ENV=production
ENV NPM_CONFIG_LOGLEVEL=warn
# Final cleanup
RUN npm prune --omit=dev && \
npm cache clean --force
USER nodejs
EXPOSE 3002
CMD [ "node", "server.js" ]