Tryton flask on docker image?

Hey
did someone able to setup tryton flask on docker image ?
seem’s i cant find trytond.conf in docker container

You must set in the flask configuration TRYTON_CONFIG=/etc/trytond.conf.

i tried putting that location

from flask import Flask
from flask_tryton import Tryton
app = Flask(__name__)
app.config['TRYTON_CONFIG'] = '/etc/trytond.conf'
app.config['TRYTON_DATABASE'] = 'coop'
tryton = Tryton(app, configure_jinja=True)

app.run()

but i am getting the following error

root@c3578928d70c:/etc/api# python3 app.py 
Traceback (most recent call last):
  File "app.py", line 8, in <module>
    tryton = Tryton(app, configure_jinja=True)
  File "/usr/local/lib/python3.7/dist-packages/flask_tryton.py", line 52, in __init__
    self.init_app(app)
  File "/usr/local/lib/python3.7/dist-packages/flask_tryton.py", line 67, in init_app
    with Transaction().start(database, user, readonly=True):
  File "/usr/local/lib/python3.7/dist-packages/trytond/transaction.py", line 107, in start
    database = backend.Database(database_name).connect()
  File "/usr/local/lib/python3.7/dist-packages/trytond/backend/sqlite/database.py", line 344, in connect
    raise IOError('Database "%s" doesn\'t exist!' % path)
OSError: Database "/root/db/coop.sqlite" doesn't exist!

do i need to set some specific things in trytond.conf ?

You must launch with the entrypoint.sh to get TRYTOND_DATABASE_URI set.

docker run --name coops -p 8001:8000 --link coop-postgres:postgres -v coop-data:/usr/local/lib/python3.7/dist-packages -v etc-data:/etc -e DB_PASSWORD=mysecretpassword -e TRYTOND_DATABASE_URI=sa -d coop-society

you mean like this ? any example will be much appreciated

This run the trytond wsgi application not your flask application.

thanks i was able to sort that out but i was facing some other issue now

 root@9abeb8da7afb:/etc/api# python3 app.py 
    Traceback (most recent call last):
      File "app.py", line 6, in <module>
        tryton = Tryton(app, configure_jinja=True)
      File "/usr/local/lib/python3.7/dist-packages/flask_tryton.py", line 52, in __init__
        self.init_app(app)
      File "/usr/local/lib/python3.7/dist-packages/flask_tryton.py", line 67, in init_app
        with Transaction().start(database, user, readonly=True):
      File "/usr/local/lib/python3.7/dist-packages/trytond/transaction.py", line 95, in start
        from trytond import backend
      File "/usr/local/lib/python3.7/dist-packages/trytond/backend/__init__.py", line 21, in <module>
        _module = importlib.import_module(_modname)
      File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    ModuleNotFoundError: No module named 'trytond.backend.

Clearly the TRYTOND_DATABASE_URI is not set. So probably because the entrypoint.sh has not been used.

docker run --link coop-postgres:postgres --name console -v coop-data:/usr/local/lib/python3.7/dist-packages -v etc-data:/etc --rm -ti coop-society python3 /etc/api/app.py

Thanks a lot @ced this solves the issue in my case

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.