Skip to content
Open
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
70 changes: 70 additions & 0 deletions deploy/docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -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/
51 changes: 51 additions & 0 deletions deploy/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
138 changes: 138 additions & 0 deletions deploy/docker/README.md
Original file line number Diff line number Diff line change
@@ -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
```
21 changes: 21 additions & 0 deletions deploy/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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