chore: se adiciona entorno vivo de desarrollo
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				ci/woodpecker/push/woodpecker Pipeline was successful
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	ci/woodpecker/push/woodpecker Pipeline was successful
				
			This commit is contained in:
		
							
								
								
									
										2
									
								
								.dev/Procfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.dev/Procfile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
trytond: trytond -d ${DB_NAME} --dev -v -c $SCRIPT_DIR/trytond.cfg
 | 
			
		||||
monitor: python3 $SCRIPT_DIR/dev.py
 | 
			
		||||
							
								
								
									
										29
									
								
								.dev/dev.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								.dev/dev.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
# script para refrescar cambios de xml del modulo de tryton
 | 
			
		||||
import os
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
import inotify.adapters
 | 
			
		||||
 | 
			
		||||
SRC = os.environ['SRC']
 | 
			
		||||
MODULE_NAME = os.environ['MODULE_NAME']
 | 
			
		||||
DB_NAME = os.environ['DB_NAME']
 | 
			
		||||
 | 
			
		||||
def _main():
 | 
			
		||||
    i = inotify.adapters.Inotify()
 | 
			
		||||
 | 
			
		||||
    i.add_watch(SRC)
 | 
			
		||||
    logging.info("MONITOREANDO ARCHIVOS EN %s", SRC)
 | 
			
		||||
 | 
			
		||||
    for event in i.event_gen(yield_nones=False):
 | 
			
		||||
        (_, type_names, path, filename) = event
 | 
			
		||||
        (_, ext) = os.path.splitext(filename)
 | 
			
		||||
 | 
			
		||||
        if ext in ['.py', '.xml']:
 | 
			
		||||
            if os.system("trytond-admin -d {} -u {}".format(DB_NAME, MODULE_NAME)) != 0:
 | 
			
		||||
                raise Exception("fallo trytond-admin")
 | 
			
		||||
 | 
			
		||||
            logging.info("ACTUALIZADO TRYTOND POR CAMBIO DE ARCHIVO %s", filename)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    _main()
 | 
			
		||||
							
								
								
									
										43
									
								
								.dev/run.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										43
									
								
								.dev/run.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
# script para iniciar entorno vivo
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
SCRIPT_DIR=$(dirname `realpath $0`)
 | 
			
		||||
 | 
			
		||||
