This is a fork of LockGit/gochat with Docker Compose multi-container deployment support.
This fork adds production-ready multi-container deployment to the original gochat project:
- β 8 Independent Containers: Each service (etcd, redis, logic, connect-ws, connect-tcp, task, api, site) runs in its own container
- β Horizontal Scaling: Scale Logic, Connect, Task, and API services independently
- β
Docker Compose: One-command deployment with
make compose-devormake compose-prod - β Auto-Configuration: Container IPs automatically registered to etcd for proper RPC communication
- β Health Checks: Each service monitors its own health with auto-restart
- β Dev/Prod Configs: Separate configurations for development and production environments
# Start all services make compose-dev # Or manually docker compose -f docker-compose.yml -f deployments/docker-compose.dev.yml up # Visit the chat app http://localhost:8080
# Scale specific services
docker compose up --scale logic=3 --scale connect-ws=2 --scale task=2make compose-prod HOST_IP=<your-server-ip>
βββ etcd β Service discovery
βββ redis β Message queue & cache
βββ logic Γγ°γ€ N β Business logic RPC (scalable)
βββ connect-ws Γγ°γ€ Nβ WebSocket handler (scalable)
βββ connect-tcp Γγ°γ€ Nβ TCP handler (scalable)
βββ task Γγ°γ€ N β Message worker (scalable)
βββ api Γγ°γ€ N β REST API (scalable)
βββ site β Frontend
- Multi-Container Guide: See README-compose.md
- Original Documentation: See below or visit github.com/LockGit/gochat
- gochat is an instant messaging system based on go. It supports private messages and room broadcast messages. It communicates between layers through RPC and supports horizontal expansion.
- Supports websocket and TCP access, and supports websocket and TCP message interworking.
- Based on etcd service discovery, making it convenient to scale and deploy.
- Using redis as the carrier of message storage and delivery is very lightweight.
- Because of Go's cross-compilation features, compiled binaries can run quickly on various platforms.
- Clear architecture and directory structure.
Language: golang
Database: sqlite3 (can be replaced with MySQL or other databases)
Database ORM: gorm
Service Discovery: etcd
RPC Communication: rpcx
Queue: redis (can be replaced with kafka or rabbitmq)
Cache: redis
Message ID: snowflake algorithm
- Private messaging
- Room broadcast messaging
- Websocket support
- TCP support
- Horizontal scaling
- Service discovery via etcd
- Message queuing via Redis
- Lightweight and fast
.
βββ api # API layer, provides REST API services
βββ connect # Connection layer, handles long connections
βββ logic # Logic layer, handles business logic
βββ task # Task layer, consumes queue messages
βββ site # Frontend static files
βββ config # Configuration files
βββ db # Database initialization
βββ docker # Docker related files
βββ proto # RPC proto files
βββ tools # Utility methods
Default test users (username/password):
- demo / 111111
- test / 111111
- admin / 111111
# Development make compose-dev # Start dev environment make compose-logs # View logs make compose-ps # Check status # Production make compose-prod HOST_IP=x.x.x.x # Deploy to server # Testing & Quality make test # Run all tests make test-coverage # Run tests with coverage make fmt # Format code make vet # Run go vet make lint # Run linter # Building make build-binary # Build gochat binary make build-image # Build Docker image # Utilities make clean # Clean up everything
Automated CI/CD pipeline for testing, building, and deploying GoChat:
-
Test: Runs on every push and pull request
- Go fmt check
- Go vet static analysis
- Unit and integration tests with coverage
- Redis service container for tests
-
Build: Builds Docker image after tests pass
- Multi-stage Docker build
- Image caching for faster builds
-
Push: Pushes to Docker Hub (on push to branches)
- Multiple tags:
latest,<branch>,<git-sha> - Credentials via GitHub Secrets
- Multiple tags:
-
Deploy: Optional deployment to environments
- Development: Auto-deploy on
devbranch - Staging: Auto-deploy on
stagingbranch - Production: Manual approval on
masterbranch
- Development: Auto-deploy on
Configure these in repository Settings β Secrets and variables β Actions:
Required for Docker Hub:
DOCKERHUB_USERNAME- Your Docker Hub usernameDOCKERHUB_TOKEN- Docker Hub access token
Optional for server deployment:
DEV_SERVER_HOST,DEV_SERVER_USER,DEV_SERVER_KEYSTAGING_SERVER_HOST,STAGING_SERVER_USER,STAGING_SERVER_KEYPROD_SERVER_HOST,PROD_SERVER_USER,PROD_SERVER_KEY
devβ Development environment (auto-deploy)stagingβ Staging environment (auto-deploy)masterβ Production environment (manual approval)
# Pull and deploy specific version
./scripts/deploy.sh dev latest
./scripts/deploy.sh staging abc123def
./scripts/deploy.sh prod latestMIT License
Original Project: LockGit/gochat
Special thanks to LockGit for creating this excellent IM system.