Add template

This commit is contained in:
Andros Fenollosa 2022-06-27 14:28:40 +02:00
parent 4f50295287
commit 400d0f1b9c
27 changed files with 147 additions and 256 deletions

4
.gitignore vendored
View File

@ -1,2 +1,4 @@
.env
.idea/* .idea/*
static/admin/
static/django_extensions/

View File

@ -1,4 +1,4 @@
http://api.localhost http://ccstech.localhost
root * /usr/src/app/ root * /usr/src/app/

View File

@ -1,11 +0,0 @@
https://api.com
root * /usr/src/app/
@notStatic {
not path /static/* /media/*
}
reverse_proxy @notStatic django:8000
file_server

View File

@ -1,11 +0,0 @@
https://beta.api.com
root * /usr/src/app/
@notStatic {
not path /static/* /media/*
}
reverse_proxy @notStatic django:8000
file_server

View File

@ -23,7 +23,5 @@ COPY ./requirements.txt .
RUN pip3 install -r requirements.txt RUN pip3 install -r requirements.txt
# launcher # launcher
COPY django-launcher.dev.sh /django-launcher.dev.sh COPY django-launcher.sh /django-launcher.sh
COPY django-launcher.pro.sh /django-launcher.pro.sh RUN chmod +x /django-launcher.sh
RUN chmod +x /django-launcher.dev.sh
RUN chmod +x /django-launcher.pro.sh

View File

@ -9,15 +9,15 @@ format: ## Format style with black
black --exclude="/(postgres|venv|migrations|\.git)/" . black --exclude="/(postgres|venv|migrations|\.git)/" .
docker.recreate.django: ## Recreate Django image docker.recreate.django: ## Recreate Django image
docker-compose -f docker-compose.dev.yaml build --no-cache --force-rm django docker-compose -f docker-compose.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 up --force-recreate --no-deps -d django
make run.loaddata make run.loaddata
run.makemigrations: ## Makemigrations 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 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 run.loaddata: ## Load initial data
# Remove database # Remove database
@ -25,14 +25,14 @@ run.loaddata: ## Load initial data
# Remove media # Remove media
rm -rf media rm -rf media
# 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.test: ## Load initial data test run.loaddata.test: ## Load initial data test
make run.loaddata make run.loaddata
# Add superuser: alias "admin" - password "admin" # 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" # 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 run.server: ## Run server
docker-compose -f docker-compose.dev.yaml up docker-compose -f docker-compose.yaml up

View File

@ -8,7 +8,7 @@ make run.server
Now open: Now open:
`http://api.localhost` `http://ccstech.localhost`
## Gulp ## Gulp
@ -68,15 +68,15 @@ make run.loaddata.test
## Other domains ## Other domains
- Caddy: `http://api.localhost`. - Caddy: `http://ccstech.localhost`.
- Gulp: `http://api.localhost:3000`. - Gulp: `http://ccstech.localhost:3000`.
- Django: `http://api.localhost:8000`. - Django: `http://ccstech.localhost:8000`.
- Mailhog: `http://api.localhost:8025`. - Mailhog: `http://ccstech.localhost:8025`.
### Bash Django ### Bash Django
``` shell ``` shell
docker exec -it api_django_1 bash docker exec -it ccstech_django_1 bash
``` ```
# Run production # Run production
@ -85,4 +85,4 @@ docker exec -it api_django_1 bash
docker-compose -f docker-compose.pro.yaml up docker-compose -f docker-compose.pro.yaml up
``` ```
Open `https://domain.com`. Open `https://ccstech.io`.

0
app/website/__init__.py Normal file
View File

3
app/website/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
app/website/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class WebsiteConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'app.website'

View File

3
app/website/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@ -0,0 +1 @@
<h1>Hi</h1>

3
app/website/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

5
app/website/views.py Normal file
View File

@ -0,0 +1,5 @@
from django.shortcuts import render
# Create your views here.
def home(request):
return render(request, 'home.html')

0
ccstech/__init__.py Normal file
View File

16
ccstech/asgi.py Normal file
View File

@ -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()

View File

@ -42,10 +42,7 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django_extensions', 'django_extensions',
'rest_framework', 'app.website',
'app.account',
'app.auction',
'app.notification',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -58,7 +55,7 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ]
ROOT_URLCONF = 'gotrucki.urls' ROOT_URLCONF = 'ccstech.urls'
TEMPLATES = [ TEMPLATES = [
{ {

23
ccstech/urls.py Normal file
View File

@ -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),
]

16
ccstech/wsgi.py Normal file
View File

@ -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()

View File

@ -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

View File

@ -12,6 +12,6 @@ python3 manage.py migrate
# Start server # Start server
echo "Starting server" echo "Starting server"
## With WebSockets ## 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 ## 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

View File

@ -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

View File

@ -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

View File

@ -1,4 +1,4 @@
version: '3.1' version: '3.8'
services: services:
@ -6,9 +6,9 @@ services:
image: postgres image: postgres
restart: "no" restart: "no"
environment: environment:
POSTGRES_USER: postgres POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: "postgres"
POSTGRES_DB: nombre-base-de-datos POSTGRES_DB: "ccstech"
ports: ports:
- 5432:5432 - 5432:5432
@ -16,22 +16,22 @@ services:
build: build:
context: ./ context: ./
dockerfile: ./Dockerfiles/django/Dockerfile dockerfile: ./Dockerfiles/django/Dockerfile
restart: unless-stopped restart: "no"
entrypoint: /django-launcher.dev.sh entrypoint: /django-launcher.sh
volumes: volumes:
- .:/usr/src/app/ - .:/usr/src/app/
environment: environment:
DEBUG: "True" DEBUG: "True"
ALLOWED_HOSTS: "ejemplo.localhost" ALLOWED_HOSTS: "ccstech.localhost"
SECRET_KEY: "misecreto" SECRET_KEY: "misecreto"
DB_ENGINE: "django.db.backends.postgresql" DB_ENGINE: "django.db.backends.postgresql"
DB_NAME: "nombre-base-de-datos" DB_NAME: "ccstech"
DB_USER: "postgres" DB_USER: "postgres"
DB_PASSWORD: "postgres" DB_PASSWORD: "postgres"
DB_HOST: "postgresql" DB_HOST: "postgresql"
DB_PORT: "5432" DB_PORT: "5432"
DOMAIN: "ejemplo.localhost" DOMAIN: "ccstech.localhost"
DOMAIN_URL: "http://ejemplo.localhost" DOMAIN_URL: "http://ccstech.localhost"
STATIC_URL: "/static/" STATIC_URL: "/static/"
STATIC_ROOT: "static" STATIC_ROOT: "static"
MEDIA_URL: "/media/" MEDIA_URL: "/media/"
@ -49,26 +49,26 @@ services:
caddy: caddy:
image: caddy:alpine image: caddy:alpine
restart: unless-stopped restart: "no"
ports: ports:
- 80:80 - 80:80
- 443:443 - 443:443
volumes: volumes:
- ./Caddyfile.dev:/etc/caddy/Caddyfile - ./Caddyfile:/etc/caddy/Caddyfile
- ./../caddy_data:/data - ./caddy_data:/data
- .:/usr/src/app/ - .:/usr/src/app/
depends_on: depends_on:
- django - django
redis: redis:
image: redis:alpine image: redis:alpine
restart: unless-stopped restart: "no"
expose: expose:
- 6379 - 6379
mailhog: mailhog:
image: mailhog/mailhog:latest image: mailhog/mailhog:latest
restart: unless-stopped restart: "no"
expose: expose:
- 1025 - 1025
ports: ports:

22
manage.py Executable file
View File

@ -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()

View File

@ -1,31 +1,18 @@
# Django # Django
django===3.2.7 django===4.0.5
django-extensions===3.1.3 django-extensions===3.1.5
# PostgreSQL driver # PostgreSQL driver
psycopg2===2.9.1 psycopg2-binary===2.9.3
# Servidor para Django sin Websockets # Servidor para Django sin Websockets
gunicorn===20.1.0 gunicorn===20.1.0
# Servidor para Django con Websockets # Servidor para Django con Websockets
uvicorn===0.13.4 uvicorn===0.18.1
websockets===9.1 websockets===10.3
# Channels # Channels
channels==2.4.0 channels==3.0.5
asgiref===3.3.4 asgiref===3.5.2
# Conector de Redis para Channels # Conector de Redis para Channels
channels_redis===3.2.0 channels_redis===3.4.0
# Django REST framework
djangorestframework
markdown
django-filter
# Template # Template
## Componentes - https://mitchel.me/slippers/
slippers
# WYSIWYG editor Python Django admin
django-tinymce===3.3.0
# Testing
pytest-django
pytest
# Pillow # Pillow
Pillow===8.2.0 Pillow===9.1.1
# Linter
black