feat: optimize docker compose for dashboard and api (#578)

* chore: use turbo for build

* fix docker compose file and remove backend

* chore: update .dockerignore to include additional files and directories for improved build management

* copy everything in both docke filed

* refactor: streamline Dockerfile to copy entire dashboard app and remove unnecessary node_modules references

* update api to use turbo to start

* run ls la for docker files

* update cmd commands

* update cmds to use node

* fix: add redis url to docker compose

* fix: reduce memory allocation for dashboard build in Dockerfile

* debug dashboard build

* update api docker file

* update dashboard

* add tsconfig

* chore: add echo to dockerfile

* fix: change echo to run

* chore: install pnpm before switching to non-root user in Dockerfile

* refactor: update start commands in package.json and Dockerfiles to use pnpm

* install turbo

* use turbo 1.10.16

* update turbo config

* fix: update CMD in Dockerfile to run the API directly using Node.js

* change

* add commands to turbo.json

* copy over turbo

* add workspace

* fix: update start commands in package.json to specify ports for dashboard and API

* publish docker images

* add dev branch

* update compose

* build only for amd64 platform

* refactor: update docker-compose to use pre-built images and remove build context

* coolify-dockertest

* point to latest

* chore: update docker-compose to use specific version tags for API and dashboard images

* remove envs for docker file

* 0.1.3

* use dynamic env

* 0.1.4

* add PUBLIC_IS_SELFHOSTED=true

* chore: update docker-compose to use version 0.1.5 for API and dashboard images

* use static for PUBLIC_IS_SELFHOSTED

* disable cache for tag

* use 0.1.7

* add PUBLIC_IS_SELFHOSTED=true

* comment out caching

* update docker-compose to use version 0.1.8 for API and dashboard images

* update api port

* use tag 0.1.9

* add cache

* use latest tag in compose file
This commit is contained in:
Rotimi Best
2025-10-11 13:27:50 +01:00
committed by GitHub
parent 27ee51155e
commit 168866c81b
44 changed files with 848 additions and 2388 deletions
+215
View File
@@ -0,0 +1,215 @@
# Publishing ClassroomIO Docker Images to Docker Hub
This guide explains how to publish the ClassroomIO API and Dashboard Docker images to Docker Hub.
## Prerequisites
1. **Docker Hub Account**: Create an account at https://hub.docker.com if you don't have one
2. **Docker Installed**: Make sure Docker is installed and running on your machine
3. **Docker Hub Access Token**: Create a personal access token at https://hub.docker.com/settings/security
## Method 1: Manual Publishing (Local)
### Step 1: Login to Docker Hub
```bash
docker login
# Enter your Docker Hub username and password/token when prompted
```
### Step 2: Build and Push Images
Use the provided script to build and push both images:
```bash
# Default (uses 'classroomio' as username and 'latest' as version)
./docker/docker-push.sh
# Custom username
DOCKERHUB_USERNAME=your-username ./docker/docker-push.sh
# Specific version
VERSION=v0.1.0 ./docker/docker-push.sh
# Both custom username and version
DOCKERHUB_USERNAME=classroomio VERSION=v0.1.0 ./docker/docker-push.sh
```
### Step 3: Verify Images
Check your Docker Hub repository at:
- https://hub.docker.com/r/classroomio/api
- https://hub.docker.com/r/classroomio/dashboard
## Method 2: GitHub Actions (Automated)
### Setup (One-time)
1. **Add Docker Hub Secrets to GitHub**:
- Go to your GitHub repository → Settings → Secrets and variables → Actions
- Add two secrets:
- `DOCKERHUB_USERNAME`: Your Docker Hub username
- `DOCKERHUB_TOKEN`: Your Docker Hub access token
2. **Push the workflow file** (already created at `.github/workflows/docker-publish.yml`)
### Publishing via GitHub Actions
The workflow will automatically publish images when:
1. **Push to main/master branch**: Creates a `latest` tag
2. **Create a version tag**: Creates versioned tags
3. **Manual trigger**: Use the Actions tab in GitHub
#### Create a version tag and push:
```bash
git tag v0.1.0
git push origin v0.1.0
```
#### Manual trigger from GitHub:
1. Go to Actions tab in your repository
2. Select "Publish Docker Images" workflow
3. Click "Run workflow"
4. Enter optional version tag (or leave default 'latest')
## Method 3: Individual Image Building
### Build API Image
```bash
docker build -f docker/Dockerfile.api -t classroomio/api:latest .
docker push classroomio/api:latest
```
### Build Dashboard Image
```bash
docker build -f docker/Dockerfile.dashboard -t classroomio/dashboard:latest .
docker push classroomio/dashboard:latest
```
## Using Published Images
### Pull Images
```bash
docker pull classroomio/api:latest
docker pull classroomio/dashboard:latest
```
### Update docker-compose.yml
Instead of building locally, use the published images:
```yaml
services:
api:
image: classroomio/api:latest
# Remove the 'build' section
ports:
- "3081:3081"
environment:
# ... your environment variables
dashboard:
image: classroomio/dashboard:latest
# Remove the 'build' section
ports:
- "3082:3082"
environment:
# ... your environment variables
```
## Versioning Strategy
### Recommended Tags:
- `latest`: Most recent stable build
- `v0.1.0`: Specific semantic version
- `v1.0`: Minor version
- `v1`: Major version
- `main`: Latest main branch build
- `dev`: Development builds
### Example: Publishing a new version
```bash
# Build with multiple tags
docker build -f docker/Dockerfile.api \
-t classroomio/api:latest \
-t classroomio/api:v1.2.0 \
-t classroomio/api:v1.2 \
-t classroomio/api:v1 \
.
# Push all tags
docker push classroomio/api:latest
docker push classroomio/api:v1.2.0
docker push classroomio/api:v1.2
docker push classroomio/api:v1
```
## Image Sizes and Build Times
- **API Image**: ~400-600 MB (Node.js Alpine + dependencies)
- **Dashboard Image**: ~600-800 MB (Node.js Alpine + SvelteKit build)
- **Build Time**: 5-10 minutes per image (depending on your machine)
## Multi-Architecture Support
The GitHub Actions workflow builds for both `linux/amd64` and `linux/arm64` platforms, making the images compatible with:
- x86_64 servers
- ARM-based servers (like AWS Graviton)
- Apple Silicon Macs (M1/M2/M3)
## Troubleshooting
### "unauthorized: authentication required"
- Run `docker login` again
- Check your Docker Hub token hasn't expired
### "denied: requested access to the resource is denied"
- Make sure you're pushing to your own username
- Repository might need to be created first on Docker Hub
### Build failures
- Check Dockerfile syntax
- Ensure all build arguments are provided
- Check available disk space: `docker system df`
### Clean up old images
```bash
# Remove dangling images
docker image prune
# Remove all unused images
docker image prune -a
```
## Security Best Practices
1. **Never commit secrets** to the repository
2. **Use Docker Hub access tokens** instead of passwords
3. **Enable 2FA** on your Docker Hub account
4. **Scan images** for vulnerabilities:
```bash
docker scan classroomio/api:latest
```
5. **Use specific version tags** in production, not `latest`
## Support
For issues with publishing, please check:
- Docker Hub status: https://status.docker.com
- GitHub Actions logs in your repository
- Docker daemon logs: `docker info`
## References
- [Docker Hub Documentation](https://docs.docker.com/docker-hub/)
- [GitHub Actions for Docker](https://docs.github.com/en/actions/publishing-packages/publishing-docker-images)
- [Docker Build Documentation](https://docs.docker.com/engine/reference/commandline/build/)
+141
View File
@@ -0,0 +1,141 @@
# Docker Usage Guide
This directory contains all Docker-related files for the ClassroomIO project.
## 📁 Directory Structure
```
docker/
├── README.md # Full publishing guide
├── USAGE.md # This file - quick usage guide
├── commands.md # Quick command reference
├── docker-compose.yaml # Docker Compose configuration
├── docker-push.sh # Script to publish images to Docker Hub
├── Dockerfile.api # API service Dockerfile
└── Dockerfile.dashboard # Dashboard service Dockerfile
```
## 🚀 Quick Start
### Using Docker Compose (Recommended)
```bash
# From the project root
cd docker
docker-compose up -d
# Or from project root
docker-compose -f docker/docker-compose.yaml up -d
```
### Building Individual Images
```bash
# From project root
docker build -f docker/Dockerfile.api -t api .
docker build -f docker/Dockerfile.dashboard -t dashboard .
```
## 📦 Publishing to Docker Hub
```bash
# From project root
./docker/docker-push.sh
# With custom options
DOCKERHUB_USERNAME=your-username VERSION=v1.0.0 ./docker/docker-push.sh
```
## 🔧 Common Commands
### Start Services
```bash
cd docker && docker-compose up -d
```
### Stop Services
```bash
cd docker && docker-compose down
```
### View Logs
```bash
cd docker && docker-compose logs -f
```
### Rebuild Services
```bash
cd docker && docker-compose up -d --build
```
## 📚 Documentation
- **README.md**: Complete Docker Hub publishing guide
- **commands.md**: Quick command reference
- **GitHub Actions**: Automated publishing via `.github/workflows/docker-publish.yml`
## 🌍 Environment Variables
Copy `.env.example` to `.env` in the project root and configure:
```bash
cp ../.env.example ../.env
```
Required variables are listed in `docker-compose.yaml`.
## 🔗 Published Images
- **API**: `classroomio/api` or `classroomio/api`
- **Dashboard**: `classroomio/dashboard` or `classroomio/dashboard`
Pull from Docker Hub:
```bash
docker pull classroomio/api:latest
docker pull classroomio/dashboard:latest
```
## 💡 Tips
1. **Always run builds from project root** - the context needs to be the entire monorepo
2. **Use docker-compose** for local development
3. **Use published images** for production deployments
4. **Check logs** if services fail to start: `docker-compose logs -f`
## 🐛 Troubleshooting
### Services won't start
```bash
# Check logs
docker-compose logs -f
# Rebuild from scratch
docker-compose down
docker-compose build --no-cache
docker-compose up -d
```
### Port conflicts
```bash
# Check if ports are in use
lsof -i :3081 # API
lsof -i :3082 # Dashboard
# Change ports in docker-compose.yaml if needed
```
### Build failures
```bash
# Clean up Docker
docker system prune -a
# Try building again
docker-compose build --no-cache
```
## 📞 Support
For more detailed information, see:
- `README.md` - Full Docker Hub publishing guide
- `commands.md` - Quick command reference
- Project main README for general setup
+90
View File
@@ -0,0 +1,90 @@
# Quick Docker Commands Reference
## Login to Docker Hub
```bash
docker login
```
## Build Images Locally
### API
```bash
docker build -f ./docker/Dockerfile.api -t classroomio/api:latest .
```
### Dashboard
```bash
docker build -f ./docker/Dockerfile.dashboard -t classroomio/dashboard:latest .
```
## Push to Docker Hub
### API
```bash
docker push classroomio/api:latest
```
### Dashboard
```bash
docker push classroomio/dashboard:latest
```
## All in One Script
```bash
# Make script executable (first time only)
chmod +x docker-push.sh
# Run the script
./docker-push.sh
# With custom username
DOCKERHUB_USERNAME=your-username ./docker-push.sh
# With version tag
VERSION=v1.0.0 ./docker-push.sh
```
## Pull Published Images
```bash
docker pull classroomio/api:latest
docker pull classroomio/dashboard:latest
```
## Run Published Images
```bash
# API
docker run -d -p 3081:3081 \
-e PUBLIC_SUPABASE_ANON_KEY=your_key \
-e PUBLIC_SUPABASE_URL=your_url \
classroomio/api:latest
# Dashboard
docker run -d -p 3082:3082 \
-e PUBLIC_SUPABASE_ANON_KEY=your_key \
-e PUBLIC_SUPABASE_URL=your_url \
classroomio/dashboard:latest
```
## Useful Commands
### Check local images
```bash
docker images | grep classroomio
```
### Remove local images
```bash
docker rmi classroomio/api:latest
docker rmi classroomio/dashboard:latest
```
### View image details
```bash
docker inspect classroomio/api:latest
```
### Check image size
```bash
docker images classroomio/api:latest --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
```