refactor: Deploy System

This commit is contained in:
2026-06-18 17:43:49 -05:00
parent 259af7dc81
commit ad8334d11c
23 changed files with 301 additions and 158 deletions

36
.env.development.example Normal file
View File

@@ -0,0 +1,36 @@
# version Trytond server example 6.0
TRYTOND_VERSION=7.6
TRYTON_ADMIN_PASS=admin
TRYTON_ADMIN_EMAIL=admin@gmail.co
TRYTONADMINPASS=admin
TRYTONPASSFILE=/etc/trytond_admin_pass.conf
SLEEP_TRYTOND_ADMIN=5
# TRYTOND operation mode
TRYTON_PORT_LIVE=18021
PUDB_PORT_LIVE=8085
PUDB_PORT=8095
DEVELOP=True
WORKER=True
# Facho
FACHO=True
FACHO_BRANCH=MigrationPython312Test
# If the module repository is private
GITEA_USER=USER
GITEA_PASSWORD=PASSWORD
GITEA_ACCESS_TOKEN=TOKEN
GITEA_DOMAIN=gitea.domain.org
# Database configuration
DB_HOSTNAME=db
DB_PASSWORD=SUp3r-pass*DB
POSTGRES_DB=tryton
POSTGRES_USER=postgres
POSTGRES_PASSWORD=SUp3r-pass*DB

51
.env.production.example Normal file
View File

@@ -0,0 +1,51 @@
# version Trytond server example 6.0
TRYTOND_VERSION=7.6
TRYTON_ADMIN_PASS=admin
TRYTON_ADMIN_EMAIL=admin@gmail.co
TRYTONADMINPASS=admin
TRYTONPASSFILE=/etc/trytond_admin_pass.conf
SLEEP_TRYTOND_ADMIN=5
# TRYTOND operation mode
TRYTON_PORT=8000
DEVELOP=False
WORKER=True
# Facho
FACHO=True
FACHO_BRANCH=MigrationPython312Test
# if the module repository is private
GITEA_USER=user
GITEA_PASSWORD=password
GITEA_ACCESS_TOKEN=TOKEN
GITEA_DOMAIN=gitea.domain.org
# Database configuration
DB_HOSTNAME=db
DB_PASSWORD=SUp3r-pass*DB
POSTGRES_DB=tryton
POSTGRES_USER=postgres
POSTGRES_PASSWORD=SUp3r-pass*DB
# SMTP This value is True or False
SMTP=False
SMTP_TYPE=smtps+ssl
SMTP_USER=email@example.com
SMTP_PASSWORD=PASSWORD
SMTP_DOMAIN=mail.example.org
SMTP_PORT=465
SMTP_FROM="NAME_FROM <email@example.com>"
SMTP_EMAIL=email@example.org
# NGINX
SERVER_NAME=localhost.example
NGINX_PORT=10000
VARIABLE=$

4
.gitignore vendored
View File

@@ -111,6 +111,8 @@ celerybeat.pid
# Environments # Environments
.env .env
.env.development
.env.production
.venv .venv
env/ env/
venv/ venv/
@@ -225,4 +227,4 @@ pyvenv.cfg
pip-selfcheck.json pip-selfcheck.json
.tdd_cache .tdd_cache
app app

View File

@@ -20,7 +20,6 @@ FROM tryton/tryton:$TRYTOND_VERSION
LABEL org.label-schema.version="$TRYTOND_VERSION" LABEL org.label-schema.version="$TRYTOND_VERSION"
ARG TRYTOND_VERSION ARG TRYTOND_VERSION
ARG DEVELOP
ARG WORKER ARG WORKER
USER root USER root
@@ -38,20 +37,19 @@ RUN echo "Install modules non official"
COPY trytond.conf /etc/trytond.conf COPY trytond.conf /etc/trytond.conf
COPY trytond_worker.conf /etc/trytond_worker.conf COPY trytond_worker.conf /etc/trytond_worker.conf
COPY gunicorn.conf.py /etc/gunicorn.conf.py COPY gunicorn.conf.py /etc/gunicorn.conf.py
COPY requirements.txt /opt
RUN pip install --break-system-packages -r /opt/requirements.txt
COPY start.sh /opt
COPY trytond_logging.conf /etc/trytond_logging.conf COPY trytond_logging.conf /etc/trytond_logging.conf
COPY trytond_cron_logging.conf /etc/trytond_cron_logging.conf COPY trytond_cron_logging.conf /etc/trytond_cron_logging.conf
COPY trytond_worker_logging.conf /etc/trytond_worker_logging.conf COPY trytond_worker_logging.conf /etc/trytond_worker_logging.conf
COPY common_password.txt /etc/common_password.txt COPY common_password.txt /etc/common_password.txt
COPY start.sh /opt
COPY requirements.txt /opt
RUN pip install --break-system-packages -r /opt/requirements.txt
COPY modules /app/modules COPY modules /app/modules
COPY install_modules.sh /app/install_modules.sh COPY ./prod/install_modules.sh /app/install_modules.sh
RUN chmod +x /app/install_modules.sh && /bin/bash /app/install_modules.sh RUN chmod +x /app/install_modules.sh && /bin/bash /app/install_modules.sh
RUN rm -rf /var/lib/trytond/www RUN rm -rf /var/lib/trytond/www

