From 8193e79c195298023bb5c00c2e6538781e2b9074 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Mon, 20 Apr 2026 19:06:01 -0300 Subject: [PATCH] Base project --- .idea/.gitignore | 10 ++ .idea/canasta-back.iml | 30 +++++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 7 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + Dockerfile | 51 +++++++ canasta_back_app/__init__.py | 0 canasta_back_app/asgi.py | 16 +++ canasta_back_app/settings.py | 127 ++++++++++++++++++ canasta_back_app/urls.py | 22 +++ canasta_back_app/wsgi.py | 16 +++ compose.yml | 37 +++++ manage.py | 22 +++ requirements.txt | 5 + 15 files changed, 363 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/canasta-back.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Dockerfile create mode 100644 canasta_back_app/__init__.py create mode 100644 canasta_back_app/asgi.py create mode 100644 canasta_back_app/settings.py create mode 100644 canasta_back_app/urls.py create mode 100644 canasta_back_app/wsgi.py create mode 100644 compose.yml create mode 100755 manage.py create mode 100644 requirements.txt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..30cf57e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/canasta-back.iml b/.idea/canasta-back.iml new file mode 100644 index 0000000..bb44714 --- /dev/null +++ b/.idea/canasta-back.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b3cb22d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d540838 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..92bb11e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +# Stage 1: Base build stage +FROM python:3.13-slim AS builder + +# Create the app directory +RUN mkdir /app + +# Set the working directory +WORKDIR /app + +# Set environment variables to optimize Python +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +# Upgrade pip and install dependencies +RUN pip install --upgrade pip + +# Copy the requirements file first (better caching) +COPY requirements.txt /app/ + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Stage 2: Production stage +FROM python:3.13-slim + +RUN useradd -m -r appuser && \ + mkdir /app && \ + chown -R appuser /app + +# Copy the Python dependencies from the builder stage +COPY --from=builder /usr/local/lib/python3.13/site-packages/ /usr/local/lib/python3.13/site-packages/ +COPY --from=builder /usr/local/bin/ /usr/local/bin/ + +# Set the working directory +WORKDIR /app + +# Copy application code +COPY --chown=appuser:appuser . . + +# Set environment variables to optimize Python +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +# Switch to non-root user +USER appuser + +# Expose the application port +EXPOSE 8000 + +# Start the application using Gunicorn +CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "canasta_back_app.wsgi:application"] \ No newline at end of file diff --git a/canasta_back_app/__init__.py b/canasta_back_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/canasta_back_app/asgi.py b/canasta_back_app/asgi.py new file mode 100644 index 0000000..8b7a79d --- /dev/null +++ b/canasta_back_app/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for canasta_back_app project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'canasta_back_app.settings') + +application = get_asgi_application() diff --git a/canasta_back_app/settings.py b/canasta_back_app/settings.py new file mode 100644 index 0000000..e52e483 --- /dev/null +++ b/canasta_back_app/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for canasta_back_app project. + +Generated by 'django-admin startproject' using Django 6.0.4. + +For more information on this file, see +https://docs.djangoproject.com/en/6.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/6.0/ref/settings/ +""" + +from pathlib import Path +import os + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY") + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = bool(os.environ.get("DEBUG", default=0)) + + +# 'DJANGO_ALLOWED_HOSTS' should be a single string of hosts with a `,` between each. +# For example: 'DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1,[::1]' +ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS","127.0.0.1").split(",") + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'canasta_back_app.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [BASE_DIR / 'templates'] + , + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'canasta_back_app.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/6.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.{}'.format( + os.getenv('DATABASE_ENGINE', 'sqlite3') + ), + 'NAME': os.getenv('DATABASE_NAME', 'polls'), + 'USER': os.getenv('DATABASE_USERNAME', 'myprojectuser'), + 'PASSWORD': os.getenv('DATABASE_PASSWORD', 'password'), + 'HOST': os.getenv('DATABASE_HOST', '127.0.0.1'), + 'PORT': os.getenv('DATABASE_PORT', 5432), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/6.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/6.0/howto/static-files/ + +STATIC_URL = 'static/' diff --git a/canasta_back_app/urls.py b/canasta_back_app/urls.py new file mode 100644 index 0000000..738476d --- /dev/null +++ b/canasta_back_app/urls.py @@ -0,0 +1,22 @@ +""" +URL configuration for canasta_back_app project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/6.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/canasta_back_app/wsgi.py b/canasta_back_app/wsgi.py new file mode 100644 index 0000000..b5d1275 --- /dev/null +++ b/canasta_back_app/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for canasta_back_app project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'canasta_back_app.settings') + +application = get_wsgi_application() diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..7641ca7 --- /dev/null +++ b/compose.yml @@ -0,0 +1,37 @@ +services: + db: + image: postgres:17 + environment: + POSTGRES_DB: ${DATABASE_NAME} + POSTGRES_USER: ${DATABASE_USERNAME} + POSTGRES_PASSWORD: ${DATABASE_PASSWORD} + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + env_file: + - .env + + django-web: + build: . + container_name: django-docker + ports: + - "8000:8000" + depends_on: + - db + environment: + DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY} + DEBUG: ${DEBUG} + DJANGO_LOGLEVEL: ${DJANGO_LOGLEVEL} + DJANGO_ALLOWED_HOSTS: ${DJANGO_ALLOWED_HOSTS} + DATABASE_ENGINE: ${DATABASE_ENGINE} + DATABASE_NAME: ${DATABASE_NAME} + DATABASE_USERNAME: ${DATABASE_USERNAME} + + DATABASE_PASSWORD: ${DATABASE_PASSWORD} + DATABASE_HOST: ${DATABASE_HOST} + DATABASE_PORT: ${DATABASE_PORT} + env_file: + - .env +volumes: + postgres_data: diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..fcbc509 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'canasta_back_app.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..de1aad9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +asgiref==3.11.1 +Django==6.0.4 +sqlparse==0.5.5 +gunicorn==25.3.0 +psycopg2-binary==2.9.11