Deploying Bit
Introduction
Bit is a platform for component-driven development that enables teams to build, version, and share reusable components across projects. It provides tools for developing, testing, and documenting components in isolation, then publishing them for use anywhere.
With Bit, you can extract components from existing projects, develop them independently, and share them across your organization. This approach promotes code reuse, consistency, and faster development cycles.
Key highlights of Bit:
- Component Isolation: Develop and test components independently
- Version Control: Semantic versioning for components
- Component Discovery: Browse and search available components
- Live Documentation: Auto-generated component documentation
- Dependency Management: Automatic dependency resolution
- CI/CD Integration: Build and test components automatically
- Team Collaboration: Shared component libraries
- Framework Agnostic: Works with React, Vue, Angular, and more
- Component Compositions: Preview components in different contexts
- Local Development: Full development environment
This guide walks through deploying a self-hosted Bit server on Klutch.sh using Docker.
Why Deploy Bit on Klutch.sh
Deploying Bit on Klutch.sh provides several advantages:
Private Components: Keep proprietary components on your infrastructure.
Team Access: Share components across your organization securely.
HTTPS by Default: Secure component access with automatic SSL.
Persistent Storage: Reliable storage for component packages.
Custom Registry: Your own npm-compatible component registry.
GitHub Integration: Automatic deployments from your repository.
Prerequisites
Before deploying Bit on Klutch.sh, ensure you have:
- A Klutch.sh account
- A GitHub account with a repository for your configuration
- Basic understanding of Docker and containerization
- Familiarity with component-driven development
- Node.js development experience
Understanding Bit Architecture
Bit consists of several components:
Bit CLI: Command-line tool for component development.
Bit Server: Registry for storing and serving components.
Scope: Collection of related components.
Workspace: Local development environment for components.
Preparing Your Repository
Create a GitHub repository for your Bit server deployment.
Repository Structure
bit-deploy/├── Dockerfile├── config/│ └── bit.config.json└── .dockerignoreCreating the Dockerfile
Create a Dockerfile for Bit server:
FROM node:18-alpine
# Install dependenciesRUN apk add --no-cache git python3 make g++
# Install BitRUN npm install -g @teambit/bvm && bvm install
# Create directoriesWORKDIR /opt/bitRUN mkdir -p /opt/bit/scopes
# Environment variablesENV BIT_HOME=/opt/bitENV BIT_REGISTRY_PORT=3000ENV BIT_TOKEN=${BIT_TOKEN}
# Expose ports# RegistryEXPOSE 3000# UIEXPOSE 4000
# Volume for scopesVOLUME ["/opt/bit/scopes"]
# Start Bit serverCMD ["bit", "start", "--port", "3000"]Environment Variables Reference
| Variable | Required | Default | Description |
|---|---|---|---|
BIT_TOKEN | Yes | - | Authentication token for registry access |
BIT_REGISTRY_PORT | No | 3000 | Port for component registry |
BIT_HOME | No | /opt/bit | Bit home directory |
Deploying Bit on Klutch.sh
- Select HTTP as the traffic type
- Set the internal port to 3000
Generate Authentication Token
Create a secure token for registry authentication:
openssl rand -hex 32Push Your Repository to GitHub
Initialize and push your configuration to GitHub.
Create a New Project on Klutch.sh
Navigate to the Klutch.sh dashboard and create a new project named “bit” or “components”.
Create a New App
Within your project, create a new app and connect your GitHub repository.
Configure HTTP Traffic
Set up HTTP for the registry and UI:
Set Environment Variables
Configure the following:
| Variable | Value |
|---|---|
BIT_TOKEN | Your generated token |
Attach Persistent Volumes
Add storage for component scopes:
| Mount Path | Recommended Size | Purpose |
|---|---|---|
/opt/bit/scopes | 20 GB | Component packages and metadata |
Deploy Your Application
Click Deploy to build and start Bit server.
Access Your Registry
Once deployment completes, access the UI at https://your-app-name.klutch.sh.
Using Bit
Installing Bit CLI
Install the Bit CLI locally:
npm install -g @teambit/bvmbvm installConfiguring Registry
Point Bit to your self-hosted registry:
bit config set registry.url https://your-bit-server.klutch.shbit config set user.token YOUR_BIT_TOKENCreating a Workspace
Initialize a new Bit workspace:
bit init --harmonyAdding Components
Add existing code as components:
bit add src/components/buttonDeveloping Components
Start the development server:
bit startPublishing Components
Export components to your server:
bit tag --allbit exportComponent Development
Component Structure
Organize components with:
- Component code (
.tsx,.vue, etc.) - Tests (
*.spec.tsx) - Documentation (
*.docs.mdx) - Compositions (
*.compositions.tsx)
Writing Tests
Add tests for components:
import { render } from '@testing-library/react';import { Button } from './button';
it('should render correctly', () => { const { getByText } = render(<Button>Click me</Button>); expect(getByText('Click me')).toBeTruthy();});Documenting Components
Create documentation with MDX:
---description: A reusable button component---
import { Button } from './button';
## Usage
<Button>Click me</Button>Team Collaboration
Creating Scopes
Organize components into scopes:
- Create scope on your server
- Configure scope in workspace
- Export components to scope
Access Control
Manage team access:
- Token-based authentication
- Scope-level permissions
- Read/write access control
Importing Components
Install components in projects:
bit install @your-org/ui.buttonOr use npm:
npm install @your-org/ui.buttonTroubleshooting Common Issues
Export Fails
Solutions:
- Verify registry URL is correct
- Check authentication token
- Review component tag status
Component Not Found
Solutions:
- Confirm component was exported
- Verify scope name is correct
- Check registry connectivity
Build Errors
Solutions:
- Run
bit compileto check for errors - Verify all dependencies are available
- Review component configuration
Additional Resources
Conclusion
Deploying Bit on Klutch.sh enables your team to build, share, and reuse components across projects with a private component registry. With isolated development, automatic documentation, and seamless collaboration features, Bit transforms how teams approach component-driven development.