diff --git a/.dockerignore b/.dockerignore index 1e0cde6..71aeb55 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,6 @@ .github/ .pytest_cache/ +data/ coverage.xml +docker-compose.dev.yml +docker-compose.yml diff --git a/README.md b/README.md index 5222c47..7ec5701 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,34 @@ celery -A config worker -B -l debug pytest --cov ``` +## Docker + +### Descarga + +```bash +docker pull ghcr.io/pablo-moreno/shoppy +``` + +### Construir imagen + +```bash +docker build -t shoppy . +``` + +### Crear contenedor + +**API** + +```bash +docker run -it --rm -p 8000:80 -e RUN_SERVER=TRUE --env-file=.env shoppy_api +``` + +**Tareas en segundo plano** + +```bash +docker run -it --rm -p 8000:80 -e RUN_CELERY=TRUE --env-file=.env shoppy_tasks +``` + ## Variables de entorno Puedes crear un archivo `.env` con las siguientes variables de entorno. @@ -66,25 +94,3 @@ Puedes crear un archivo `.env` con las siguientes variables de entorno. | REDSYS_TERMINAL | 001 | Terminal de Redsys | | REDSYS_CURRENCY_CODE | 978 | Código de moneda de Redsys | | REDSYS_TPV_DOMAIN | | Dominio del TPV para redirección de Redsys | - -## Docker - -### Construir imagen - -```bash -docker build -t shoppy . -``` - -### Crear contenedor - -**API** - -```bash -docker run -it --rm -p 8000:80 -e RUN_SERVER=TRUE --env-file=.env shoppy_api -``` - -**Tareas en segundo plano** - -```bash -docker run -it --rm -p 8000:80 -e RUN_CELERY=TRUE --env-file=.env shoppy_tasks -``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4880113 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,68 @@ +version: "3" +services: + postgres: + image: postgres:14.1 + environment: + POSTGRES_USER: admin + POSTGRES_PASSWORD: development + POSTGRES_DB: default + volumes: + - "./data/postgres:/var/lib/postgres/data" + + minio: + image: bitnami/minio:latest + ports: + - "9190:9000" + - "9191:9001" + volumes: + - "./data/minio/:/bitnami/minio/data" + + redis: + image: redis + + shoppy: + image: shoppy + ports: + - "8000:8000" + environment: + DEBUG: "True" + DATABASE_URL: "postgres://admin:development@postgres:5432/default" + S3_HOST: "http://172.17.0.1:9190" + S3_LOCATION: "backend" + S3_STORAGE_BUCKET_NAME: "shoppy" + S3_ENDPOINT_URL: "http://172.17.0.1:9190" + S3_ENABLED: "True" + S3_ACCESS_KEY_ID: "shoppy-access-key" + S3_SECRET_ACCESS_KEY: "shoppy-secret-key" + RUN_SERVER: "TRUE" + CELERY_BROKER_URL: "redis://redis:6379/0" + links: + - postgres + - minio + - redis + depends_on: + - postgres + - minio + - redis + + shoppy_tasks: + image: shoppy + environment: + DATABASE_URL: "postgres://admin:development@postgres:5432/default" + S3_HOST: "http://172.17.0.1:9190" + S3_LOCATION: "backend" + S3_STORAGE_BUCKET_NAME: "shoppy" + S3_ENDPOINT_URL: "http://172.17.0.1:9190" + S3_ENABLED: "True" + S3_ACCESS_KEY_ID: "shoppy-access-key" + S3_SECRET_ACCESS_KEY: "shoppy-secret-key" + RUN_CELERY: "TRUE" + CELERY_BROKER_URL: "redis://redis:6379/0" + links: + - postgres + - minio + - redis + depends_on: + - postgres + - minio + - redis diff --git a/files/admin.py b/files/admin.py index 8c38f3f..45f4570 100644 --- a/files/admin.py +++ b/files/admin.py @@ -1,3 +1,12 @@ from django.contrib import admin +from files.models import FileUpload + + # Register your models here. +@admin.register(FileUpload) +class FileUploadAdmin(admin.ModelAdmin): + list_display = ( + 'id', + 'file', + ) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 0e840a1..7564f5a 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,4 +1,7 @@ server { + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log notice; + listen 80; # Static files @@ -9,6 +12,15 @@ server { # Reverse proxy location / { proxy_pass http://127.0.0.1:8000; + proxy_cache_bypass $http_upgrade; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; } # security headers @@ -24,15 +36,4 @@ server { gzip_proxied any; gzip_comp_level 6; gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml; - - # Proxy - proxy_cache_bypass $http_upgrade; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header X-Forwarded-Host $host; - proxy_set_header X-Forwarded-Port $server_port; } diff --git a/requirements.txt b/requirements.txt index aba2429..edb9562 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +boto3==1.34.105 celery==5.4.0 django==5.0.6 django-cors-headers==3.13.0 diff --git a/scripts/run.sh b/scripts/run.sh index 829b0ca..51e5ee6 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -10,6 +10,8 @@ RUN_CELERY=${RUN_CELERY:="FALSE"} if [ $RUN_SERVER = "TRUE" ]; then + chown -R www-data:www-data static/ + python manage.py collectstatic --no-input service nginx start uvicorn --workers $ASGI_WORKERS --host $ASGI_HOST --port $ASGI_PORT config.asgi:application elif [ $RUN_CELERY = "TRUE" ]; then