Docker-Compose Single-Run
Add firstrun checks Avoids running commands on firstrun Add Docker-compose file allows setup in a single docker-compose up command Updated Readme re: docker-compose Added stub detailing how to use the compose file. Update README.md Changed Entrypoint Moved sanity checks to their own script, changed entrypoint logic updated entrypoint
This commit is contained in:
49
shynet/core/management/commands/sanity_checks.py
Normal file
49
shynet/core/management/commands/sanity_checks.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import traceback
|
||||
import uuid
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils.crypto import get_random_string
|
||||
|
||||
from django.db import DEFAULT_DB_ALIAS, connections
|
||||
from django.db.utils import OperationalError, ConnectionHandler
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from core.models import User
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Performs sanity checks on the Shynet setup"
|
||||
|
||||
def check_migrations(self):
|
||||
from django.db.migrations.executor import MigrationExecutor
|
||||
try:
|
||||
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
|
||||
except OperationalError:
|
||||
# DB_NAME database not found?
|
||||
return True
|
||||
except ImproperlyConfigured:
|
||||
# No databases are configured (or the dummy one)
|
||||
return True
|
||||
|
||||
if executor.migration_plan(executor.loader.graph.leaf_nodes()):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def handle(self, *args, **options):
|
||||
migration = self.check_migrations()
|
||||
|
||||
admin, hostname, whitelabel = [True] * 3
|
||||
if not migration:
|
||||
admin = not User.objects.all().exists()
|
||||
hostname = not Site.objects.filter(domain__isnull=False).exclude(domain__exact="").exclude(domain__exact="example.com").exists()
|
||||
whitelabel = not Site.objects.filter(name__isnull=False).exclude(name__exact="").exclude(name__exact="example.com").exists()
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"{migration} {admin} {hostname} {whitelabel}"
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user