diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..101616a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +./venv +./db/db.sqlite3 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..70ec5db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.10-alpine + +ENV PYTHONUNBUFFERED 1 + +ADD requirements.txt /opt/requirements.txt + +RUN set -ex \ + && apk add --no-cache --virtual .build-deps postgresql-dev build-base \ + jpeg-dev zlib-dev libjpeg libxml2-dev libxslt-dev \ + && pip install --upgrade pip \ + && pip install --no-cache-dir -r /opt/requirements.txt \ + && runDeps="$(scanelf --needed --nobanner --recursive /env \ + | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ + | sort -u \ + | xargs -r apk info --installed \ + | sort -u)" \ + && apk add --virtual rundeps $runDeps \ + && apk del .build-deps + +WORKDIR /opt + +EXPOSE 8000 +CMD ["./start.sh"] + +ADD . /opt +RUN chmod 755 /opt/start.sh diff --git a/later42/settings.py b/later42/settings.py index 974d2ca..6dbd249 100644 --- a/later42/settings.py +++ b/later42/settings.py @@ -23,7 +23,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent SECRET_KEY = os.getenv('SECRET', 'django-insecure-c%g@wujt4dco#e%k-!25o3)0%t+wm5=k%l(m!kk^p_g%kknod!') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = os.getenv('DEBUG', 'False') ALLOWED_HOSTS = ['*'] @@ -45,6 +45,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ # 'later42.logging.debug.ExceptionLoggingMiddleware', 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -84,6 +85,17 @@ DATABASES = { } } +if os.getenv('DB_TYPE') == 'postgres': + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'HOST': os.environ.get('DB_HOST'), + 'NAME': os.environ.get('DB_NAME'), + 'USER': os.environ.get('DB_USER'), + 'PASSWORD': os.environ.get('DB_PASS'), + } + } + # Password validation # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators @@ -123,6 +135,9 @@ STATIC_URL = 'static/' STATICFILES_DIRS = [ BASE_DIR / "later42/static", ] +STATIC_ROOT = BASE_DIR / "static" +STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" + # Default primary key field type # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field diff --git a/later42/static/apps/later42.shortcut b/later42/static/apps/later42.shortcut new file mode 100644 index 0000000..b54623e Binary files /dev/null and b/later42/static/apps/later42.shortcut differ diff --git a/later42/urls.py b/later42/urls.py index 21af61f..229dc35 100644 --- a/later42/urls.py +++ b/later42/urls.py @@ -43,7 +43,6 @@ urlpatterns = [ path('admin/', admin.site.urls), path('signup/', signup.register, name='signup'), path("accounts/login/", LoginView.as_view(authentication_form=CustomLoginForm), name="login"), - path('accounts/', include('django_registration.backends.activation.urls')), path("accounts/", include("django.contrib.auth.urls")), path('profile/', profile.get, name='profile'), path('api/url/', api.URL.as_view(), name='urls'), diff --git a/requirements.txt b/requirements.txt index 2968a99..bdba665 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ loguru==0.6.0 bs4==0.0.1 requests==2.28.1 djangorestframework==3.14.0 +whitenoise==6.2.0 diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..d4698a0 --- /dev/null +++ b/start.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +./manage.py migrate --noinput +exec gunicorn --bind :8000 --workers 4 later42.wsgi:application diff --git a/static/.keep b/static/.keep new file mode 100644 index 0000000..e69de29