View File

@@ -1,7 +1,14 @@
require 'yaml' require 'yaml'
require 'digest' require 'digest'
DOCKER_COMPOSE='compose.test.yml' DOCKER_COMPOSE_TEST='docker-compose.test.yml'
ENV_FILE_DEV='.env.development'
DOCKER_COMOPSE_LIVE='docker-compose.live.yml'
ENV_FILE_LIVE='.env.development'
DOCKER_COMPOSE_DEPLOY='docker-compose.prod.yml'
ENV_FILE_DEPLOY='.env.production'
desc 'iniciar entorno' desc 'iniciar entorno'
task :up do task :up do
@@ -21,7 +28,6 @@ end
desc 'iterar' desc 'iterar'
task :tdd, [:name] do |_, args| task :tdd, [:name] do |_, args|
refresh_cache refresh_cache
test_dir = '' test_dir = ''
if args.name if args.name
@@ -32,7 +38,6 @@ task :tdd, [:name] do |_, args|
compose('exec', 'test.dev', "bash -c 'cd modules && flake8 *'") compose('exec', 'test.dev', "bash -c 'cd modules && flake8 *'")
compose('exec', 'test.dev', "bash -c 'python -m unittest discover -s modules'") compose('exec', 'test.dev', "bash -c 'python -m unittest discover -s modules'")
end end
end end
desc 'detener entorno' desc 'detener entorno'
@@ -45,32 +50,32 @@ namespace :live do
desc 'iniciar entorno' desc 'iniciar entorno'
task :up do task :up do
compose('up', '--build', '-d', compose: 'compose.live.yml') compose('up', '--build', '-d', env_file: ENV_FILE_LIVE, compose: DOCKER_COMPOSE_LIVE)
end end
desc 'monitorear salida' desc 'monitorear salida'
task :tail do task :tail do
compose('logs', '-f', 'live', '-n', '50', compose: 'compose.live.yml') compose('logs', '-f', 'live', '-n', '50', env_file: ENV_FILE_LIVE, compose: DOCKER_COMPOSE_LIVE)
end end
desc 'detener entorno' desc 'detener entorno'
task :down do task :down do
compose('down', compose: 'compose.live.yml') compose('down', env_file: ENV_FILE_LIVE, compose: DOCKER_COMPOSE_LIVE)
end end
desc 'eliminar entorno' desc 'eliminar entorno'
task :del do task :del do
compose('down', '-v', '--rmi', 'all', compose: 'compose.live.yml') compose('down', '-v', '--rmi', 'all', env_file: ENV_FILE_LIVE, compose: DOCKER_COMPOSE_LIVE)
end end
desc 'detener entorno' desc 'detener entorno'
task :stop do task :stop do
compose('stop', compose: 'compose.live.yml') compose('stop', env_file: ENV_FILE_LIVE, compose: DOCKER_COMPOSE_LIVE)
end end
desc 'reiniciar entorno' desc 'reiniciar entorno'
task :restart do task :restart do
compose('restart', compose: 'compose.live.yml') compose('restart', env_file: ENV_FILE_LIVE, compose: DOCKER_COMPOSE_LIVE)
end end
desc 'terminal' desc 'terminal'
@@ -80,25 +85,85 @@ namespace :live do
desc 'monitorear salida' desc 'monitorear salida'
task :tail_end do task :tail_end do
compose('logs', '-f', '-n 50', 'live', compose: 'compose.live.yml') compose('logs', '-f', '-n 50', 'live', env_file: ENV_FILE_LIVE, compose: DOCKER_COMPOSE_LIVE)
end end
desc 'populate data' desc 'populate data'
task :populate, [:database] do |_, args| task :populate, [:database] do |_, args|
if args.database if args.database
compose('stop', "live", compose: "compose.live.yml") compose('stop', "live", env_file: ENV_FILE_DEV, compose: DOCKER_COMPOSE_LIVE)
compose('exec', '-it', '--user', 'postgres', 'db', "bash -c 'dropdb -U tryton #{args.database}'") compose('exec', '-it', '--user', 'postgres', 'db', "bash -c 'dropdb -U tryton #{args.database}'")
compose('exec', '-it', '--user', 'postgres', 'db', "bash -c 'createdb -U tryton #{args.database}'") compose('exec', '-it', '--user', 'postgres', 'db', "bash -c 'createdb -U tryton #{args.database}'")
compose('restart', "live", compose: "compose.live.yml") compose('restart', "live", env_file: ENV_FILE_DEV, compose: DOCKER_COMPOSE_LIVE)
sleep(40) sleep(40)
compose('exec', 'live', "bash -c 'python3 demo/populate_scripts/__main__.py -c .dev/trytond.cfg -d #{args.database}'") compose('exec', 'live', "bash -c 'python3 demo/populate_scripts/__main__.py -c .dev/trytond.cfg -d #{args.database}'")
compose('restart', 'live', compose: "compose.live.yml") compose('restart', 'live', env_file: ENV_FILE_DEV, compose: DOCKER_COMPOSE_LIVE)
else else
puts "Falta el nombre de la base de datos" puts "Falta el nombre de la base de datos"
end end
end end
end end
desc 'produccion'
namespace :deploy do
desc 'iniciar entorno'
task :up do
compose('up', '--build', '-d', env_file: ENV_FILE_DEPLOY, compose: DOCKER_COMPOSE_DEPLOY)
end
desc 'monitorear salida'
task :tail do
compose('logs', env_file: ENV_FILE_DEPLOY, compose: DOCKER_COMPOSE_DEPLOY)
end
desc 'detener entorno'
task :down do
compose('down', env_file: ENV_FILE_DEPLOY, compose: DOCKER_COMPOSE_DEPLOY)
end
desc 'eliminar entorno'
task :del do
compose('down', '-v', '--rmi', 'all', env_file: ENV_FILE_DEPLOY ,compose: DOCKER_COMPOSE_DEPLOY)
end
desc 'reiniciar entorno'
task :restart do
compose('restart', env_file: ENV_FILE_DEPLOY, compose: DOCKER_COMPOSE_DEPLOY)
end
desc 'terminal-tryton'
task :sh_tryton do
compose('exec', '--user', 'root', 'tryton', '/entrypoint.sh', 'bash', compose: DOCKER_COMPOSE_DEPLOY)
end
desc 'terminal-worker'
task :sh_worker do
compose('exec', '--user', 'root', 'tryton_worker', '/entrypoint.sh', 'bash', compose: DOCKER_COMPOSE_DEPLOY)
end
desc 'terminal-cron'
task :sh_cron do
compose('exec', '--user', 'root', 'tryton_cron', '/entrypoint.sh', 'bash', compose: DOCKER_COMPOSE_DEPLOY)
end
desc 'terminal-db'
task :sh_db do
compose('exec', '--user', 'postgres', 'db', 'bash', compose: DOCKER_COMOPSE_DEPLOY)
end
desc 'terminal-nginx'
task :sh_nginx do
compose('exec', 'nginx', 'bash', compose: DOCKER_COMOPSE_DEPLOY)
end
desc 'top'
task :top do
compose('top', compose: DOCKER_COMOPSE_DEPLOY)
end
end
desc 'Git - Submodules' desc 'Git - Submodules'
namespace :git do namespace :git do
@@ -124,8 +189,8 @@ namespace :git do
end end
end end
def compose(*arg, compose: DOCKER_COMPOSE) def compose(*arg, env_file: ENV_FILE_DEV, compose: DOCKER_COMPOSE_TEST)
sh "docker compose -f #{compose} #{arg.join(' ')}" sh "docker compose --env-file #{env_file} -f #{compose} #{arg.join(' ')}"
end end
def refresh_cache def refresh_cache

View File

@@ -1,80 +0,0 @@
services:
db:
image: postgres
hostname:
${DB_HOSTNAME}
volumes:
- postgres:/var/lib/postgresql
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
tryton:
build:
context: ./
dockerfile: Dockerfile_Deploy
args:
TRYTOND_VERSION: ${TRYTOND_VERSION}
EMAIL: admin@admin.org
WORKER: True
image: tryton/${POSTGRES_DB}:${TRYTOND_VERSION}
healthcheck:
test: curl --fail localhost:8000 || exit 1
interval: 30s
retries: 5
start_period: 30s
timeout: 20s
ports:
- "${TRYTON_PORT:-8000}:8000"
volumes:
- .:/app
- var:/var
- attachment:/mnt/attachment
environment:
- TRYTOND_DATABASE_URI=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOSTNAME}:5432/
depends_on:
- db
env_file:
- .env
working_dir: /app
nginx:
image: nginx:1.23.3
restart: unless-stopped
volumes:
- ./nginx.conf:/etc/nginx/conf.d/nginx.conf.template
ports:
- "${NGINX_PORT:-10000}:${NGINX_PORT:-10000}"
env_file:
- .env
depends_on:
- tryton
command: /bin/bash -c "envsubst < /etc/nginx/conf.d/nginx.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
tryton_worker:
image: tryton/${POSTGRES_DB}:${TRYTOND_VERSION}
depends_on:
tryton:
condition: service_healthy
entrypoint: [ "bash", "-c", "/entrypoint.sh trytond-worker -c /etc/trytond_worker.conf -d ${POSTGRES_DB} --logconf /etc/trytond_worker_logging.conf"]
volumes:
- .:/app
environment:
- TRYTOND_DATABASE_URI=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOSTNAME}:5432/
env_file:
- .env
working_dir: /app
tryton_cron:
image: tryton/${POSTGRES_DB}:${TRYTOND_VERSION}
depends_on:
tryton:
condition: service_healthy
entrypoint: [ "bash", "-c", "/entrypoint.sh trytond-cron -c /etc/trytond.conf -d ${POSTGRES_DB} --logconf /etc/trytond_cron_logging.conf"]
volumes:
- .:/app
environment:
- TRYTOND_DATABASE_URI=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOSTNAME}:5432/
env_file:
- .env
working_dir: /app
volumes:
var:
postgres:
attachment:

