Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
node_modules
npm-debug.log
.env.local
.env.development.local
.env.test.local
.env.production.local
.git
.gitignore
README.md
LICENSE
.vscode
.nyc_output
coverage
.coverage
dist
build
*.log
.DS_Store
Thumbs.db
65 changes: 57 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,77 @@
FROM node:20-alpine
# Build stage
FROM node:20-alpine AS builder

# Install build dependencies for node-gyp
RUN apk add --no-cache python3 make g++
# Install build dependencies for node-gyp and native modules
RUN apk add --no-cache \
python3 \
py3-pip \
make \
g++ \
sqlite-dev \
pkgconfig

# Set environment variable for node-gyp to find Python
ENV PYTHON=/usr/bin/python3

# Install distutils for Python (required by node-gyp)
RUN pip3 install --break-system-packages setuptools

# Create working directory
WORKDIR /opt/app

# Copy dependency files
COPY package*.json ./
COPY babel.config.js tsconfig.json ./
COPY .env ./

# Install dependencies
RUN npm install
# Configure npm for better Docker builds
RUN npm config set unsafe-perm true

# Install all dependencies (including dev dependencies for build)
RUN npm ci

# Copy source
# Copy source code
COPY src ./src

# Build project
# Build the project
RUN npm run build

# Runtime stage
FROM node:20-alpine AS runtime

# Install runtime dependencies only
RUN apk add --no-cache \
python3 \
py3-pip \
sqlite

# Set environment variable for node-gyp to find Python
ENV PYTHON=/usr/bin/python3

# Install distutils for Python (required by some runtime native modules)
RUN pip3 install --break-system-packages setuptools

# Create working directory
WORKDIR /opt/app

# Copy package files
COPY package*.json ./

# Configure npm
RUN npm config set unsafe-perm true

# Install only production dependencies
RUN npm ci --only=production && npm cache clean --force

# Copy built application from builder stage
COPY --from=builder /opt/app/dist ./dist

# Copy other necessary files
COPY src/views ./src/views
COPY src/public ./src/public

# Copy .env file if it exists
COPY .env* ./

EXPOSE 3000

CMD ["npm", "start"]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"start": "node dist/index.js",
"build": "tsc",
"dev": "nodemon --exec ts-node src/index.ts",
"test": "tsc --noEmit && jest"
"test": "tsc --noEmit && jest",
"rebuild": "npm rebuild"
},
"author": "Emmo00",
"license": "MIT",
Expand Down