2.0.5 β’ Published 5 months ago
@nk11/tilt-ts v2.0.5
Tilt TypeScript
A TypeScript implementation of core Tilt.dev functionality for Kubernetes development workflows. This project brings Tilt's powerful development features to TypeScript environments with live updates, file syncing, and automated deployments.
π Features
- Docker Build Management - Automated image building and registry pushing
- Kubernetes Resource Management - YAML deployment and lifecycle management
- Live Updates - Real-time file syncing and command execution in running containers
- File Watching - Intelligent file change detection with pattern matching
- Hot Reloading - Instant feedback loop for development changes
- Dry Run Mode - Preview changes before applying them
- Multi-container Support - Handle complex multi-service applications
π Prerequisites
- Node.js 18+ or Bun runtime
- Docker with daemon running
- kubectl configured with cluster access
- Kubernetes cluster (local or remote)
- Container registry (like k3d registry or Docker Hub)
π οΈ Installation
# Clone the repository
git clone <repository-url>
cd tilt_ts
# Install dependencies (using Bun)
bun i @nk11/tilt-ts
# Or using npm
npm i @nk11/tilt-ts
βοΈ Configuration
Default Configuration
The tool uses these defaults (configurable via tiltfile.ts
):
- Docker Registry:
localhost:36269
(k3d default) - Kubernetes Context:
k3d-ecosys-local-dev
- Namespace:
eco-test
(auto-normalized toeco-test
)
Setting up k3d (Optional)
For local development with k3d:
# Create a k3d cluster with registry
k3d cluster create ecosys-local-dev --registry-create k3d-registry:0.0.0.0:36269
# Get cluster info
kubectl cluster-info
π Tiltfile Configuration
Create a tiltfile.ts
in your project root:
import { k8s_yaml } from "./src/k8s_yaml";
import { docker_build } from "./src/docker_build";
import { sync, run } from "./src/SYNC";
// Build Docker image with live updates
docker_build(
"myapp/frontend",
{
context: "./webapp",
dockerfile: "Dockerfile",
},
{
ignore: ["*.log", "node_modules", "*.test.js"],
live_update: [
// Sync source files to container
sync("src/**/*", "/app/src"),
sync("public/**/*", "/app/public"),
// Restart service when package.json changes
run("npm install", { trigger: ["package.json"] }),
// Reload server on code changes
run("pkill -f 'node.*server' && npm start &", {
trigger: ["src/**/*.js", "src/**/*.ts"],
}),
],
}
);
// Deploy Kubernetes resources
k8s_yaml("./k8s/");
// k8s_yaml(["./deployment.yaml", "./service.yaml"]); // Alternative
Live Update Options
Sync Steps
sync("local/path/**/*", "/container/path");
- Copies files from local filesystem to running container
- Supports glob patterns and wildcards
- Preserves directory structure
Run Steps
run("command to execute", { trigger: ["file/pattern"] });
- Executes commands inside the container
- Triggered by specific file changes
- Useful for recompiling, reloading, or restarting services
Ignore Patterns
{
ignore: ["*.log", "tmp/*", "node_modules", ".git/**"];
}
π Usage
Basic Commands
# Start development environment
bun run start
# or
bun run up
# Start without live updates
tilt up --no-dev
# Preview changes (dry run)
bun run dry-run
# Check current status
bun run status
# Validate configuration
bun run validate
# Stop and cleanup
bun run down
Advanced Usage
Custom Tiltfile Location
bun run tilt.ts -f ./custom/tiltfile.ts up
Environment-specific Configs
// tiltfile.production.ts
import { tiltConfig } from "./src/tiltState";
tiltConfig.setDockerRegistry("production-registry.io");
tiltConfig.setK8sContext("production-cluster");
tiltConfig.setK8sNamespace("production");
π Live Updates in Action
When you run tilt up
, the system:
- Builds Docker images defined in your Tiltfile
- Deploys Kubernetes resources to your cluster
- Watches for file changes in configured directories
- Syncs changed files directly to running containers
- Executes trigger commands when specific files change
Example Development Flow
# Start Tilt
$ bun run start
π Starting Tilt (dev mode)...
β
Pre-flight checks passed
π³ Building image: myapp/frontend
π¦ Tagged: localhost:36269/myapp/frontend:latest
βΈοΈ Applying: ./k8s/deployment.yaml
π Starting live updates for myapp/frontend...
β
Live updates active for myapp/frontend -> frontend-pod-xyz
π Development Mode Instructions:
- Edit files in your project directories
- Changes will be automatically synced to running containers
# Edit a file
$ echo "console.log('Updated!');" >> src/app.js
π File change: src/app.js
π Syncing src/app.js -> /app/src/app.js
β
Synced src/app.js -> /app/src/app.js
π Running command: npm restart
β
Command executed successfully
π Project Structure
tilt_ts/
βββ src/
β βββ docker_build.ts # Docker build configuration
β βββ k8s_yaml.ts # Kubernetes YAML handling
β βββ tiltEngine.ts # Main orchestration engine
β βββ liveUpdateManager.ts # Live update functionality
β βββ dockerManager.ts # Docker operations
β βββ kubernetesManager.ts # Kubernetes operations
β βββ stateAnalyzer.ts # Change detection
β βββ tiltState.ts # Configuration state
β βββ types.ts # TypeScript definitions
β βββ utils/
β βββ shellExecutor.ts # Shell command utilities
βββ example/ # Example application
β βββ Dockerfile
β βββ deployment.yaml
β βββ service.yaml
βββ tiltfile.ts # Main configuration
βββ tilt.ts # CLI entry point
βββ package.json
π§ API Reference
docker_build()
docker_build(imageName: string, buildContext: BuildContext, liveUpdates?: LiveUpdateConfig)
Parameters:
imageName
: Name for the Docker imagebuildContext
: Build configurationcontext
: Build context directorydockerfile
: Dockerfile path (default: "Dockerfile")build_args
: Build arguments
liveUpdates
: Live update configuration (optional)
k8s_yaml()
k8s_yaml(yamlPath: string | string[])
Parameters:
yamlPath
: Path to YAML file(s), directory, or glob pattern
Examples:
k8s_yaml("./deployment.yaml"); // Single file
k8s_yaml("./k8s/"); // Directory
k8s_yaml("./k8s/*.yaml"); // Glob pattern
k8s_yaml(["./deploy.yaml", "./svc.yaml"]); // Multiple files
Live Update Steps
sync()
sync(localPath: string, containerPath: string)
run()
run(command: string, options: { trigger: string[] })
π Troubleshooting
Common Issues
Docker Build Fails
# Check Docker daemon
docker info
# Verify registry connectivity
docker push localhost:36269/test:latest
Kubernetes Connection Issues
# Check current context
kubectl config current-context
# Test cluster connectivity
kubectl cluster-info
# Verify namespace
kubectl get namespaces
Live Updates Not Working
# Check pod status
kubectl get pods -n your-namespace
# View live update status
bun run status
# Check container logs
kubectl logs <pod-name> -n <namespace>
Debug Mode
Enable verbose logging:
DEBUG=1 bun run start
File Permissions
If sync operations fail, check container permissions:
# In your Dockerfile
RUN chmod -R 755 /app
USER 1000:1000 # Or appropriate user
π€ Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Development Setup
# Install dependencies
bun install
# Run tests
bun test
# Type checking
bun run type-check
# Linting
bun run lint
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Tilt.dev - Original inspiration and API design
- Kubernetes - Container orchestration
- Docker - Containerization platform
π Related Resources
Made with β€οΈ for Kubernetes developers