View File

@@ -8,7 +8,7 @@ services:
live: live:
build: build:
context: . context: .
dockerfile: Dockerfile_Live dockerfile: Dockerfile_live
args: args:
TRYTOND_VERSION: ${TRYTOND_VERSION} TRYTOND_VERSION: ${TRYTOND_VERSION}
TRYTON_ADMIN_PASSWORD: ${TRYTON_ADMIN_PASSWORD:-admin} TRYTON_ADMIN_PASSWORD: ${TRYTON_ADMIN_PASSWORD:-admin}
@@ -28,7 +28,7 @@ services:
- "${PUDB_PORT_LIVE:-8020}:8020" - "${PUDB_PORT_LIVE:-8020}:8020"
working_dir: /app working_dir: /app
env_file: env_file:
- .env - .env.development
volumes: volumes:
app: app:
attachments: attachments:

102
docker-compose.prod.yaml Normal file
View File

@@ -0,0 +1,102 @@
services:
db:
image: postgres
hostname: ${DB_HOSTNAME}
volumes:
- postgres:/var/lib/postgresql
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
tryton:
build:
context: ./
dockerfile: Dockerfile_prod
args:
TRYTOND_VERSION: ${TRYTOND_VERSION}
GITEA_USER: ${GITEA_USER}
GITEA_PASSWORD: ${GITEA_PASSWORD}
GITEA_DOMAIN: ${GITEA_DOMAIN}
WORKER: ${WORKER}
TRYTONPASSFILE: ${TRYTONPASSFILE}
TRYTON_ADMIN_EMAIL: ${TRYTON_ADMIN_EMAIL}
SMTP: ${SMTP}
SMTP_TYPE: ${SMTP_TYPE}
SMTP_USER: ${SMTP_USER}
SMTP_PASSWORD: ${SMTP_PASSWORD}
SMTP_DOMAIN: ${SMTP_DOMAIN}
SMTP_PORT: ${SMTP_PORT}
SMTP_FROM: ${SMTP_FROM}
SMTP_EMAIL: ${SMTP_EMAIL}
image: tryton/${POSTGRES_DB}:${TRYTOND_VERSION}
healthcheck:
test: curl --fail localhost:8000 || exit 1
interval: 30s
retries: 5
start_period: 30s
timeout: 20s
ports:
- "${TRYTON_PORT:-8000}:8000"
volumes:
- .:/app
- var:/var
- attachment:/mnt/attachment
environment:
- TRYTOND_DATABASE_URI=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOSTNAME}:5432/
depends_on:
- db
env_file:
- .env.production
working_dir: /app
nginx:
image: nginx:1.23.3
restart: unless-stopped
volumes:
- ./prod/nginx.conf:/etc/nginx/conf.d/nginx.conf.template
ports:
- "${NGINX_PORT:-10000}:${NGINX_PORT:-10000}"
env_file:
- .env.production
depends_on:
- tryton
command: /bin/bash -c "envsubst < /etc/nginx/conf.d/nginx.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
tryton_worker:
image: tryton/${POSTGRES_DB}:${TRYTOND_VERSION}
depends_on:
tryton:
condition: service_healthy
entrypoint:
[
"bash",
"-c",
"/entrypoint.sh trytond-worker -c /etc/trytond_worker.conf -d ${POSTGRES_DB} --logconf /etc/trytond_worker_logging.conf",
]
volumes:
- .:/app
environment:
- TRYTOND_DATABASE_URI=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOSTNAME}:5432/
env_file:
- .env.production
working_dir: /app
tryton_cron:
image: tryton/${POSTGRES_DB}:${TRYTOND_VERSION}
depends_on:
tryton:
condition: service_healthy
entrypoint:
[
"bash",
"-c",
"/entrypoint.sh trytond-cron -c /etc/trytond.conf -d ${POSTGRES_DB} --logconf /etc/trytond_cron_logging.conf",
]
volumes:
- .:/app
environment:
- TRYTOND_DATABASE_URI=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOSTNAME}:5432/
env_file:
- .env.production
working_dir: /app
volumes:
app:
var:
postgres:
attachment:

