diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a4a9e69 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +# Filaprint - Development and build files +node_modules +.git +.gitignore +*.md +.env +.env.* +!.env.example + +# IDE +.vscode +.idea + +# OS +.DS_Store +Thumbs.db + +# Debug logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Test files +__tests__ +*.test.ts +*.spec.ts + +# Build cache +.svelte-kit +.turbo diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..be1336b --- /dev/null +++ b/.env.example @@ -0,0 +1,12 @@ +# MongoDB Connection +MONGODB_URI=mongodb://admin:changeme@mongodb:27017/filaprint?authSource=admin + +# JWT Secret for authentication (generate a random string) +JWT_SECRET=your-super-secret-jwt-key-change-this + +# MongoDB Container Credentials +MONGO_USER=admin +MONGO_PASSWORD=changeme + +# Application Origin (for CSRF protection) +ORIGIN=http://localhost:3000 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..380f4e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,58 @@ +# Build stage +FROM oven/bun:1 AS builder + +WORKDIR /app + +# Copy package files +COPY package.json bun.lock* ./ + +# Install dependencies +RUN bun install --frozen-lockfile + +# Copy source code +COPY . . + +# Build the application +RUN bun run build + +# Production stage +FROM oven/bun:1-slim AS production + +WORKDIR /app + +# Copy package files for production dependencies +COPY package.json bun.lock* ./ + +# Install only production dependencies +RUN bun install --frozen-lockfile --production + +# Copy built application from builder stage +COPY --from=builder /app/build ./build +COPY --from=builder /app/server ./server + +# Create uploads directory for 3D models +RUN mkdir -p /app/static/uploads/models + +# Copy static files +COPY --from=builder /app/static ./static + +# Set environment variables +ENV NODE_ENV=production +ENV PORT=3000 + +# Expose the port +EXPOSE 3000 + +# Create a non-root user +RUN addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 filaprint && \ + chown -R filaprint:nodejs /app + +USER filaprint + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:3000/ || exit 1 + +# Start the application +CMD ["bun", "run", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..33a24b2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +services: + filaprint: + build: . + container_name: filaprint + restart: unless-stopped + ports: + - "3000:3000" + environment: + - NODE_ENV=production + - MONGODB_URI=${MONGODB_URI} + - JWT_SECRET=${JWT_SECRET} + - ORIGIN=${ORIGIN:-http://localhost:3000} + volumes: + # Persist uploaded 3D models + - ./data/uploads:/app/static/uploads + depends_on: + - mongodb + networks: + - filaprint-network + + mongodb: + image: mongo:7 + container_name: filaprint-mongo + restart: unless-stopped + environment: + - MONGO_INITDB_ROOT_USERNAME=${MONGO_USER:-admin} + - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD:-changeme} + volumes: + - mongodb_data:/data/db + networks: + - filaprint-network + # Uncomment to expose MongoDB port for debugging + # ports: + # - "27017:27017" + +networks: + filaprint-network: + driver: bridge + +volumes: + mongodb_data: