diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..70f7c47 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,40 @@ +# Git +.git +.gitignore +.gitattributes + +# Dependencies +node_modules +npm-debug.log +yarn-error.log +pnpm-debug.log + +# Build output +.nuxt +dist +.output +build + +# IDE +.vscode +.idea +*.swp +*.swo +*~ +.DS_Store + +# Environment +.env +.env.local +.env.*.local + +# OS +Thumbs.db + +# Tests +coverage +.nyc_output + +# Documentation +README.md +docs diff --git a/.gitignore b/.gitignore index 97e75a5..ef319dd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,4 @@ node_modules .cache .output .env -dist -Dockerfile -docker-compose.yml \ No newline at end of file +dist \ No newline at end of file diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000..93e91f5 --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,150 @@ +# Docker Setup untuk Healthcare Admin Dashboard + +## Deskripsi +File-file Docker ini memungkinkan Anda menjalankan aplikasi Nuxt 3 healthcare admin dashboard dalam kontainer Docker. + +## File-file yang Dibuat + +1. **Dockerfile** - Production-ready multistage build +2. **Dockerfile.dev** - Development Dockerfile dengan hot-reload +3. **docker-compose.yml** - Orchestration untuk production dan development +4. **.dockerignore** - Files yang akan diabaikan saat build + +## Cara Penggunaan + +### 1. Production Build & Run + +#### Menggunakan Docker: +```bash +# Build image +docker build -t healthcare-app . + +# Run container +docker run -p 3000:3000 \ + -e NODE_ENV=production \ + -e AUTH_ORIGIN=http://localhost:3005 \ + healthcare-app +``` + +#### Menggunakan Docker Compose: +```bash +# Build dan run +docker-compose up + +# Run di background +docker-compose up -d + +# Stop +docker-compose down +``` + +### 2. Development Mode + +#### Menggunakan Docker Compose dengan dev profile: +```bash +# Run development container +docker-compose --profile dev up app-dev + +# Run di background +docker-compose --profile dev up -d app-dev + +# View logs +docker-compose --profile dev logs -f app-dev + +# Stop +docker-compose --profile dev down +``` + +#### Menggunakan Docker Compose untuk development dengan hot-reload: +```bash +# Build dev image +docker build -f Dockerfile.dev -t healthcare-app-dev . + +# Run dengan volume mounting untuk hot-reload +docker run -p 3030:3030 \ + -v $(pwd):/app \ + -v /app/node_modules \ + -e NODE_ENV=development \ + healthcare-app-dev +``` + +## Environment Variables + +Konfigurasi environment variables sesuai kebutuhan: + +- `NODE_ENV` - `production` atau `development` (default: production) +- `HOST` - Hostname untuk bind (default: 0.0.0.0) +- `PORT` - Port server (default: 3000 untuk production, 3030 untuk dev) +- `AUTH_ORIGIN` - URL auth server (default: http://localhost:3005) + +### Mengatur Environment di docker-compose.yml: +```yaml +environment: + - NODE_ENV=production + - AUTH_ORIGIN=http://your-auth-server:3005 +``` + +Atau melalui `.env` file: +```bash +# Create .env file di project root +echo "AUTH_ORIGIN=http://localhost:3005" > .env +``` + +## Build & Push ke Registry (Opsional) + +```bash +# Build dengan tag +docker build -t your-registry/healthcare-app:latest . + +# Push ke registry +docker push your-registry/healthcare-app:latest + +# Run dari registry +docker run -p 3000:3000 your-registry/healthcare-app:latest +``` + +## Troubleshooting + +### Container gagal start +```bash +# Check logs +docker logs + +# Run dengan interactive terminal +docker run -it -p 3000:3000 healthcare-app sh +``` + +### Port sudah terpakai +```bash +# Gunakan port yang berbeda +docker run -p 8000:3000 healthcare-app +``` + +### Hot-reload tidak berfungsi di development +Pastikan volume mounting sudah di-setup dengan benar: +```bash +docker run -p 3030:3030 \ + -v $(pwd):/app \ + -v /app/node_modules \ + healthcare-app-dev +``` + +## Performance & Best Practices + +1. **Multi-stage build** digunakan untuk mengecilkan ukuran final image +2. **Dumb-init** digunakan untuk signal handling yang proper +3. **.dockerignore** yang optimal untuk mempercepat build +4. Volume mounting untuk development mode dengan hot-reload + +## Spesifikasi + +- **Base Image**: Node.js 20 Alpine (lightweight) +- **Production Port**: 3000 +- **Development Port**: 3030 +- **Package Manager**: npm atau yarn + +## Notes + +- Pastikan Docker dan Docker Compose sudah terinstall +- Untuk Windows, gunakan WSL2 Docker backend +- AUTH_ORIGIN perlu disesuaikan dengan environment/server Anda diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e60e2d2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# Development Dockerfile +FROM node:20-alpine + +WORKDIR /app + +# Install basic tools +RUN apk add --no-cache git + +# Copy package files +COPY package.json yarn.lock* package-lock.json* ./ + +# Install dependencies +RUN npm install --frozen-lockfile || yarn install --frozen-lockfile + +# Copy source code +COPY . . + +# Expose dev port +EXPOSE 3030 + +# Run development server +CMD ["npm", "run", "dev"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ba97646 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "3030:3030" + environment: + - NODE_ENV=production + - HOST=0.0.0.0 + - PORT=3030 + - AUTH_ORIGIN=http://localhost:3005 + restart: unless-stopped + container_name: general-template-app \ No newline at end of file diff --git a/package.json b/package.json index 724eb4e..d0a0eac 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "private": true, "scripts": { "build": "nuxt build", - "dev": "nuxt dev -o --host --port 3005", + "dev": "nuxt dev -o --host --port 3030", "generate": "nuxt generate", "preview": "nuxt preview", "postinstall": "nuxt prepare"