Files
gitea/README.md
mguschin 209a06b21f Init.
2026-02-02 19:58:01 +03:00

146 lines
3.4 KiB
Markdown

# Gitea Docker Setup
Self-hosted Git service with Docker Compose and SSL certificates for production deployment. Database is managed separately.
## Quick Start
### Local Development
1. Copy the local environment configuration:
```bash
cp .env.local .env
```
2. Update `.env` with your database connection details (ensure database is running):
```bash
nano .env
# Update DB_HOST, DB_USER, DB_PASSWORD
```
3. Start Gitea:
```bash
docker-compose up -d
```
4. Access Gitea at `http://localhost:3000`
### Production Deployment (repos.guschin.info)
1. Copy the production environment configuration:
```bash
cp .env.production .env
```
2. **IMPORTANT**: Edit `.env` and update the database credentials:
```bash
nano .env
# Update DB_HOST, DB_USER, DB_PASSWORD with your external database connection
```
3. **IMPORTANT**: Ensure the MySQL database is running and accessible before starting Gitea
4. Install SSL certificates:
```bash
./install-certificates.sh
```
5. Start Gitea:
```bash
docker-compose up -d
```
## Configuration Files
- `docker-compose.yml` - Docker Compose configuration for Gitea only
- `.env` - Active environment configuration (gitignored)
- `.env.local` - Local development settings
- `.env.production` - Production environment settings
- `install-certificates.sh` - SSL certificate installation for production
## Environment Variables
### Database Configuration (External)
- `DB_HOST` - MySQL host (e.g., db-server.example.com:3306)
- `DB_NAME` - Database name (default: gitea)
- `DB_USER` - Database user (default: gitea)
- `DB_PASSWORD` - Database password (ensure it's secure!)
### Gitea Configuration
- `GITEA_DOMAIN` - Domain name (localhost or repos.guschin.info)
- `GITEA_ROOT_URL` - Full URL to Gitea instance
- `GITEA_HTTP_PORT` - HTTP port mapping (default: 3000)
- `GITEA_SSH_PORT` - SSH port mapping (default: 2222 for local, 22 for production)
## Common Commands
```bash
# Start Gitea
docker-compose up -d
# Stop Gitea
docker-compose down
# View logs
docker-compose logs -f gitea
# Restart Gitea
docker-compose restart gitea
# Check service status
docker-compose ps
```
**Database Backup/Restore**: Use commands on the external database server, not in docker-compose.
## SSL Certificates
The `install-certificates.sh` script will:
1. Install certbot if not present
2. Obtain Let's Encrypt SSL certificates for repos.guschin.info
3. Configure automatic certificate renewal
4. Copy certificates to `./certs` directory
Certificates are automatically renewed every 60 days.
## Volumes
- `gitea-data` - Gitea application data and repositories
## Security Notes
1. Always change default passwords in production
2. Use strong passwords for database credentials
3. Keep the `.env` file secure (it's gitignored by default)
4. Regularly update Docker images: `docker-compose pull && docker-compose up -d`
5. Enable 2FA for Gitea admin accounts
## Ports
- **Local**: HTTP on 3000, SSH on 2222
- **Production**: HTTP on 3000 (behind reverse proxy), SSH on 22
## Troubleshooting
### Database connection issues
Ensure the external database is running and accessible with the credentials in `.env`. Test the connection:
```bash
mysql -h ${DB_HOST} -u ${DB_USER} -p
```
### Certificate issues
```bash
# Test certificate renewal
sudo certbot renew --dry-run
# Check certificate expiry
sudo certbot certificates
```
### Permission issues
```bash
# Fix volume permissions
docker-compose down
sudo chown -R 1000:1000 ./volumes/gitea-data
docker-compose up -d
```