Indicate docker config in readme and auto create admin user in docker
All checks were successful
Docker / build (push) Successful in 10s
All checks were successful
Docker / build (push) Successful in 10s
This commit is contained in:
parent
4bc1afa0cb
commit
9994403925
3 changed files with 99 additions and 0 deletions
66
README.md
66
README.md
|
|
@ -66,6 +66,72 @@ run and to maintain.
|
||||||
```./maintenance_tool.sh```
|
```./maintenance_tool.sh```
|
||||||
|
|
||||||
|
|
||||||
|
## Docker install
|
||||||
|
|
||||||
|
1. Create a `docker-compose.yml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: "3.9"
|
||||||
|
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: postgres:16
|
||||||
|
container_name: photo26-db
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: photo26
|
||||||
|
POSTGRES_USER: photo26
|
||||||
|
POSTGRES_PASSWORD: change-me
|
||||||
|
volumes:
|
||||||
|
- ./postgres_data:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
photo26:
|
||||||
|
image: git.sinfonie.org/sinfonie/photo26:latest
|
||||||
|
container_name: photo26-app
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
environment:
|
||||||
|
DB_ENGINE: postgres
|
||||||
|
DB_NAME: photo26
|
||||||
|
DB_USER: photo26
|
||||||
|
DB_PASSWORD: change-me
|
||||||
|
DB_HOST: db
|
||||||
|
DB_PORT: 5432
|
||||||
|
SECRET_KEY: change-me
|
||||||
|
EXTRA_HOSTS: photos.example.org
|
||||||
|
volumes:
|
||||||
|
- ./static:/app/static
|
||||||
|
- ./media:/app/media
|
||||||
|
ports:
|
||||||
|
- "8080:8000"
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Start the stack:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
On first start the container will run migrations and create a default admin account automatically.
|
||||||
|
|
||||||
|
3. **Default credentials** — change these immediately after first login:
|
||||||
|
|
||||||
|
| Field | Value |
|
||||||
|
|----------|-----------------|
|
||||||
|
| Username | `admin` |
|
||||||
|
| Password | `admin` |
|
||||||
|
| Email | `admin@localhost` |
|
||||||
|
|
||||||
|
Admin panel: `http://localhost:8080/admin/`
|
||||||
|
|
||||||
|
4. **Passwords to change** in `docker-compose.yml` before going to production:
|
||||||
|
- `POSTGRES_PASSWORD` / `DB_PASSWORD` — database password
|
||||||
|
- `SECRET_KEY` — Django secret key (use a long random string)
|
||||||
|
- Log in to the admin panel and change the `admin` user password
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
6. *Enjoy \o/*
|
6. *Enjoy \o/*
|
||||||
|
|
||||||
In development, you can launch the development server using:
|
In development, you can launch the development server using:
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,5 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
python manage.py migrate --noinput
|
python manage.py migrate --noinput
|
||||||
|
python manage.py create_default_admin
|
||||||
exec gunicorn photo21.wsgi:application --bind 0.0.0.0:8000 --workers 3
|
exec gunicorn photo21.wsgi:application --bind 0.0.0.0:8000 --workers 3
|
||||||
|
|
|
||||||
32
photologue/management/commands/create_default_admin.py
Normal file
32
photologue/management/commands/create_default_admin.py
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Create default admin user (admin@localhost / admin) if it does not exist"
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
User = get_user_model()
|
||||||
|
email = "admin@localhost"
|
||||||
|
username = "admin"
|
||||||
|
password = "admin"
|
||||||
|
|
||||||
|
if User.objects.filter(username=username).exists():
|
||||||
|
self.stdout.write("Default admin already exists, skipping.")
|
||||||
|
return
|
||||||
|
|
||||||
|
user = User.objects.create_superuser(username=username, email=email, password=password)
|
||||||
|
|
||||||
|
# Mark the email as verified via allauth
|
||||||
|
try:
|
||||||
|
from allauth.account.models import EmailAddress
|
||||||
|
EmailAddress.objects.create(
|
||||||
|
user=user,
|
||||||
|
email=email,
|
||||||
|
primary=True,
|
||||||
|
verified=True,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
self.stderr.write(f"Could not create allauth EmailAddress: {e}")
|
||||||
|
|
||||||
|
self.stdout.write(f"Default admin created: {username} / {password}")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue