From 31d0cdeae0798657424c9e175c322bc7b60ef6e5 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelazim Date: Thu, 23 Oct 2025 22:02:48 +0300 Subject: [PATCH] feat: add Docker support and update README with usage instructions --- .dockerignore | 64 ++++++++++++++++++++++++++++++++++++++ Dockerfile | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 49 +++++++++++++++++++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..65c88d8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,64 @@ +# Dependencies +node_modules +**/node_modules +.pnp +.pnp.js + +# Testing +coverage +*.test.ts +*.test.js +*.spec.ts +*.spec.js +__tests__ +__mocks__ + +# Build outputs (we'll copy specific ones) +**/dist +**/build +**/.next +**/out +.turbo + +# Environment +.env +.env.local +.env.*.local + +# Git +.git +.gitignore +.gitattributes + +# IDE +.vscode +.idea +*.swp +*.swo +*~ +.DS_Store + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +lerna-debug.log* + +# Misc +.changeset +*.md +!README.md +LICENSE +CODEOWNERS + +# Development files +*.development.* +dev-* +tmp +temp + +# Docker +Dockerfile* +docker-compose* +.dockerignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e492273 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,85 @@ +# Stage 1: Base image with Bun and necessary tools +FROM oven/bun:1.2.19-alpine AS base + +WORKDIR /app + +RUN apk add --no-cache \ + openssl \ + postgresql-client \ + curl \ + nodejs + +# Stage 2: Install dependencies +FROM base AS dependencies + +WORKDIR /app + +COPY package.json bun.lock ./ + +# Copy package.json files for workspace packages +COPY packages/core/package.json ./packages/core/ +COPY packages/view/package.json ./packages/view/ +COPY www/package.json ./www/ + +# Install all dependencies +RUN bun install --frozen-lockfile + +# Stage 3: Build the view package +FROM dependencies AS build-view + +WORKDIR /app + +COPY --from=dependencies /app/node_modules ./node_modules +COPY packages/view ./packages/view + +RUN bun run --cwd packages/view build + +# Stage 4: Build the core package +FROM build-view AS build-core + +WORKDIR /app + +COPY scripts ./scripts + +COPY --from=build-view /app/node_modules ./node_modules +COPY packages/core ./packages/core + +RUN bun run --cwd packages/core build && bun run scripts/post-build.ts + +# Stage 5: Production image +FROM oven/bun:1.2.19-alpine AS production + +WORKDIR /app + +# Install only essential runtime dependencies +RUN apk add --no-cache openssl + +COPY package.json ./ +COPY packages/core/package.json ./packages/core/ +COPY www/package.json ./www/ + +# Install only production dependencies +RUN bun install --production --frozen-lockfile + +# Copy built artifacts from core package +COPY --from=build-core /app/packages/core/dist ./packages/core/dist +COPY --from=build-core /app/packages/core/view-build ./packages/core/view-build + +# Make the main entry point executable +RUN chmod +x ./packages/core/dist/index.js + +# Create global symlink for core package +RUN ln -s /app/packages/core/dist/index.js /usr/local/bin/hviz + +# Clean up build cache and temporary files +RUN rm -rf /tmp/* /root/.bun/install/cache + +# Set environment variable for production +ENV NODE_ENV=production \ + PORT=3333 + +# Expose necessary ports +EXPOSE 3333 + +ENTRYPOINT ["hviz"] +CMD [ "--help" ] \ No newline at end of file diff --git a/README.md b/README.md index 5542855..1018012 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,11 @@ npx hviz # Or with bunx bunx hviz + +# Or with Docker (no installation needed) +docker run --rm -p 3000:3333 \ + -v "$(pwd)/prisma":/app/prisma \ + hviz --type prisma --schema /app/prisma/schema.prisma ``` That's it! hviz will guide you through the rest with interactive prompts. @@ -50,6 +55,22 @@ npm install -D hviz bun install -D hviz ``` +### 🐳 Docker + +Use Docker without any local installation: + +```bash +# Build the image +docker build -t hviz . + +# Run with your schema +docker run --rm -p 3000:3333 \ + -v "$(pwd)/prisma":/app/prisma \ + hviz --type prisma --schema /app/prisma/schema.prisma +``` + +Then open your browser at `http://localhost:3000` + --- ## 🎯 Usage @@ -92,6 +113,34 @@ hviz --type typeorm --schema typeorm/schema.ts hviz --type prisma --schema prisma/schema.prisma --port 4000 ``` +### 🐳 Docker Usage + +Run HViz in Docker with different ORMs: + +```bash +# Prisma +docker run --rm -p 3000:3333 \ + -v "$(pwd)/prisma":/app/prisma \ + hviz --type prisma --schema /app/prisma/schema.prisma + +# Drizzle +docker run --rm -p 3000:3333 \ + -v "$(pwd)/drizzle":/app/drizzle \ + hviz --type drizzle --schema /app/drizzle/schema.ts + +# TypeORM +docker run --rm -p 3000:3333 \ + -v "$(pwd)/src/entities":/app/entities \ + hviz --type typeorm --schema /app/entities + +# Custom port +docker run --rm -p 8080:3333 \ + -v "$(pwd)/prisma":/app/prisma \ + hviz --type prisma --schema /app/prisma/schema.prisma +``` + +Access the visualization at `http://localhost:3000` (or at `http://localhost:{HOST_PORT}` if you specified a custom port, e.g., `http://localhost:8080`) + --- ## 🛠️ CLI Options