feat: use alpine base image for docker
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
.github/
|
||||||
|
.pytest_cache/
|
||||||
|
coverage.xml
|
||||||
+12
-8
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.11-slim-buster
|
FROM python:3.11-alpine
|
||||||
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
ENV PYTHONDONTWRITEBYTECODE 1
|
||||||
ENV PYTHONUNBUFFERED 1
|
ENV PYTHONUNBUFFERED 1
|
||||||
@@ -6,15 +6,19 @@ ENV PYTHONUNBUFFERED 1
|
|||||||
RUN mkdir /code
|
RUN mkdir /code
|
||||||
|
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
COPY . /code
|
COPY requirements.txt /code
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apk update && \
|
||||||
apt-get install -y gcc vim postgresql-client nginx && \
|
apk add gcc vim postgresql-client openrc nginx && \
|
||||||
apt-get remove --purge --auto-remove -y
|
apk del gcc && \
|
||||||
|
openrc && \
|
||||||
|
touch /run/openrc/softlevel && \
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
COPY . /code
|
||||||
|
|
||||||
COPY nginx/nginx.conf /etc/nginx/sites-enabled/default
|
COPY nginx/nginx.conf /etc/nginx/sites-enabled/default
|
||||||
|
|
||||||
RUN pip install -r requirements.txt && \
|
RUN python manage.py collectstatic --noinput
|
||||||
python manage.py collectstatic --noinput
|
|
||||||
|
|
||||||
CMD [ "bash", "./scripts/run.sh" ]
|
CMD [ "sh", "./scripts/run.sh" ]
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ celery -A config worker -B -l debug
|
|||||||
pytest --cov
|
pytest --cov
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Variables de entorno
|
## Variables de entorno
|
||||||
|
|
||||||
Puedes crear un archivo `.env` con las siguientes variables de entorno.
|
Puedes crear un archivo `.env` con las siguientes variables de entorno.
|
||||||
@@ -67,3 +65,24 @@ Puedes crear un archivo `.env` con las siguientes variables de entorno.
|
|||||||
| REDSYS_CURRENCY_CODE | 978 | Código de moneda de Redsys |
|
| REDSYS_CURRENCY_CODE | 978 | Código de moneda de Redsys |
|
||||||
| REDSYS_TPV_DOMAIN | | Dominio del TPV para redirección 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
|
||||||
|
```
|
||||||
|
|||||||
+1
-1
@@ -2,6 +2,6 @@ import os
|
|||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
||||||
|
|
||||||
application = get_asgi_application()
|
application = get_asgi_application()
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ import os
|
|||||||
from celery import Celery
|
from celery import Celery
|
||||||
|
|
||||||
# set the default Django settings module for the 'celery' program.
|
# set the default Django settings module for the 'celery' program.
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.base")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
||||||
|
|
||||||
app = Celery("config")
|
app = Celery("config")
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,6 +2,6 @@ import os
|
|||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
ASGI_HOST=${WSGI_HOST:="0.0.0.0"}
|
ASGI_HOST=${WSGI_HOST:="0.0.0.0"}
|
||||||
ASGI_PORT=8000
|
ASGI_PORT=8000
|
||||||
@@ -10,7 +10,7 @@ RUN_CELERY=${RUN_CELERY:="FALSE"}
|
|||||||
|
|
||||||
|
|
||||||
if [ $RUN_SERVER = "TRUE" ]; then
|
if [ $RUN_SERVER = "TRUE" ]; then
|
||||||
service nginx restart
|
rc-service nginx start
|
||||||
uvicorn --workers $ASGI_WORKERS --host $ASGI_HOST --port $ASGI_PORT config.asgi:application
|
uvicorn --workers $ASGI_WORKERS --host $ASGI_HOST --port $ASGI_PORT config.asgi:application
|
||||||
elif [ $RUN_CELERY = "TRUE" ]; then
|
elif [ $RUN_CELERY = "TRUE" ]; then
|
||||||
service nginx stop
|
service nginx stop
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ router = DefaultRouter()
|
|||||||
|
|
||||||
router.register("taxes", TaxViewSet)
|
router.register("taxes", TaxViewSet)
|
||||||
router.register("customers", CustomerViewSet)
|
router.register("customers", CustomerViewSet)
|
||||||
router.register("product", ProductViewSet)
|
router.register("products", ProductViewSet)
|
||||||
router.register("product-prices", ProductPriceViewSet)
|
router.register("product-prices", ProductPriceViewSet)
|
||||||
router.register("orders", OrderViewSet)
|
router.register("orders", OrderViewSet)
|
||||||
router.register("orders/(?P<order_id>[^/.]+)/lines", OrderLineViewSet)
|
router.register("orders/(?P<order_id>[^/.]+)/lines", OrderLineViewSet)
|
||||||
|
|||||||
Reference in New Issue
Block a user