Deploying booktype as docker container
  • Hi,

    I try to deploy booktype as docker container. But I'm not so fit with django technology. So I need some support. can somé specialists have a look on my code?

    You can find the source under: https://github.com/OlafRadicke/booktype_with_docker
    And the docker image under: https://hub.docker.com/r/olafradicke/booktype/

    Currently I have the following problem:

    "settings.DATABASES is improperly configured. "
    ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the NAME value.

    I've no picture, how django read the config. :-S

    Best regards

    Olaf
  • 11 Comments sorted by
  • Vote Up0Vote Down Daniel JamesDaniel James
    Posts: 844Member, Sourcefabric Team
    Hi Olaf,

    Nice work! The first observation I would make is that you don't need to install sqlite3 in https://github.com/OlafRadicke/booktype_with_docker/blob/master/docker/Dockerfile if you are initialising a Booktype instance with postgres.

    The second observation is that your file https://github.com/OlafRadicke/booktype_with_docker/blob/master/docker/settings.py looks like it is not up to date for Booktype 2.0. Take a look at https://github.com/sourcefabric/Booktype/blob/2.0/lib/booktype/skeleton/base_settings.py.original for the current state of the base settings.

    Please let us know if you need more help.

    Cheers!

    Daniel
     
  • Hi Daniel,

    > Daniel James <booktype-dev@lists.sourcefabric.org> hat am 5. Januar 2016 um 13:08 geschrieben:
    > Hi Olaf,Nice work! The first observation I would make is that you don't need to install sqlite3 in
    > https://github.com/OlafRadicke/booktype_with_docker/blob/master/docker/Dockerfile
    > if you are initialising a Booktype instance with postgres.

    Yes, I started with SQLite configuration, but I can't find the support for this case in the
    the documentation:
    http://sourcefabric.booktype.pro/booktype-20-for-authors-and-publishers/installation-on-gnulinux/
    So later I switched to PostgreSQL setup. But I removed the item now from the install list

    > The second observation is that your file
    > https://github.com/OlafRadicke/booktype_with_docker/blob/master/docker/settings.py
    > looks like it is not up to date for Booktype 2.0. Take a look at
    > https://github.com/sourcefabric/Booktype/blob/2.0/lib/booktype/skeleton/base_settings.py.original
    > for the current state of the base settings.

    The settings.py is old stuff from a first try based on this project:
    https://github.com/nickstenning/dockerfiles/tree/master/booktype
    I
    replaced with a customized base.py file.

    It's right that the persistent data stored in /<instance name>/data/ ?

    Thank you,

    Olaf
  • Vote Up0Vote Down Daniel JamesDaniel James
    Posts: 844Member, Sourcefabric Team
    That's right, we don't document the sqlite installation as it is not useful for production installs. There are enough installation options already!

    The data directory for each instance is created by default under the instance path, for example /var/www/booktype/instance1/data/ and would be accessed internally at the URL http://booktype.example.com/data/ (this URL is hidden from browsing by users).

    This behaviour is controlled by the settings:

    DATA_ROOT = BOOKTYPE_ROOT.child('data')
    DATA_URL  = '{}/data/'.format(BOOKTYPE_URL)
  • All after my changes I get the same problem. For reproduce do this:All after my changes I get the same problem. For reproduction do this:


    # clone my repo
    Git clone https://github.com/OlafRadicke/booktype_with_docker.git
    # let run my roll out script (it's create the docker container on your local machine)
    cd ./booktype_with_docker/ansible
    su -c 'ansible-playbook booktype_with_docker'
    # check is all container running now:
    [root@oradicke-localdomain ~]# docker ps
    CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                               NAMES
    89ddb07ce27d        olafradicke/booktype   "/bin/bash start.sh"     About an hour ago   Up About an hour    8000/tcp, 0.0.0.0:49108->8080/tcp   booktype
    301e57e02bf4        redis                  "/entrypoint.sh redis"   2 hours ago         Up 2 hours          6379/tcp                            booktyperedis
    f60f86fb056c        postgres               "/docker-entrypoint.s"   2 hours ago         Up 2 hours          5432/tcp                            booktypepostgres
    # Go in the container for manual start
    [root@oradicke-localdomain ~]# docker exec -it booktype /bin/bash
    root@89ddb07ce27d:/# /bin/bash start.sh
  • Vote Up0Vote Down Daniel JamesDaniel James
    Posts: 844Member, Sourcefabric Team
    Thanks, I'll give it a try!
  • Hi Olaf,

    I did not try to create the image but I quickly just checked the repository.

    Commands from the file https://github.com/OlafRadicke/booktype_with_docker/blob/master/docker/start.sh you  (lines 6-11) should really be part of the Dockerfile and not start.sh. 

    That is only needed initially. You create database, you start all the migrations code to update the database and at the end create the superuser. You are using python built in web server so you don't need  "./manage.py collectstatic" (to collect all the static files and put them at one place) and "./manage.py compress" (because you are using production profile); but you would need these two steps in case you decide to use some other web server (like gunicorn or apache).

    You start.sh could also be shorter if you just 1) activate python virtual environment 2) $PATH_TO_INSTANCE/manage.py runserver 0.0.0.0:8080. No need for loading .env file if you call directly manage.py file.

    You also need to run the supervisor to run the conversion scripts so you can produce EPUB/PDF files. What you could do is setup supervisor and make supervisor run django web server (or some 3rd party server like gunicorn) and conversion scripts (that is that ./manage celeryd part in the documentation) at the same time.

    This way you will create one image which will include web server and conversion scripts and for postgresql and redis you could use existing default images provided for them. You can configure Celery to use REDIS instead of RabbitMQ (this way you don't need this service) to make things more simple.

    I mean, this all depends how you want to organise all these difference services around Docker. 

    Aco

  • Forgot to say, if you decide to run web server and celery workers over supervisor, you would need to put correct supervisor configuration into the image (which includes directives for web server and celery workers) and then start supervisord service with CMD instead of start builtin web server.

    Aco
  • Hi Aleksandar,

    thank you for you review and proposals. If I move the code to Dockerfile, than I get this error by build run:

    Step 38 : RUN django-admin.py syncdb --noinput
     ---> Running in 203fa4f984d2
    Traceback (most recent call last):
      File "/usr/local/bin/django-admin.py", line 5, in <module>
        management.execute_from_command_line()
      File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
        utility.execute()
      File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
        settings.INSTALLED_APPS
      File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 46, in __getattr__
        self._setup(name)
      File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
        self._wrapped = Settings(settings_module)
      File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 98, in __init__
        % (self.SETTINGS_MODULE, e)
    ImportError: Could not import settings 'settings.prod' (Is it on sys.path? Is there an import error in the settings file?): No module named settings.prod

    $PYTHONPATH has the value:
    :/:/docker_book/lib/:/Booktype/lib:/docker_book:/docker_book/settings

    And  $DJANGO_SETTINGS_MODULE has the value:
    settings.prod
    More details here: https://hub.docker.com/r/olafradicke/booktype/builds/bwainaajkajfen5vtkxfwjm/


    I use systemd as supervisor, so I don't need a supervisor configuration. All services has a owe container with their own systemd service configuration.
    Post edited by Olaf Radicke at 2016-01-08 05:07:06
  • Hi Olaf,

    you can also execute ./manage.py file (so you don't need to load environment variables). It should be in /docker_book/ directory. But when it comes to this error, I would say that DJANGO_SETTINGS_MODULE is wrong, in your case it should be docker_book_site.settings.prod.

    I guess your /docker_book/manage.py should have something like:

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "docker_book_site.settings.prod")

    Aco
  • My /docker_book/manage.py file hase the value:
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "docker_book_site.settings.dev")

    So, it is wrong.
  • I tried to overwriting manage.py with value
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.dev")
    but that is not a solution.