diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..052bd4b77c32411c9daba269fb12245a9c775c1b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +fly.toml +.git/ +*.sqlite3 +env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..52f73ed5e1429fb8c98b3baddbb4c69188c9a6c5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +ARG PYTHON_VERSION=3.11-slim + +FROM python:${PYTHON_VERSION} + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +RUN mkdir -p /code + +WORKDIR /code + +COPY requirements.txt /tmp/requirements.txt +RUN set -ex && \ + pip install --upgrade pip && \ + pip install -r /tmp/requirements.txt && \ + rm -rf /root/.cache/ +COPY . /code + +RUN apt-get update && apt-get install -y \ + sqlite3 \ + && rm -rf /var/lib/apt/lists/* + +RUN python manage.py collectstatic --noinput + +# Create data directory for SQLite +RUN mkdir -p /data +VOLUME /data + +RUN chmod +x startup.sh +EXPOSE 8000 +ENTRYPOINT ["./startup.sh"] diff --git a/education/views.py b/education/views.py index 3b44b070572c18d898169611ef9789af1c485482..0d9307a019cfcbbc432e2be9ace55a1190e038c0 100644 --- a/education/views.py +++ b/education/views.py @@ -14,7 +14,7 @@ def show_create(request: HttpRequest): form = EdukasiForm(request.POST) if form.is_valid(): form.save() - return redirect('show-all') # Redirect to a success page + return redirect('education-show-all') # Redirect to a success page else: form = EdukasiForm() diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000000000000000000000000000000000000..3eb1af2e19e28a5409476aa05b116f8bb3e96bd6 --- /dev/null +++ b/fly.toml @@ -0,0 +1,35 @@ +# fly.toml app configuration file generated for el-pekape on 2025-03-14T21:08:45+07:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'el-pekape' +primary_region = 'sin' +console_command = '/code/manage.py shell' + +[build] + +[env] + PORT = '8000' + +[mounts] + source="data" + destination="/data" + +[http_service] + internal_port = 8000 + force_https = true + auto_stop_machines = 'stop' + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1 + +[[statics]] + guest_path = '/code/static' + url_prefix = '/static/' + diff --git a/main/settings.py b/main/settings.py index 1fa4028f38a772ef9f94316bc9dfe2a5c25f8c2a..701a061407ce3863e802ce0b508a99c532ec6f18 100644 --- a/main/settings.py +++ b/main/settings.py @@ -11,8 +11,6 @@ https://docs.djangoproject.com/en/5.1/ref/settings/ """ from pathlib import Path -from django.conf import settings -from django.conf.urls.static import static import os # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -30,6 +28,11 @@ DEBUG = True ALLOWED_HOSTS = ['*'] +CSRF_TRUSTED_ORIGINS = [ + "https://el-pekape.fly.dev", + "https://pkpl.andrew-devito.website", +] + # Application definition @@ -78,10 +81,14 @@ WSGI_APPLICATION = 'main.wsgi.application' # Database # https://docs.djangoproject.com/en/5.1/ref/settings/#databases +import dotenv + +env = dotenv.dotenv_values() + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + 'NAME': os.path.join('/data', 'db.sqlite3'), # Store SQLite in /data } } diff --git a/main/urls.py b/main/urls.py index f1afc3cdf114f1c624a32ca6b8f8044c57439403..c3e770cab592fb6f4cc40279d968e8009a0c012b 100644 --- a/main/urls.py +++ b/main/urls.py @@ -23,5 +23,4 @@ urlpatterns = [ path("", show_home, name="home"), path('education/', include('education.urls')), path('finance/', include('finance.urls')), - path("__reload__/", include("django_browser_reload.urls")), ] diff --git a/requirements.txt b/requirements.txt index d3e4ba564fbf9ac31944e674cfb4469113120ab1..c8a11c66e5f79c39501cedcb894b14c0cd732622 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,5 @@ django +dotenv +dj_database_url +gunicorn +config \ No newline at end of file diff --git a/startup.sh b/startup.sh new file mode 100644 index 0000000000000000000000000000000000000000..ee4a0155758f75042216985f2ba2c8ff114b888f --- /dev/null +++ b/startup.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# Ensure volume is mounted +mkdir -p /data + +# Run migrations +python manage.py migrate + +# Enable WAL mode for better durability +sqlite3 /data/db.sqlite3 'PRAGMA journal_mode=WAL;' +sqlite3 /data/db.sqlite3 'PRAGMA synchronous=1;' + +# Start Gunicorn server +gunicorn --bind :8000 --workers 2 main.wsgi