die() {
 | 
			
		||||
    echo $1
 | 
			
		||||
    exit 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[ ! -d "$SRC" ] && die "no se ubica ruta en SRC"
 | 
			
		||||
[ -z "$DB_NAME" ] && die "se requiere variable DB_NAME"
 | 
			
		||||
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
# dependencias minimas
 | 
			
		||||
pip3 install psycopg2 proteus inotify honcho
 | 
			
		||||
 | 
			
		||||
# instalar dependencias de tryton desde paquete
 | 
			
		||||
python3 setup.py install
 | 
			
		||||
 | 
			
		||||
# usamos enlace al paquete
 | 
			
		||||
python3 setup.py develop
 | 
			
		||||
 | 
			
		||||
# instalar modulo
 | 
			
		||||
trytond_modules_path=`pip3 show trytond | grep Location | sed -nr 's/Location: +//gp'`/trytond/modules
 | 
			
		||||
module_name=`cat "$SRC/setup.py"  | fgrep -A 1 [trytond.modules] | sed 1d | cut -d '=' -f 1 | tr -d ' \n'`
 | 
			
		||||
[ ! -d "$trytond_modules_path" ] && die "fallo al ubicar ruta de modulos de trytond"
 | 
			
		||||
ln -sf "$SRC" "$trytond_modules_path/$module_name"
 | 
			
		||||
 | 
			
		||||
# inicializar base de datos
 | 
			
		||||
# https://docs.tryton.org/projects/server/en/latest/tutorial/module/setup_database.html
 | 
			
		||||
yes admin | trytond-admin -d ${DB_NAME} --all 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# ejecutar servidor
 | 
			
		||||
export SCRIPT_DIR
 | 
			
		||||
export MODULE_NAME=$module_name
 | 
			
		||||
export DB_NAME
 | 
			
		||||
export SRC
 | 
			
		||||
 | 
			
		||||
honcho -d ${SCRIPT_DIR} start
 | 
			
		||||
							
								
								
									
										2
									
								
								.dev/trytond.cfg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.dev/trytond.cfg
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
[web]
 | 
			
		||||
listen = 0.0.0.0:8000
 | 
			
		||||
@@ -13,12 +13,19 @@
 | 
			
		||||
* git >= 2.30
 | 
			
		||||
* rake >= 13
 | 
			
		||||
 | 
			
		||||
### procedimiento
 | 
			
		||||
### procedimiento en pruebas
 | 
			
		||||
 | 
			
		||||
1. iniciar entorno `rake init`
 | 
			
		||||
2. iterar con `rake tdd`
 | 
			
		||||
3. detener el entorno `rake down`
 | 
			
		||||
 | 
			
		||||
### entorno vivo de desarrollo
 | 
			
		||||
 | 
			
		||||
1. iniciar entorno `rake live:up`
 | 
			
		||||
2. conectar cliente tryton a `localhost:8000` usuario: `admin` y clave: `admin`
 | 
			
		||||
  1. si desea ver la salida de trytond usar `rake live:tail`
 | 
			
		||||
3. detener entorno `rake live:down`
 | 
			
		||||
 | 
			
		||||
### consideraciones
 | 
			
		||||
 | 
			
		||||
* evito trabajo innecesario
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								Rakefile
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								Rakefile
									
									
									
									
									
								
							@@ -26,6 +26,25 @@ task :down do
 | 
			
		||||
  compose('down')
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def compose(*arg)
 | 
			
		||||
  sh "docker-compose -f #{DOCKER_COMPOSE} #{arg.join(' ')}"
 | 
			
		||||
desc 'entorno vivo'
 | 
			
		||||
namespace :live do
 | 
			
		||||
 | 
			
		||||
  desc 'iniciar entorno'
 | 
			
		||||
  task :up do
 | 
			
		||||
    compose('up', '--build', '-d', compose: 'docker-compose.yml')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  desc 'monitorear salida'
 | 
			
		||||
  task :tail do
 | 
			
		||||
    compose('logs', '-f', 'app.dev', compose: 'docker-compose.yml')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  desc 'detener entorno'
 | 
			
		||||
  task :down do
 | 
			
		||||
    compose('down', compose: 'docker-compose.yml')
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def compose(*arg, compose: DOCKER_COMPOSE)
 | 
			
		||||
  sh "docker-compose -f #{compose} #{arg.join(' ')}"
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
version: '3.9'
 | 
			
		||||
services:
 | 
			
		||||
  db.dev:
 | 
			
		||||
    image: postgres:12
 | 
			
		||||
    environment:
 | 
			
		||||
      - POSTGRES_USER=tryton
 | 
			
		||||
      - POSTGRES_PASSWORD=tryton
 | 
			
		||||
      - POSTGRES_DB=tryton
 | 
			
		||||
 | 
			
		||||
  app.dev:
 | 
			
		||||
    image: python:3.9
 | 
			
		||||
    depends_on:
 | 
			
		||||
      - db.dev
 | 
			
		||||
    command: bash .dev/run.sh
 | 
			
		||||
    environment:
 | 
			
		||||
      - DB_NAME=tryton
 | 
			
		||||
      - SRC=/app
 | 
			
		||||
      - TRYTOND_DATABASE_URI=postgresql://tryton:tryton@db.dev:5432/
 | 
			
		||||
    volumes:
 | 
			
		||||
      - .:/app
 | 
			
		||||
    ports:
 | 
			
		||||
      - "8000:8000"
 | 
			
		||||
    working_dir: /app
 | 
			
		||||
		Reference in New Issue
	
	Block a user