diff --git a/Pipfile.lock b/Pipfile.lock.not-in-use similarity index 100% rename from Pipfile.lock rename to Pipfile.lock.not-in-use diff --git a/Pipfile b/Pipfile.not-in-use similarity index 95% rename from Pipfile rename to Pipfile.not-in-use index 74d03099..58b144e5 100644 --- a/Pipfile +++ b/Pipfile.not-in-use @@ -12,7 +12,7 @@ social-auth-app-django = "==4.0.0" social-auth-core = "==4.1.0" Django = "==2.2.20" PyJWT = "==2.0.1" -mysqlclient = "*" +# mysqlclient = "*" [dev-packages] coverage = "==5.5" diff --git a/build_files.sh b/build_files.sh new file mode 100644 index 00000000..dd998d74 --- /dev/null +++ b/build_files.sh @@ -0,0 +1,5 @@ +# build_files.sh +echo "BUILD START" +pip install -r requirements.txt +python3.9 manage.py collectstatic --noinput --clear +echo "BUILD END" \ No newline at end of file diff --git a/edagames/settings/dev.py b/edagames/settings/dev.py index c14e3236..0443032d 100644 --- a/edagames/settings/dev.py +++ b/edagames/settings/dev.py @@ -30,6 +30,7 @@ 'localhost', '127.0.0.1', 'django', + '.vercel.app', ] diff --git a/edagames/settings/prod.py b/edagames/settings/prod.py index 6c14a404..c84028ea 100644 --- a/edagames/settings/prod.py +++ b/edagames/settings/prod.py @@ -16,10 +16,11 @@ import base64 from botocore.exceptions import ClientError import json +from pathlib import Path # Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - +# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ @@ -30,7 +31,10 @@ DEBUG = True ALLOWED_HOSTS = [ - '*', + 'localhost', + '127.0.0.1', + 'django', + '.vercel.app', ] @@ -66,10 +70,29 @@ ROOT_URLCONF = 'edagames.urls' +# STATICFILES_DIRS = os.path.join(BASE_DIR, 'static'), +# STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_build', 'static') + +STATIC_URL = 'static/' + +# STATICFILES_DIRS = [ +# BASE_DIR / "static", +# ] +# STATIC_ROOT = BASE_DIR / 'static' +# MEDIA_URL = '/media/' + + +STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ] +# Configures the staticfiles directory to serve +# static files from /static/ on our deployment +STATIC_ROOT = os.path.join( + BASE_DIR, + 'staticfiles', 'static') + TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': ['templates'], + 'DIRS': [BASE_DIR, 'templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -89,7 +112,7 @@ 'django.contrib.auth.backends.ModelBackend', ) -WSGI_APPLICATION = 'edagames.wsgi.application' +WSGI_APPLICATION = 'edagames.wsgi.app' # get secret @@ -123,18 +146,17 @@ def get_secret(db_secret_name): # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases -secret_value = json.loads(get_secret(get_env_variable('DB_SECRET_NAME'))) +# secret_value = json.loads(get_secret(get_env_variable('DB_SECRET_NAME'))) +import dj_database_url DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': secret_value["dbname"], - 'USER': secret_value["username"], - 'PASSWORD': secret_value["password"], - 'HOST': secret_value["host"], - 'PORT': secret_value["port"] - } + 'default': dj_database_url.config(default=get_env_variable('EDAGAME_POSTGRES_URL')) } +DATABASES['default']['OPTIONS'] = { + 'sslmode': 'require', + 'options': 'endpoint=' + get_env_variable('EDAGAME_POSTGRES_ENDPOINT'), + } + # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators @@ -190,10 +212,8 @@ def get_secret(db_secret_name): # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ -STATIC_URL = '/static/' LOGIN_REDIRECT_URL = '/' LOGOUT_REDIRECT_URL = '/login' -STATICFILES_DIRS = ['static'] CRISPY_TEMPLATE_PACK = 'bootstrap4' LOGIN_URL = 'login' LOGOUT_URL = 'logout' diff --git a/edagames/urls.py b/edagames/urls.py index bb12bbc5..0c855020 100644 --- a/edagames/urls.py +++ b/edagames/urls.py @@ -25,3 +25,5 @@ path('', include('development.urls', namespace='api')), path('', include(('tournaments.urls'), namespace='tournaments')), ] +urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT) +urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/edagames/wsgi.py b/edagames/wsgi.py index d48226b5..2668d561 100644 --- a/edagames/wsgi.py +++ b/edagames/wsgi.py @@ -13,4 +13,4 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'edagames.settings') -application = get_wsgi_application() +app = get_wsgi_application() diff --git a/environment.py b/environment.py index ba1c609e..bcf3c23c 100644 --- a/environment.py +++ b/environment.py @@ -4,7 +4,7 @@ def get_env_variable(var_name): try: - return os.environ[var_name] + return os.environ.get(var_name) except KeyError: error_msg = "Set the %s environment variable" % var_name raise ImproperlyConfigured(error_msg) diff --git a/requirements.txt b/requirements.txt index c2408710..455318c6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,9 @@ django==2.2.20 djangorestframework==3.12.4 idna==2.10; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' ipdb==0.13.9 -mysqlclient==2.1.0 +# mysqlclient==2.1.0 +dj-database-url==0.5.0 +psycopg2-binary==2.8.6 oauthlib==3.2.0; python_version >= '3.6' pycparser==2.21 pyjwt==2.0.1 diff --git a/vercel.json b/vercel.json new file mode 100644 index 00000000..5013f028 --- /dev/null +++ b/vercel.json @@ -0,0 +1,30 @@ +{ + "builds": [ + { + "src": "edagames/wsgi.py", + "use": "@vercel/python", + "config": { + "maxLambdaSize": "15mb", + "runtime": "python3.9" + } + }, + { + "src": "build_files.sh", + "use": "@vercel/static-build", + "config": { + "distDir": "staticfiles" + } + } + ], + "routes": [ + { + "src": "/static/(.*)", + "dest": "/static/$1" + }, + { + "src": "/(.*)", + "dest": "edagames/wsgi.py" + } + ], + "outputDirectory": "staticfiles" +} \ No newline at end of file