This document provides detailed instructions for setting up and running the Container Engine project locally.
Before you begin, ensure you have the following installed:
- Rust (1.70 or later) - Install from rustup.rs
- Docker and Docker Compose - For running PostgreSQL and Redis
- Git - For version control
git clone https://github.com/ngocbd/Open-Container-Engine.git
cd Open-Container-EngineCopy the example environment file and update it:
cp .env.example .envEdit .env to customize settings if needed. The defaults should work for local development.
Using Docker Compose, start PostgreSQL and Redis:
docker-compose up postgres redis -dThis will start:
- PostgreSQL on port 5432
- Redis on port 6379
# Install dependencies
cargo build
# Set up the database (requires DATABASE_URL)
export DATABASE_URL="postgresql://postgres:password@localhost:5432/container_engine"
# Run database migrations
cargo install sqlx-cli
sqlx migrate runTo enable offline compilation without a database connection:
cargo sqlx preparecargo runThe API server will start on http://localhost:3000.
Check if the server is running:
curl http://localhost:3000/healthExpected response:
{
"status": "healthy",
"service": "container-engine",
"version": "0.1.0"
}For a complete development environment:
# Start all services (PostgreSQL, Redis, and the API)
docker-compose up --build
# Or run in the background
docker-compose up -d --build# Apply all pending migrations
sqlx migrate run
# Create a new migration
sqlx migrate add <migration_name>
# Revert the last migration
sqlx migrate revert# Stop the database
docker-compose stop postgres
# Remove the database volume
docker-compose rm -f postgres
docker volume rm open-container-engine_postgres_data
# Restart and run migrations
docker-compose up postgres -d
sqlx migrate runsrc/
├── main.rs # Application entry point
├── config.rs # Configuration management
├── database.rs # Database connection and setup
├── error.rs # Error handling and types
├── auth/ # Authentication and authorization
│ ├── mod.rs
│ ├── models.rs # User and API key models
│ ├── jwt.rs # JWT token management
│ └── middleware.rs # Authentication middleware
├── user/ # User profile management
│ ├── mod.rs
│ └── models.rs
├── deployment/ # Container deployment management
│ ├── mod.rs
│ └── models.rs
└── handlers/ # HTTP request handlers
├── mod.rs
├── auth.rs # Authentication endpoints
├── user.rs # User management endpoints
└── deployment.rs # Deployment endpoints
# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test module
cargo test auth# Format code
cargo fmt
# Check for linting issues
cargo clippy
# Check compilation without building
cargo checkThe API provides the following main endpoints:
POST /v1/auth/register- Register a new userPOST /v1/auth/login- Login and get tokensPOST /v1/auth/refresh- Refresh access tokenPOST /v1/auth/logout- Logout
GET /v1/api-keys- List API keysPOST /v1/api-keys- Create API keyDELETE /v1/api-keys/{id}- Revoke API key
GET /v1/user/profile- Get user profilePUT /v1/user/profile- Update profilePUT /v1/user/password- Change password
GET /v1/deployments- List deploymentsPOST /v1/deployments- Create deploymentGET /v1/deployments/{id}- Get deployment detailsPUT /v1/deployments/{id}- Update deploymentDELETE /v1/deployments/{id}- Delete deploymentPATCH /v1/deployments/{id}/scale- Scale deploymentPOST /v1/deployments/{id}/start- Start deploymentPOST /v1/deployments/{id}/stop- Stop deployment
For detailed API documentation, see APIs.md.
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgresql://postgres:password@localhost:5432/container_engine |
REDIS_URL |
Redis connection string | redis://localhost:6379 |
PORT |
Server port | 3000 |
JWT_SECRET |
JWT signing secret | your-super-secret-jwt-key-change-this-in-production |
JWT_EXPIRES_IN |
JWT expiration time (seconds) | 3600 |
API_KEY_PREFIX |
API key prefix | ce_api_ |
KUBERNETES_NAMESPACE |
Kubernetes namespace | container-engine |
DOMAIN_SUFFIX |
Domain suffix for deployments | container-engine.app |
RUST_LOG |
Logging level | container_engine=debug,tower_http=debug |
-
Ensure PostgreSQL is running:
docker-compose ps postgres
-
Check database logs:
docker-compose logs postgres
-
Test connection manually:
psql postgresql://postgres:password@localhost:5432/container_engine
-
Ensure Redis is running:
docker-compose ps redis
-
Test Redis connection:
redis-cli ping
If you encounter SQLx compilation errors:
- Ensure the database is running and accessible
- Set the
DATABASE_URLenvironment variable - Run
cargo sqlx prepareto generate the query cache - Use
SQLX_OFFLINE=truefor builds without database access
If ports 3000, 5432, or 6379 are already in use:
- Update the ports in
docker-compose.yml - Update corresponding environment variables
- Restart the services
For production deployment:
- Use secure values for
JWT_SECRET - Configure proper database credentials
- Set up SSL/TLS certificates
- Configure proper logging levels
- Set up monitoring and alerting
- Use a reverse proxy (nginx, traefik)
- Configure Kubernetes cluster access
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and ensure they pass
- Submit a pull request
For more details, see the main README.md.