Go to file
Francisco Sandoval 10f9e59ae5 fix getInfoDevice 2023-12-15 15:45:31 -03:00
docs getInfoDevice lee informacion desde redis 2023-12-14 16:14:07 -03:00
project fix getInfoDevice 2023-12-15 15:45:31 -03:00
.gitignore commit inicial 2023-12-05 10:34:47 -03:00
readme.md update readme.md 2023-12-05 17:07:21 -03:00
requirements.txt lee los trayecto de redis 2023-12-12 22:49:05 -03:00

readme.md

Dependencias

  • Django: framework django
  • psycopg2-binary: permite uso de base datos postgres
  • djangorestframework: permite crear rest api json
  • django-cors-headers: requerido para desarrollo de frontend, permite acceso desde una dominio distinto al backend
  • django-filter: permite filtrar resultado usando paraquetros en querystring
  • coreapi: genera documentación de rest api
  • python-decouple: lee archivo .env para variables de ambiente
  • PyJWT: permite generar json-web-token
  • pymongo: permite conectarse a base datos mongo
  • Pillow: permite imagenar imagenes
  • openpyxl: permite generar archivos excel

Docker

Para iniciar la aplicacion usando docker

cd <carpeta del proyecto>/docker
docker compose up -d

Script para levantar aplicacion python

start.sh

#!/bin/sh
cd /app

# si no existe directorio de ambiente, se crea
if [ ! -d /app/libs ]; then
  python -m venv libs
  . ./libs/bin/activate
  pip install -r requirements.txt
fi

# activar ambiente con dependencias
. ./libs/bin/activate

# si no existe un proyecto inicial, lo crea
if [ ! -d /app/project ]; then
  django-admin startproject project
fi

# iniciar servidor con puerto 8000
python /app/project/manage.py runserver 0.0.0.0:8000

Extraer models de base de datos

python manage.py inspectdb > api/models.py

file: docker-compose.yml

version: '3'
name: transporte

services:

  frontend:
    image: node:18-alpine
    volumes:
      - ./frontend:/app
    ports:
      - 3000:3000
    environment:
      - VITE_PORT=3000
      - VITE_BACKEND=/api
    working_dir: /app
    command: sh -c "
      [ ! -d node_modules ] && npm install ;
      chmod -R o+w . ;
      npm run dev
      "

  backend:
      image: python:3.11-alpine
      environment:
        - PORT=4000
        - DBHOST=db
        - DBPORT=5432
        - DBNAME=database
        - DBSCHEMA=desarrollo1
        - DBUSER=postgres
        - DBPASS=password
        - SECRET_JWT="kf6Jc!f30Z!1k1N0#!%#"
      volumes:
        - ./backend:/app
        - venv:/root/venv
      ports:
        - 4000:4000
      working_dir: /app
      command: sh -c "
        [ -d /root/venv/bin ] || ( \
            python -m venv /root/venv/ \
            && . /root/venv/bin/activate \
            && pip install -r requirements.txt \
        ) ;

        . /root/venv/bin/activate ;

        cd /app ;
        [ -d project ] || django-admin startproject project ;
        [ -f .env ] || ( [ -f .env.develop ] && cp .env.develop .env ) ;
        chmod -R o+w project/ ;
        python project/manage.py runserver 0.0.0.0:$$PORT
        "

  db:
    #image: postgis/postgis:14-3.4-alpine
    image: postgres:14-alpine-geometry
    volumes:
      - db:/var/lib/postgresql/data
      - ./backups:/backups
      #- ./backend/docs/database/01_create_tables.sql:/docker-entrypoint-initdb.d/01_create_tables.sql
    ports:
      - 5436:5432
    environment:
      POSTGRES_PASSWORD: password
      POSTGRES_DB: database
      PGDATA: /var/lib/postgresql/data/pgdata

  adminer:
    image: adminer
    environment:
      ADMINER_DEFAULT_SERVER: db
      ADMINER_DEFAULT_USER: postgres
      ADMINER_DEFAULT_PASSWORD: password
      ADMINER_DESIGN: lucas-sandery

volumes:
  db:
  venv: