diff --git a/.gitignore b/.gitignore index bfa0621..7fda18d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ - +.env .idea/* +static/admin/ +static/django_extensions/ \ No newline at end of file diff --git a/Caddyfile.dev b/Caddyfile similarity index 82% rename from Caddyfile.dev rename to Caddyfile index 6d6920d..51e7b18 100644 --- a/Caddyfile.dev +++ b/Caddyfile @@ -1,4 +1,4 @@ -http://api.localhost +http://ccstech.localhost root * /usr/src/app/ diff --git a/Caddyfile.pro b/Caddyfile.pro deleted file mode 100644 index 92cdc0d..0000000 --- a/Caddyfile.pro +++ /dev/null @@ -1,11 +0,0 @@ -https://api.com - -root * /usr/src/app/ - -@notStatic { - not path /static/* /media/* -} - -reverse_proxy @notStatic django:8000 - -file_server diff --git a/Caddyfile.staging b/Caddyfile.staging deleted file mode 100644 index 78c735f..0000000 --- a/Caddyfile.staging +++ /dev/null @@ -1,11 +0,0 @@ -https://beta.api.com - -root * /usr/src/app/ - -@notStatic { - not path /static/* /media/* -} - -reverse_proxy @notStatic django:8000 - -file_server diff --git a/Dockerfiles/django/Dockerfile b/Dockerfiles/django/Dockerfile index 768ea2e..c19e5f2 100644 --- a/Dockerfiles/django/Dockerfile +++ b/Dockerfiles/django/Dockerfile @@ -23,7 +23,5 @@ COPY ./requirements.txt . RUN pip3 install -r requirements.txt # launcher -COPY django-launcher.dev.sh /django-launcher.dev.sh -COPY django-launcher.pro.sh /django-launcher.pro.sh -RUN chmod +x /django-launcher.dev.sh -RUN chmod +x /django-launcher.pro.sh +COPY django-launcher.sh /django-launcher.sh +RUN chmod +x /django-launcher.sh diff --git a/Makefile b/Makefile index b4aedbb..b02098a 100644 --- a/Makefile +++ b/Makefile @@ -9,15 +9,15 @@ format: ## Format style with black black --exclude="/(postgres|venv|migrations|\.git)/" . docker.recreate.django: ## Recreate Django image - docker-compose -f docker-compose.dev.yaml build --no-cache --force-rm django - docker-compose -f docker-compose.dev.yaml up --force-recreate --no-deps -d django + docker-compose -f docker-compose.yaml build --no-cache --force-rm django + docker-compose -f docker-compose.yaml up --force-recreate --no-deps -d django make run.loaddata run.makemigrations: ## Makemigrations - docker-compose -f docker-compose.dev.yaml exec -T django bash -c "python3 manage.py makemigrations" + docker-compose -f docker-compose.yaml exec -T django bash -c "python3 manage.py makemigrations" run.migrate: ## Migrate - docker-compose -f docker-compose.dev.yaml exec -T django bash -c "python3 manage.py migrate" + docker-compose -f docker-compose.yaml exec -T django bash -c "python3 manage.py migrate" run.loaddata: ## Load initial data # Remove database @@ -25,14 +25,14 @@ run.loaddata: ## Load initial data # Remove media rm -rf media # Migrate - docker-compose -f docker-compose.dev.yaml exec -T django bash -c "python3 manage.py migrate" + docker-compose -f docker-compose.yaml exec -T django bash -c "python3 manage.py migrate" run.loaddata.test: ## Load initial data test make run.loaddata # Add superuser: alias "admin" - password "admin" - docker-compose -f docker-compose.dev.yaml exec -T django bash -c "cat data/create_superuser.py | python3 manage.py shell" + docker-compose -f docker-compose.yaml exec -T django bash -c "cat data/create_superuser.py | python3 manage.py shell" # Add more users: alias random - password "password" - docker-compose -f docker-compose.dev.yaml exec -T django bash -c "cat data/create_users.py | python3 manage.py shell" + docker-compose -f docker-compose.yaml exec -T django bash -c "cat data/create_users.py | python3 manage.py shell" run.server: ## Run server - docker-compose -f docker-compose.dev.yaml up + docker-compose -f docker-compose.yaml up diff --git a/README.md b/README.md index d0a6835..11f7637 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ make run.server Now open: -`http://api.localhost` +`http://ccstech.localhost` ## Gulp @@ -68,15 +68,15 @@ make run.loaddata.test ## Other domains -- Caddy: `http://api.localhost`. -- Gulp: `http://api.localhost:3000`. -- Django: `http://api.localhost:8000`. -- Mailhog: `http://api.localhost:8025`. +- Caddy: `http://ccstech.localhost`. +- Gulp: `http://ccstech.localhost:3000`. +- Django: `http://ccstech.localhost:8000`. +- Mailhog: `http://ccstech.localhost:8025`. ### Bash Django ``` shell -docker exec -it api_django_1 bash +docker exec -it ccstech_django_1 bash ``` # Run production @@ -85,4 +85,4 @@ docker exec -it api_django_1 bash docker-compose -f docker-compose.pro.yaml up ``` -Open `https://domain.com`. +Open `https://ccstech.io`. diff --git a/app/website/__init__.py b/app/website/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/website/admin.py b/app/website/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/app/website/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/app/website/apps.py b/app/website/apps.py new file mode 100644 index 0000000..b8fd484 --- /dev/null +++ b/app/website/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class WebsiteConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'app.website' diff --git a/app/website/migrations/__init__.py b/app/website/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/website/models.py b/app/website/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/app/website/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/app/website/templates/home.html b/app/website/templates/home.html new file mode 100644 index 0000000..15f747a --- /dev/null +++ b/app/website/templates/home.html @@ -0,0 +1 @@ +

Hi

\ No newline at end of file diff --git a/app/website/tests.py b/app/website/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/app/website/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/app/website/views.py b/app/website/views.py new file mode 100644 index 0000000..35fb3dc --- /dev/null +++ b/app/website/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render + +# Create your views here. +def home(request): + return render(request, 'home.html') \ No newline at end of file diff --git a/ccstech/__init__.py b/ccstech/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ccstech/asgi.py b/ccstech/asgi.py new file mode 100644 index 0000000..a11ad89 --- /dev/null +++ b/ccstech/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for ccstech 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ccstech.settings') + +application = get_asgi_application() diff --git a/settings.py b/ccstech/settings.py similarity index 97% rename from settings.py rename to ccstech/settings.py index ec058c9..aedd0ff 100644 --- a/settings.py +++ b/ccstech/settings.py @@ -42,10 +42,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'django_extensions', - 'rest_framework', - 'app.account', - 'app.auction', - 'app.notification', + 'app.website', ] MIDDLEWARE = [ @@ -58,7 +55,7 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] -ROOT_URLCONF = 'gotrucki.urls' +ROOT_URLCONF = 'ccstech.urls' TEMPLATES = [ { diff --git a/ccstech/urls.py b/ccstech/urls.py new file mode 100644 index 0000000..e594313 --- /dev/null +++ b/ccstech/urls.py @@ -0,0 +1,23 @@ +"""ccstech URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.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 +from app.website import views as website_views + +urlpatterns = [ + path('', website_views.home, name='home'), + path('admin/', admin.site.urls), +] diff --git a/ccstech/wsgi.py b/ccstech/wsgi.py new file mode 100644 index 0000000..08b6afb --- /dev/null +++ b/ccstech/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for ccstech 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ccstech.settings') + +application = get_wsgi_application() diff --git a/django-launcher.dev.sh b/django-launcher.dev.sh deleted file mode 100644 index 6b77191..0000000 --- a/django-launcher.dev.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -# Collect static files -echo "Collect static files" -python3 manage.py collectstatic --noinput - -# Apply database migrations -echo "Apply database migrations" -python3 manage.py makemigrations -python3 manage.py migrate - -# Start server -echo "Starting server" -## With WebSockets -uvicorn --host 0.0.0.0 --port 8000 --reload chapps.asgi:application -## without WebSockets -#gunicorn --workers=4 -b 0.0.0.0:8000 --reload gotrucki.wsgi:application diff --git a/django-launcher.pro.sh b/django-launcher.sh similarity index 68% rename from django-launcher.pro.sh rename to django-launcher.sh index 2d9fd37..990988f 100644 --- a/django-launcher.pro.sh +++ b/django-launcher.sh @@ -12,6 +12,6 @@ python3 manage.py migrate # Start server echo "Starting server" ## With WebSockets -uvicorn --workers=4 --host 0.0.0.0 --port 8000 chapps.asgi:application +uvicorn --host 0.0.0.0 --port 8000 --reload ccstech.asgi:application ## without WebSockets -#gunicorn --workers=4 -b 0.0.0.0:8000 gotrucki.wsgi:application +#gunicorn --workers=4 -b 0.0.0.0:8000 --reload ccstech.wsgi:application diff --git a/docker-compose.pro.yaml b/docker-compose.pro.yaml deleted file mode 100644 index 425969c..0000000 --- a/docker-compose.pro.yaml +++ /dev/null @@ -1,76 +0,0 @@ -version: '3.1' - -services: - - postgresql: - image: postgres - restart: always - environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: sapps - expose: - - 5432 - - django: - build: - context: ./ - dockerfile: ./Dockerfiles/django/Dockerfile - restart: always - entrypoint: /django-launcher.pro.sh - volumes: - - .:/usr/src/app/ - environment: - DEBUG: "False" - ALLOWED_HOSTS: "" - SECRET_KEY: "secret" - DB_ENGINE: "django.db.backends.postgresql" - DB_NAME: "sapps" - DB_USER: "postgres" - DB_PASSWORD: "postgres" - DB_HOST: "postgresql" - DB_PORT: "5432" - DOMAIN: "ejemplo.com" - DOMAIN_URL: "https://ejemplo.com" - STATIC_URL: "/static/" - STATIC_ROOT: "static" - MEDIA_URL: "/media/" - REDIS_HOST: "redis" - REDIS_PORT: "6379" - EMAIL_HOST: "" - EMAIL_USE_TLS: "True" - EMAIL_PORT: "2525" - EMAIL_USER: "" - EMAIL_PASSWORD: "" - expose: - - 8000 - depends_on: - - postgresql - - caddy: - image: caddy:alpine - restart: always - ports: - - 80:80 - - 443:443 - volumes: - - .:/usr/src/app/ - - ./Caddyfile.pro:/etc/caddy/Caddyfile - - ./../caddy_data:/data - depends_on: - - django - - redis: - image: redis:alpine - restart: unless-stopped - expose: - - 6379 - - gulp: - build: Dockerfiles/gulp - restart: always - command: gulp - volumes: - - .:/app/ - depends_on: - - caddy diff --git a/docker-compose.staging.yaml b/docker-compose.staging.yaml deleted file mode 100644 index 834a763..0000000 --- a/docker-compose.staging.yaml +++ /dev/null @@ -1,76 +0,0 @@ -version: '3.1' - -services: - - postgresql: - image: postgres - restart: always - environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: sapps - expose: - - 5432 - - django: - build: - context: ./ - dockerfile: ./Dockerfiles/django/Dockerfile - restart: always - entrypoint: /django-launcher.dev.sh - volumes: - - .:/usr/src/app/ - environment: - DEBUG: "True" - ALLOWED_HOSTS: "" - SECRET_KEY: "secret" - DB_ENGINE: "django.db.backends.postgresql" - DB_NAME: "sapps" - DB_USER: "postgres" - DB_PASSWORD: "postgres" - DB_HOST: "postgresql" - DB_PORT: "5432" - DOMAIN: "ejemplo.com" - DOMAIN_URL: "https://ejemplo.com" - STATIC_URL: "/static/" - STATIC_ROOT: "static" - MEDIA_URL: "/media/" - REDIS_HOST: "redis" - REDIS_PORT: "6379" - EMAIL_HOST: "" - EMAIL_USE_TLS: "True" - EMAIL_PORT: "2525" - EMAIL_USER: "" - EMAIL_PASSWORD: "" - expose: - - 8000 - depends_on: - - postgresql - - caddy: - image: caddy:alpine - restart: always - ports: - - 80:80 - - 443:443 - volumes: - - .:/usr/src/app/ - - ./Caddyfile.staging:/etc/caddy/Caddyfile - - ./../caddy_data:/data - depends_on: - - django - - redis: - image: redis:alpine - restart: unless-stopped - expose: - - 6379 - - gulp: - build: Dockerfiles/gulp - restart: always - command: gulp - volumes: - - .:/app/ - depends_on: - - caddy diff --git a/docker-compose.dev.yaml b/docker-compose.yaml similarity index 68% rename from docker-compose.dev.yaml rename to docker-compose.yaml index 0acf796..219cb24 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.yaml @@ -1,4 +1,4 @@ -version: '3.1' +version: '3.8' services: @@ -6,9 +6,9 @@ services: image: postgres restart: "no" environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: nombre-base-de-datos + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + POSTGRES_DB: "ccstech" ports: - 5432:5432 @@ -16,22 +16,22 @@ services: build: context: ./ dockerfile: ./Dockerfiles/django/Dockerfile - restart: unless-stopped - entrypoint: /django-launcher.dev.sh + restart: "no" + entrypoint: /django-launcher.sh volumes: - .:/usr/src/app/ environment: DEBUG: "True" - ALLOWED_HOSTS: "ejemplo.localhost" + ALLOWED_HOSTS: "ccstech.localhost" SECRET_KEY: "misecreto" DB_ENGINE: "django.db.backends.postgresql" - DB_NAME: "nombre-base-de-datos" + DB_NAME: "ccstech" DB_USER: "postgres" DB_PASSWORD: "postgres" DB_HOST: "postgresql" DB_PORT: "5432" - DOMAIN: "ejemplo.localhost" - DOMAIN_URL: "http://ejemplo.localhost" + DOMAIN: "ccstech.localhost" + DOMAIN_URL: "http://ccstech.localhost" STATIC_URL: "/static/" STATIC_ROOT: "static" MEDIA_URL: "/media/" @@ -49,26 +49,26 @@ services: caddy: image: caddy:alpine - restart: unless-stopped + restart: "no" ports: - 80:80 - 443:443 volumes: - - ./Caddyfile.dev:/etc/caddy/Caddyfile - - ./../caddy_data:/data + - ./Caddyfile:/etc/caddy/Caddyfile + - ./caddy_data:/data - .:/usr/src/app/ depends_on: - django redis: image: redis:alpine - restart: unless-stopped + restart: "no" expose: - 6379 mailhog: image: mailhog/mailhog:latest - restart: unless-stopped + restart: "no" expose: - 1025 ports: diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..393e21e --- /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', 'ccstech.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 index 5d91421..2548d31 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,31 +1,18 @@ # Django -django===3.2.7 -django-extensions===3.1.3 +django===4.0.5 +django-extensions===3.1.5 # PostgreSQL driver -psycopg2===2.9.1 +psycopg2-binary===2.9.3 # Servidor para Django sin Websockets gunicorn===20.1.0 # Servidor para Django con Websockets -uvicorn===0.13.4 -websockets===9.1 +uvicorn===0.18.1 +websockets===10.3 # Channels -channels==2.4.0 -asgiref===3.3.4 +channels==3.0.5 +asgiref===3.5.2 # Conector de Redis para Channels -channels_redis===3.2.0 -# Django REST framework -djangorestframework -markdown -django-filter +channels_redis===3.4.0 # Template -## Componentes - https://mitchel.me/slippers/ -slippers -# WYSIWYG editor Python Django admin -django-tinymce===3.3.0 -# Testing -pytest-django -pytest # Pillow -Pillow===8.2.0 -# Linter -black +Pillow===9.1.1 \ No newline at end of file