View File

@@ -1,33 +0,0 @@
services:
db:
image: postgres:12
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
live:
build:
context: .
dockerfile: Dockerfile_Live
args:
TRYTOND_VERSION: ${TRYTOND_VERSION}
depends_on:
- db
command: bash /app/.dev/run.sh
environment:
- DB_NAME=${POSTGRES_DB}
- SRC=/app
- TRYTOND_DATABASE_URI=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOSTNAME}:5432/
volumes:
- ./:/app
- ./attachments:/attachments
- ./.dev/pudb.cfg:/root/.config/pudb/pudb.cfg
ports:
- "${TRYTOND_PORT_LIVE:-18020}:8000"
- "${PUDB_PORT_LIVE:-8020}:8020"
working_dir: /app
env_file:
- .env
volumes:
app:
attachments:

View File

@@ -1,19 +0,0 @@
server {
server_name ${SERVER_NAME};
listen ${NGINX_PORT};
client_max_body_size 8M;
sendfile on;
send_timeout 500s;
location / {
proxy_pass http://tryton:8000/; # "trytond" is the service name of another Docker container on port 8000
proxy_read_timeout 500;
proxy_connect_timeout 500;
proxy_send_timeout 500;
proxy_set_header Host ${VARIABLE}host;
proxy_set_header X-Real-IP ${VARIABLE}remote_addr;
proxy_set_header X-Forwarded-For ${VARIABLE}proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host ${VARIABLE}server_name;
}
}

21
prod/nginx.conf Normal file
View File

@@ -0,0 +1,21 @@
server {
server_name ${SERVER_NAME};
listen ${NGINX_PORT};
client_max_body_size 50M;
sendfile on;
send_timeout 500s;
location / {
proxy_pass http://tryton:8000/; # "trytond" is the service name of another Docker container on port 8000
proxy_read_timeout 500;
proxy_connect_timeout 500;
proxy_send_timeout 500;
proxy_set_header Host ${VARIABLE}host;
proxy_set_header X-Real-IP ${VARIABLE}remote_addr;
proxy_set_header X-Forwarded-For ${VARIABLE}proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host ${VARIABLE}server_name;
proxy_set_header X-Forwarded-Proto ${VARIABLE}scheme;
}
}