Deploying Bifolk from GitLab Container Registry¶
This guide explains how to deploy Bifolk using pre-built Docker images from the GitLab Container Registry.
Prerequisites¶
- Docker Engine 20.10+ and Docker Compose 2.0+
- Git (to clone repository for configuration files)
- Access to the GitLab Container Registry (public images require no authentication; private images require a token)
Overview¶
Instead of building Docker images locally, you can use pre-built images published to the GitLab Container Registry. This approach:
- Saves build time - No need to build images on your deployment server
- Ensures consistent deployments - Use the same tested images across environments
- Simplifies updates - Pull new versions with a single command
- Uses verified images - Images are built and tested via CI/CD pipeline
Quick Start¶
1. Clone Repository (for configuration files)¶
2. Configure Secrets¶
Copy the example secrets and configure them with your actual values:
Edit files in secrets/:
- secret_key.txt - Django SECRET_KEY (generate with: python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())")
- db_password.txt - PostgreSQL password
- email_password.txt - SMTP password for email functionality
Set proper permissions:
3. Set Up Docker Compose¶
Copy the example configuration:
Edit docker-compose.yml and set the image URLs:
services:
bifolk-app:
image: registry.code.wdmt.de/bifolk/bifolk/bifolk-app:latest
bifolk-docs:
image: registry.code.wdmt.de/bifolk/bifolk/bifolk-docs:latest
4. Configure Environment (Optional)¶
Create a .env file if you need to override default settings:
Edit .env to customize settings like:
- DJANGO_DEBUG=False (important for production!)
- DJANGO_ALLOWED_HOSTS=your-domain.com
- EMAIL_HOST=smtp.example.com
- Database settings
5. Pull and Start¶
# Pull latest images from registry
docker-compose pull
# Start services in background
docker-compose up -d
# View logs
docker-compose logs -f
6. Verify Deployment¶
Check container status:
View application logs:
Access the application: - Application: http://localhost:8000 - Documentation: http://localhost:8001
Image Tags¶
Images are published with multiple tags:
| Tag | Description | Use Case |
|---|---|---|
stable |
Latest versioned release (same as latest v*..) | Production (recommended) |
latest |
Latest build from next-release branch | Production |
v0.x.x |
Specific version (semantic versioning) | Production (pinned version) |
Tag Examples¶
# Use stable release (recommended for production)
image: registry.code.wdmt.de/bifolk/bifolk/bifolk-app:stable
# Use latest from next-release branch
image: registry.code.wdmt.de/bifolk/bifolk/bifolk-app:latest
# Pin to specific version
image: registry.code.wdmt.de/bifolk/bifolk/bifolk-app:v0.1.0
Production Deployment Recommendations¶
1. Use Stable or Specific Version Tags¶
For production, use the stable tag or specific version tags instead of latest:
services:
bifolk-app:
image: registry.code.wdmt.de/bifolk/bifolk/bifolk-app:stable # Always latest release
bifolk-docs:
image: registry.code.wdmt.de/bifolk/bifolk/bifolk-docs:stable
Or pin to a specific version for maximum control:
services:
bifolk-app:
image: registry.code.wdmt.de/bifolk/bifolk/bifolk-app:v0.1.0 # Pin to specific version
bifolk-docs:
image: registry.code.wdmt.de/bifolk/bifolk/bifolk-docs:v0.1.0
This ensures: - Predictable deployments - Easy rollback to previous versions - No unexpected changes from automatic updates
2. Disable Debug Mode¶
Ensure DJANGO_DEBUG=False in production:
3. Configure Allowed Hosts¶
Set proper allowed hosts for your domain:
4. Use Strong Secrets¶
- Generate a strong SECRET_KEY
- Use complex database passwords
- Secure email credentials
5. Configure Email¶
Set up proper SMTP settings for email functionality:
environment:
- EMAIL_HOST=smtp.example.com
- EMAIL_PORT=587
- EMAIL_USE_TLS=True
- EMAIL_USER=your-email@example.com
- DEFAULT_FROM_EMAIL=noreply@yourdomain.com
6. Use Reverse Proxy¶
For production, use a reverse proxy (Nginx, Traefik) for: - SSL/TLS termination - Load balancing - Static file serving - Request filtering
Updating to New Versions¶
Method 1: Update to Latest Release¶
# Pull latest images
docker-compose pull
# Recreate containers with new images
docker-compose up -d
# View logs to verify update
docker-compose logs -f bifolk-app
Method 2: Update to Specific Version¶
- Edit
docker-compose.ymland change the image tags:
- Pull and restart:
Method 3: Rolling Back¶
To roll back to a previous version:
- Edit
docker-compose.ymlwith the previous version tag:
- Pull and restart:
Authentication for Private Images¶
If the registry is private, you need to authenticate with the GitLab Container Registry.
Create Personal Access Token (PAT)¶
- Go to GitLab → User Settings → Access Tokens
- Click "Add new token"
- Select scope:
read_registry - Generate token and copy it
Login to Registry¶
After authentication, you can pull private images normally.
Monitoring and Maintenance¶
View Logs¶
# All services
docker-compose logs -f
# Specific service
docker-compose logs -f bifolk-app
# Last 100 lines
docker-compose logs --tail=100 bifolk-app
Check Container Health¶
# Container status
docker-compose ps
# Health check status
docker inspect --format='{{.State.Health.Status}}' bifolk-app
Database Backup¶
# Backup database
docker exec bifolk-db pg_dump -U bifolk bifolk > backup.sql
# Restore database
docker exec -i bifolk-db psql -U bifolk bifolk < backup.sql
Resource Usage¶
Troubleshooting¶
Image Pull Fails¶
Problem: Error response from daemon: manifest for registry.code.wdmt.de/... not found
Solutions: - Verify the image tag exists in the registry (check the GitLab Container Registry page) - Ensure the image URL is correct - If the registry is private, authenticate with a PAT (see Authentication section) - Check internet connectivity
Container Fails to Start¶
Problem: Container exits immediately after starting
Solutions:
-
Check logs:
-
Verify secrets are configured:
-
Ensure database is ready:
-
Check environment variables in docker-compose.yml
Database Connection Issues¶
Problem: could not connect to server: Connection refused
Solutions:
- Verify
DB_HOSTis set tobifolk-db(the service name) -
Check if database container is running:
-
Review database logs:
-
Verify database credentials in secrets match docker-compose.yml
Permission Denied Errors¶
Problem: Permission errors accessing volumes or secrets
Solutions:
-
Set correct permissions on secrets:
-
Check volume ownership:
-
Recreate volumes if needed:
Application Not Accessible¶
Problem: Cannot access http://localhost:8000
Solutions:
-
Check if port is already in use:
-
Verify container port mapping:
-
Check firewall rules (if on remote server)
-
Test with curl:
Advanced Configuration¶
Custom Port Mapping¶
Change the exposed port in docker-compose.yml:
Or use .env file:
Using External Database¶
To use an external PostgreSQL database:
- Remove
bifolk-dbservice from docker-compose.yml - Update database environment variables:
environment:
- DB_HOST=external-db-host.com
- DB_PORT=5432
- DB_NAME=bifolk
- DB_USER=bifolk
# Set DB_PASSWORD via secret
Multiple Environments¶
Create separate compose files for different environments:
docker-compose.prod.yml- Productiondocker-compose.staging.yml- Stagingdocker-compose.dev.yml- Development
Use with: