diff --git a/.dockerignore b/.dockerignore index 72e9aa4..96e50f4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,55 @@ -Dockerfile -.dockerignore +# dependencies node_modules -npm-debug.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# testing +coverage + +# next.js +.next/ +out/ +build +dist + +# misc +.DS_Store +*.pem + +# debug +*.log + +# local env files - DO NOT copy to container +.env +.env.local +.env.development +.env*.local + +# Only .env.production will be used in Docker +# vercel +.vercel + +# typescript +*.tsbuildinfo + +# git +.git +.gitignore README.md -.next -.git \ No newline at end of file +CONTRIBUTING.md +SECURITY.md +LICENSE + +# docker +Dockerfile +.dockerignore +docker-compose.yml + +# IDE +.vscode +.idea + +# GitHub +.github \ No newline at end of file diff --git a/.env.example b/.env.example index b3129cb..cdd577b 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,12 @@ -NODE_ENV=developmnet -ANALYZE=false \ No newline at end of file +# Environment +NODE_ENV=development + +# Build Analysis +ANALYZE=false + +# Telemetry (set to 1 to disable) +NEXT_TELEMETRY_DISABLED=1 + +# Add any other environment variables your app needs below +# NEXT_PUBLIC_API_URL= +# NEXT_PUBLIC_ANALYTICS_ID= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 287e11c..a76e8e3 100644 --- a/.gitignore +++ b/.gitignore @@ -33,7 +33,9 @@ yarn-error.log* # env files (can opt-in for committing if needed) .env -.env.local +.env*.local +.env.development +.env.production # vercel .vercel diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 38945d5..516a49f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,75 +70,6 @@ Please ensure that: This helps us keep the `main` branch stable and production-ready. -## Folder Structure - -```bash -NURUI/ -├── .github/ -├── .next/ -├── .vercel/ -├── .vscode/ -├── node_modules/ -├── public/ -├── src/ -│ ├── app/ -│ │ ├── (docs)/ -│ │ ├── about-us/ -│ │ ├── playground/ -│ │ ├── favicon.ico -│ │ ├── globals.css -│ │ ├── layout.tsx -│ │ ├── MainContent.tsx -│ │ ├── page.tsx -│ │ └── ThemeProvider.tsx -│ ├── cli/ -│ │ ├── bin/ -│ │ └── node_modules/ -│ │ ├── README.md -│ │ ├── .npmignore -│ │ ├── package-lock.json -│ │ └── package.json -│ └── components/ -│ ├── common/ -│ ├── icons/ -│ ├── nurui/ -│ ├── pages/ -│ └── ui/ -├── content/ -├── docs/ -├── context/ -├── hooks/ -├── layout/ -├── lib/ -├── registry/ -│ ├── ComponentNavigation.tsx -│ └── componentsRegistry.tsx -├── styles/ -├── types/ -├── utils/ -├── .gitignore -├── .prettierrc.json -├── CONTRIBUTING.md -├── custom.d.ts -├── eslint.config.mjs -├── LICENSE -├── mdx-components.tsx -├── next-env.d.ts -├── next.config.ts -├── nurui-logo.png -├── og-image.png -├── package.json -├── postcss.config.mjs -├── README.md -├── registry-cli.json -├── registry.json -├── SECURITY.md -├── tailwind.config.ts -├── tailwindcss.d.ts -├── tsconfig.json -└── yarn.lock -``` - ## How to Add a New Component to Nurui Follow these 7 simple steps to add a new UI component to the library. diff --git a/Dockerfile b/Dockerfile index 050521b..e6e1022 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,56 +1,58 @@ -FROM ubuntu - +# Use Node.js 20 Alpine as base image FROM node:20-alpine AS base # Install dependencies only when needed FROM base AS deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. RUN apk add --no-cache libc6-compat WORKDIR /app -# Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./ -RUN \ - if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ - elif [ -f package-lock.json ]; then npm ci; \ - elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ - else echo "Lockfile not found." && exit 1; \ - fi +# Copy package files +COPY package.json yarn.lock* ./ +# Install dependencies with yarn +RUN yarn install --frozen-lockfile # Rebuild the source code only when needed FROM base AS builder WORKDIR /app + +# Copy node_modules from deps stage COPY --from=deps /app/node_modules ./node_modules + +# Copy all source files COPY . . -# Next.js collects completely anonymous telemetry data about general usage. -# Learn more here: https://nextjs.org/telemetry -# Uncomment the following line in case you want to disable telemetry during the build. -# ENV NEXT_TELEMETRY_DISABLED=1 +# Set build-time environment variables +ARG NODE_ENV=production +ARG ANALYZE=false +ENV NODE_ENV=${NODE_ENV} +ENV ANALYZE=${ANALYZE} +ENV NEXT_TELEMETRY_DISABLED=1 -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 +# Build the application +RUN yarn build # Production image, copy all the files and run next FROM base AS runner WORKDIR /app +# Set runtime environment variables ENV NODE_ENV=production -# Uncomment the following line in case you want to disable telemetry during runtime. -# ENV NEXT_TELEMETRY_DISABLED=1 +ENV NEXT_TELEMETRY_DISABLED=1 +ENV ANALYZE=false +# Create a non-root user RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs +# Copy necessary files COPY --from=builder /app/public ./public +# Set the correct permission for prerender cache +RUN mkdir .next +RUN chown nextjs:nodejs .next + # Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static @@ -59,8 +61,6 @@ USER nextjs EXPOSE 3000 ENV PORT=3000 - -# server.js is created by next build from the standalone output -# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output ENV HOSTNAME="0.0.0.0" + CMD ["node", "server.js"] \ No newline at end of file diff --git a/README.md b/README.md index 171688e..a62465a 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,58 @@ Visit https://nurui.vercel.app/docs/installation to view the documentation. -## 🛠️ Project Setup +## 🚀 Quick Start + +### Option 1: Using Docker (Recommended for Production) + +Prerequisite: Docker & Docker Compose installed. ```bash # 1. Clone the repository git clone https://github.com/afsar-dev/Nurui.git cd Nurui -# 2. Create a .env file in the root directory and add: -NODE_ENV=development +# 2. Create production environment file +cat .env.production +# The project uses the existing .env.production file. +# You can modify it if needed. + +# 3. Build and start with Docker Compose +yarn docker:compose:up +# Or manually: +docker compose up -d + +# The production application will be available at http://localhost:3000 +``` + +### Option 1.1 — Run With Docker (Without Compose) + +If you prefer to run Nurui using standard Docker commands: + +```bash +# 1. Build Docker Image +yarn docker:build +# Or manually: +docker build -t nurui:latest . + +# 2. Run Container +yarn docker:run +# Or manually: +docker run -d \ --name nurui \ -p 3000:3000 \ --env-file .env.production \ nurui:latest +``` + +### Option 2: Local Development Setup + +```bash +# 1. Clone the repository +git clone https://github.com/afsar-dev/Nurui.git +cd Nurui + +# 2. Create a .env.development file (or .env) file in the root directory +cat .env + +# Add to .env file: +# NODE_ENV=development # 3. Install dependencies yarn install @@ -33,9 +76,22 @@ yarn dev # The application will be available at http://localhost:3000 ``` - +```bash +NODE_ENV=production +ANALYZE=false +NEXT_TELEMETRY_DISABLED=1 +``` + +For local Development (.env or .env.development): + +``` +NODE_ENV=development +ANALYZE=false +``` ## License diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f523044 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +services: + nurui: + image: nurui:latest + build: + context: . + dockerfile: Dockerfile + args: + - NODE_ENV=production + container_name: nurui-app + ports: + - "3000:3000" + env_file: + - .env.production + environment: + - NODE_ENV=production + - NEXT_TELEMETRY_DISABLED=1 + - ANALYZE=false + restart: unless-stopped + networks: + - nurui-network + +networks: + nurui-network: + driver: bridge diff --git a/next.config.ts b/next.config.ts index e16223b..a83a439 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,6 +1,6 @@ -import type { NextConfig } from "next"; -import createMDX from "@next/mdx"; import withBundleAnalyzer from "@next/bundle-analyzer"; +import createMDX from "@next/mdx"; +import type { NextConfig } from "next"; const isAnalyzerEnabled = process.env.ANALYZE === "true"; @@ -9,6 +9,7 @@ const analyzer = withBundleAnalyzer({ }); const nextConfig: NextConfig = { + output: "standalone", images: { remotePatterns: [ { diff --git a/package.json b/package.json index 4d296ee..1ff7dba 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,21 @@ "build": "next build", "start": "next start", "lint": "next lint", - "analyze": "cross-env ANALYZE=true next build" + "analyze": "cross-env ANALYZE=true next build", + "docker:build": "docker build -t nurui:latest .", + "docker:run": "docker run -d -p 3000:3000 --name nurui-container --env-file .env.production nurui:latest", + "docker:stop": "docker stop nurui-container && docker rm nurui-container", + "docker:logs": "docker logs -f nurui-container", + "docker:restart": "yarn docker:stop && yarn docker:build && yarn docker:run", + "docker:compose:up": "docker compose up -d", + "docker:compose:build": "docker compose build", + "docker:compose:rebuild": "docker compose up -d --build", + "docker:compose:down": "docker compose down", + "docker:compose:restart": "docker compose restart", + "docker:compose:logs": "docker compose logs -f", + "docker:compose:ps": "docker compose ps", + "docker:clean": "docker system prune -af", + "docker:clean:all": "docker compose down && docker system prune -af --volumes" }, "dependencies": { "@gsap/react": "^2.1.2",