Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,8 @@ OSMOSE_DB_USER= # database username
OSMOSE_DB_PWD= # database password
HTTPS_PORTAL_STAGE= # see https://github.com/SteveLTN/https-portal, use "local" to test on your machine
OSMOSE_SENTRY_URL= # if you use https://sentry.io (more for staging and production)

DJANGO_ADMIN_USERNAME= # Username for your Django superadmin user
DJANGO_ADMIN_EMAIL= # Email address of your Django superadmin user (for now there is no real use of it)
DJANGO_ADMIN_PASSWORD= # Password for your Django superadmin user
```
53 changes: 45 additions & 8 deletions backend/api/management/commands/seed.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from datetime import datetime, timedelta
from random import randint, choice

Expand All @@ -6,7 +7,6 @@
from django.core import management
from django.utils import timezone
from django.utils.dateparse import parse_datetime
from faker import Faker

from backend.api.models import (
DatasetType,
Expand All @@ -24,12 +24,14 @@
AnnotationTask,
SpectroConfig,
)
from backend.osmosewebsite.management.commands.seed import Command as WebsiteCommand

if os.environ.get("ENV") != "production":
from faker import Faker
from backend.osmosewebsite.management.commands.seed import Command as WebsiteCommand


class Command(management.BaseCommand):
help = "Seeds the DB with fake data (deletes all existing data first)"
fake = Faker()

data_nb = 5
files_nb = 100
Expand All @@ -51,17 +53,41 @@ def add_arguments(self, parser):
default=100,
help="Give the amount of files in dataset to create, useful to test request optimisations",
)
parser.add_argument(
"--admin-name",
type=str,
default="admin",
help="Define superadmin username",
)
parser.add_argument(
"--admin-email",
type=str,
default="admin@osmose.xyz",
help="Define superadmin email address",
)
parser.add_argument(
"--admin-pwd",
type=str,
default="osmose29",
help="Define superadmin password",
)

def handle(self, *args, **options):
self.data_nb = options["data_nb"] or self.data_nb
self.files_nb = options["files_nb"] or self.files_nb

# Cleanup
print("# Cleanup")
management.call_command("flush", verbosity=0, interactive=False)
if os.environ.get("ENV") != "production":
print("# Cleanup")
management.call_command("flush", verbosity=0, interactive=False)

# Creation
print("# Creation")

self._create_superadmin(**options)
if os.environ.get("ENV") == "production":
return
self.fake = Faker()
self._create_users()
self._create_metadata()
self._create_datasets()
Expand All @@ -72,12 +98,23 @@ def handle(self, *args, **options):
self._create_comments()
WebsiteCommand().handle(*args, **options)

def _create_superadmin(self, **options):
name = options["admin_name"] or "admin"
if User.objects.filter(is_superuser=True, username=name).count() > 0:
print(f" ###### _create_superadmin: {name} - already exists ######")
return
print(f" ###### _create_superadmin: {name} ######")
self.admin = User.objects.create_user(
name,
options["admin_email"] or f"{name}@osmose.xyz",
options["admin_pwd"] or "osmose29",
is_superuser=True,
is_staff=True
)

def _create_users(self):
print(" ###### _create_users ######")
password = "osmose29"
self.admin = User.objects.create_user(
"admin", "admin@osmose.xyz", password, is_superuser=True, is_staff=True
)
users = []
# WARNING : names like TestUserX are used for Cypress tests, do not change or remove
names = ["TestUser1", "TestUser2"] + [
Expand Down
1 change: 1 addition & 0 deletions backend/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if [ "$STAGING" = "true" ]; then poetry install; fi
# Normal setup commands
#poetry run python manage.py collectstatic --noinput # Since osmose.ifremer.fr is read-only, this won't work
poetry run python manage.py migrate
poetry run python manage.py seed --admin-name=$DJANGO_ADMIN_USERNAME --admin-pwd=$DJANGO_ADMIN_PASSWORD --admin-email=$DJANGO_ADMIN_EMAIL

# Launching server
poetry run gunicorn -b 0.0.0.0:8000 backend.wsgi
File renamed without changes.
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ services:
OSMOSE_DB_BASE: "${OSMOSE_DB_USER}"
OSMOSE_SENTRY_URL: "${OSMOSE_SENTRY_URL}"
OSMOSE_PROXY_URL: "${OSMOSE_PROXY_URL}"
read_only: true
DJANGO_ADMIN_USERNAME: "${DJANGO_ADMIN_USERNAME}"
DJANGO_ADMIN_EMAIL: "${DJANGO_ADMIN_EMAIL}"
DJANGO_ADMIN_PASSWORD: "${DJANGO_ADMIN_PASSWORD}"
volumes:
- static:/opt/staticfiles:ro
- ./volumes/datawork:/opt/datawork:ro
Expand Down
4 changes: 3 additions & 1 deletion dockerfiles/back.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ RUN pip install --no-cache-dir poetry

COPY pyproject.toml .
COPY poetry.lock .
COPY metadatax-0.1.0.tar.gz .

# Copy external libraries folder
COPY dependencies ./dependencies

ENV POETRY_CACHE_DIR=/opt/.cache/pypoetry
RUN poetry install --only main
Expand Down
Loading