diff --git a/artel/Dockerfile b/artel/Dockerfile index 39fb199..984a8ee 100644 --- a/artel/Dockerfile +++ b/artel/Dockerfile @@ -46,6 +46,8 @@ COPY --chown=wagtail:wagtail . . # Use user "wagtail" to run the build commands below and the server itself. USER wagtail +RUN mkdir -p /app/media + # Collect static files. RUN python manage.py collectstatic --noinput --clear diff --git a/artel/artel/settings/base.py b/artel/artel/settings/base.py index 755a912..33f2dbf 100644 --- a/artel/artel/settings/base.py +++ b/artel/artel/settings/base.py @@ -16,6 +16,18 @@ import os PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(PROJECT_DIR) +import sentry_sdk +from sentry_sdk.integrations.django import DjangoIntegration + +# -> GlitchTip error reporting +sentry_sdk.init( + integrations=[DjangoIntegration()], + auto_session_tracking=False, + traces_sample_rate=0 +) + +SENTRY_ENVIRONMENT = os.environ.get("SENTRY_ENVIRONMENT", '') + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ diff --git a/artel/artel/settings/dev.py b/artel/artel/settings/dev.py index b29e619..380a4cc 100644 --- a/artel/artel/settings/dev.py +++ b/artel/artel/settings/dev.py @@ -3,6 +3,7 @@ from .base import * # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True + # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = "django-insecure-s7hlfa-#n7-v0#&-0ko3(efe+@^d@ie1_1-633e&jb1rh$)j1p" diff --git a/artel/artel/settings/production.py b/artel/artel/settings/production.py index f885e60..0faaaa5 100644 --- a/artel/artel/settings/production.py +++ b/artel/artel/settings/production.py @@ -7,10 +7,12 @@ ALLOWED_HOSTS = [ "localhost", "0.0.0.0", "127.0.0.1", + "artel.citizen4.eu", "artel.tepewu.pl" ] CSRF_TRUSTED_ORIGINS = [ "https://0.0.0.0", "http://0.0.0.0", "https://localhost", "http://localhost", - "https://artel.tepewu.pl" + "https://artel.tepewu.pl", + "https://artel.citizen4.eu", ] diff --git a/artel/artel/urls.py b/artel/artel/urls.py index 720ae2a..edfa02e 100644 --- a/artel/artel/urls.py +++ b/artel/artel/urls.py @@ -12,6 +12,8 @@ from wagtail.documents import urls as wagtaildocs_urls from search import views as search_views +handler404 = 'artel.views.my_custom_page_not_found_view' + urlpatterns = [ path("django-admin/", admin.site.urls), path("admin/", include(wagtailadmin_urls)), diff --git a/artel/artel/views.py b/artel/artel/views.py new file mode 100644 index 0000000..7a3135b --- /dev/null +++ b/artel/artel/views.py @@ -0,0 +1,11 @@ +from django.conf import settings +from django.http import HttpResponseNotFound +from sentry_sdk import capture_message + + +def my_custom_page_not_found_view(*args, **kwargs): + if settings.SENTRY_ENVIRONMENT != 'production': + capture_message("Page not found!", level="error") + + # return any response here, e.g.: + return HttpResponseNotFound("Not found") diff --git a/artel/docker-compose-prod.yml b/artel/docker-compose-prod.yml index 237b033..91ed14b 100644 --- a/artel/docker-compose-prod.yml +++ b/artel/docker-compose-prod.yml @@ -23,7 +23,7 @@ services: user: "${UID}:${GID}" restart: always ports: - - "8001:8000" + - "8000:8000" volumes: - ./:/app environment: diff --git a/artel/docker-compose-stack.yml b/artel/docker-compose-stack.yml new file mode 100644 index 0000000..622d984 --- /dev/null +++ b/artel/docker-compose-stack.yml @@ -0,0 +1,93 @@ +version: "3.8" +services: + + db: + image: postgres + restart: always + environment: + - POSTGRES_ROOT_PASSWORD=${POSTGRES_ROOT_PASSWORD} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + volumes: + - db:/var/lib/postgresql/data + networks: + - internal + deploy: + resources: + limits: + cpus: '1.0' + memory: 512M + + comfy: + image: comfy + user: "${UID}:${GID}" + restart: always + ports: + - "8000" + volumes: + - media:/app/media + - static:/app/static + environment: + - SECRET_KEY=${SECRET_KEY} + - DATABASE_URL=${DATABASE_URL} + - DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE} + - SENTRY_DSN=${SENTRY_DSN} + - SENTRY_ENVIRONMENT=${SENTRY_ENVIRONMENT} + - EMAIL_HOST=${EMAIL_HOST} + - EMAIL_HOST_USER=${EMAIL_HOST_USER} + - EMAIL_HOST_PASSWORD=${EMAIL_HOST_PASSWORD} + - EMAIL_PORT=${EMAIL_PORT} + - EMAIL_USE_TLS=${EMAIL_USE_TLS} + - DEFAULT_FROM_EMAIL=${DEFAULT_FROM_EMAIL} + depends_on: + - db + networks: + - internal + deploy: + resources: + limits: + cpus: '1.0' + memory: 512M + + web: + image: nginx + restart: always + volumes: + - nginx:/etc/nginx/conf.d + - static:/opt/services/comfy/static + - media:/opt/services/comfy/media + ports: + - "80" + environment: + - NGINX_HOST=${NGINX_HOST} + - NGINX_PORT=${NGINX_PORT} + networks: + - internal + - web + deploy: + resources: + limits: + cpus: '1.0' + memory: 256M + labels: + - "traefik.enable=true" + - "traefik.docker.network=web" + - "traefik.http.routers.artel.rule=Host(`${NGINX_HOST}`)" + - "traefik.http.routers.artel.entrypoints=websecure" + - "traefik.http.services.artel.loadbalancer.server.port=80" + - "traefik.http.routers.artel.tls=true" + - "traefik.http.routers.artel.tls.certresolver=ovh" + +volumes: + db: + media: + static: + nginx: + +networks: + internal: + web: + external: + name: web + diff --git a/artel/docker-compose.yml b/artel/docker-compose.yml index 280cffa..7a4e937 100644 --- a/artel/docker-compose.yml +++ b/artel/docker-compose.yml @@ -11,9 +11,10 @@ services: context: ./ user: "${UID}:${GID}" ports: - - "8000:8000" + - "8001:8000" volumes: - - ./:/app +# - ./:/app + - media:/app/media environment: - SECRET_KEY - DATABASE_URL @@ -30,6 +31,17 @@ services: - POSTGRES_PASSWORD - POSTGRES_DB volumes: - - ../postgres/:/var/lib/postgresql + - db:/var/lib/postgresql/data env_file: - .env + + adminer: + image: adminer + restart: always + ports: + - "8002:8080" + + +volumes: + media: + db: diff --git a/artel/requirements.txt b/artel/requirements.txt index 7b1f252..65539f3 100644 --- a/artel/requirements.txt +++ b/artel/requirements.txt @@ -8,4 +8,5 @@ phonenumbers==8.13.13 django-phonenumber-field==7.1.0 factory-boy==3.2.1 pdfkit==1.0.0 -num2words==0.5.12 \ No newline at end of file +num2words==0.5.12 +sentry-sdk==1.28.0