a unified docker image

This commit is contained in:
Eugene Pankov
2021-11-21 00:08:04 +01:00
parent e1b0d01ac3
commit 34ac0781c2
11 changed files with 174 additions and 34 deletions

View File

@@ -42,7 +42,7 @@ class ChooseGatewayViewSet(RetrieveModelMixin, GenericViewSet):
gateways = list(self.queryset)
random.shuffle(gateways)
if not len(gateways):
raise NotFound()
raise NoGatewaysError()
loop = asyncio.new_event_loop()
try:

View File

@@ -12,12 +12,12 @@ class IndexView(APIView):
def get(self, request, format=None):
if settings.FRONTEND_URL:
return HttpResponseRedirect(settings.FRONTEND_URL)
return static.serve(request, 'index.html', document_root=str(settings.FRONTEND_BUILD_DIR))
return static.serve(request, 'index.html', document_root=str(settings.STATIC_ROOT))
class TerminalView(APIView):
def get(self, request, format=None):
response = static.serve(request, 'terminal.html', document_root=str(settings.FRONTEND_BUILD_DIR))
response = static.serve(request, 'terminal.html', document_root=str(settings.STATIC_ROOT))
response['X-Frame-Options'] = 'SAMEORIGIN'
return response

View File

@@ -9,8 +9,6 @@ load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
FRONTEND_BUILD_DIR = BASE_DIR / '../frontend/build'
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'django-insecure')
DEBUG = bool(os.getenv('DEBUG', False))
@@ -135,11 +133,6 @@ LOGGING = {
},
}
STATIC_URL = '/static/'
if FRONTEND_BUILD_DIR.exists():
STATICFILES_DIRS = [FRONTEND_BUILD_DIR]
STATIC_ROOT = BASE_DIR / 'public'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CSRF_USE_SESSIONS = False
@@ -172,6 +165,7 @@ SOCIAL_AUTH_PIPELINE = (
APP_DIST_STORAGE = os.getenv('APP_DIST_STORAGE', 'file://' + str(BASE_DIR / 'app-dist'))
NPM_REGISTRY = os.getenv('NPM_REGISTRY', 'https://registry.npmjs.org').rstrip('/')
FRONTEND_BUILD_DIR = Path(os.getenv('FRONTEND_BUILD_DIR', BASE_DIR / '../frontend/build'))
FRONTEND_URL = None
BACKEND_URL = None
@@ -229,6 +223,12 @@ else:
GITHUB_ELIGIBLE_SPONSORSHIPS = []
STATIC_URL = '/static/'
if FRONTEND_BUILD_DIR.exists():
STATICFILES_DIRS = [FRONTEND_BUILD_DIR]
STATIC_ROOT = BASE_DIR / 'public'
if FRONTEND_URL:
CORS_ALLOWED_ORIGINS = [FRONTEND_URL]
CORS_ALLOW_CREDENTIALS = True