diff --git a/deploy/docker/.dockerignore b/deploy/docker/.dockerignore new file mode 100644 index 000000000..6b097f475 --- /dev/null +++ b/deploy/docker/.dockerignore @@ -0,0 +1,70 @@ +node_modules +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.next/ +out/ +build/ +dist/ +.env +.env.local +.env.development.local +.env.test.local +.env.production.local +.vscode/ +.idea/ +*.swp +*.swo +*~ +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db +.git +.gitignore +.gitattributes +README.md +*.md +.github/ +.gitlab-ci.yml +.travis.yml +Dockerfile* +docker-compose*.yml +.dockerignore +coverage/ +.nyc_output +jest.config.js +cypress/ +cypress.json +.eslintrc* +.prettierrc* +.stylelintrc* +logs +*.log +pids +*.pid +*.seed +*.pid.lock +coverage +.nyc_output +jspm_packages/ +.npm +.eslintcache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ +.node_repl_history +*.tgz +.yarn-integrity +.cache +.parcel-cache +.next +.nuxt +.vuepress/dist +.serverless +.fusebox/ +.dynamodb/ \ No newline at end of file diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile new file mode 100644 index 000000000..a526638e8 --- /dev/null +++ b/deploy/docker/Dockerfile @@ -0,0 +1,51 @@ +FROM node:18-alpine AS deps + +RUN apk add --no-cache libc6-compat + +WORKDIR /app + +COPY ../../package*.json ./ +COPY ../../yarn.lock* ./ + +RUN if [ -f yarn.lock ]; then yarn install --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + else npm install; fi + +FROM node:18-alpine AS builder + +WORKDIR /app + +COPY --from=deps /app/node_modules ./node_modules +COPY ../../ . + +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 + +RUN if [ -f yarn.lock ]; then yarn build; \ + elif [ -f package-lock.json ]; then npm run build; \ + else npm run build; fi + +FROM node:18-alpine AS runner + +WORKDIR /app + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./package.json + +USER nextjs + +EXPOSE 3000 + +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 +ENV PORT=3000 + +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://localhost:3000 || exit 1 + +CMD ["npm", "start"] diff --git a/deploy/docker/README.md b/deploy/docker/README.md new file mode 100644 index 000000000..b79d90af5 --- /dev/null +++ b/deploy/docker/README.md @@ -0,0 +1,138 @@ +# Docker Deployment + +This directory contains Docker configuration files for deploying the Carbon app. + +## Prerequisites + +- Docker +- Docker Compose + +## Quick Start + +1. Clone the repository: +```bash +git clone https://github.com/carbon-app/carbon.git +cd carbon +``` + +2. Build and run: +```bash +cd deploy/docker +docker-compose up --build -d +``` + +3. Access the application at http://localhost:3000 + +## Files + +- `Dockerfile` - Multi-stage Docker build configuration +- `docker-compose.yml` - Container orchestration +- `.dockerignore` - Build context exclusions + +## Commands + +### Using Docker Compose + +Start the application: +```bash +docker-compose up -d +``` + +Build and start: +```bash +docker-compose up --build -d +``` + +View logs: +```bash +docker-compose logs -f carbon-app +``` + +Stop the application: +```bash +docker-compose down +``` + +### Using Docker directly + +Build image: +```bash +docker build -t carbon-app -f Dockerfile ../../ +``` + +Run container: +```bash +docker run -d --name carbon-app -p 3000:3000 carbon-app +``` + +## Configuration + +### Environment Variables + +Set in `docker-compose.yml`: +- `NODE_ENV` - Node.js environment (default: production) +- `NEXT_TELEMETRY_DISABLED` - Disable Next.js telemetry (default: 1) +- `PORT` - Application port (default: 3000) + +### Port Mapping + +Change the host port by modifying the ports section in `docker-compose.yml`: +```yaml +ports: + - "8080:3000" # Access via localhost:8080 +``` + +## Troubleshooting + +### Build Issues + +Increase Docker memory allocation if builds fail due to memory constraints. + +### Port Conflicts + +If port 3000 is in use, change the host port mapping in `docker-compose.yml`. + +### Container Health + +The container includes health checks. View status with: +```bash +docker-compose ps +``` + +### Logs + +View application logs: +```bash +docker-compose logs carbon-app +``` + +Follow logs in real-time: +```bash +docker-compose logs -f carbon-app +``` + +## Production + +For production deployments: + +1. Use a reverse proxy (nginx, traefik) +2. Configure proper logging +3. Set up monitoring and alerting +4. Use orchestration tools (Docker Swarm, Kubernetes) +5. Implement backup strategies + +## Updates + +To update the application: + +1. Pull latest changes: +```bash +git pull origin main +``` + +2. Rebuild and restart: +```bash +cd deploy/docker +docker-compose down +docker-compose up --build -d +``` \ No newline at end of file diff --git a/deploy/docker/docker-compose.yml b/deploy/docker/docker-compose.yml new file mode 100644 index 000000000..7e40dce81 --- /dev/null +++ b/deploy/docker/docker-compose.yml @@ -0,0 +1,21 @@ +version: '3.8' + +services: + carbon-app: + build: + context: ../../ + dockerfile: deploy/docker/Dockerfile + container_name: carbon-app + ports: + - "3000:3000" + environment: + - NODE_ENV=production + - NEXT_TELEMETRY_DISABLED=1 + - PORT=3000 + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s \ No newline at end of file