Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker support [WIP] #32

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open

Docker support [WIP] #32

wants to merge 54 commits into from

Conversation

stefankoegl
Copy link
Member

@stefankoegl stefankoegl commented Nov 16, 2014

Support running gpodder.net in Docker.

Getting started

# Start all the containers
sudo docker-compose up

# Initialize database
sudo docker run -it --env-file=contrib/docker.env --network mygpo_default mygpo_beat python manage.py migrate

# Create an admin user
sudo docker run -it --env-file=contrib/docker.env --network mygpo_default -it mygpo_beat python manage.py createsuperuser

TODO

  • media files (images / css) is not yet served correctly
  • split media and static files Split static and media files #28
  • Startup ordering is not correct yet; beat and worker fail because the database takes too long to start
  • docs
  • probably more

@JeanFred
Copy link

JeanFred commented Aug 9, 2016

Hello,

I tried to have a look at this to get it working using docker-compose.

I rebased this and here is where I am currently:
JeanFred@e8b3212

Still more to do, but I’m stuck on a Django migration thing (and my Django-fu is not that strong):

Steps to reproduce:

  1. Check out my branch 'docker'
  2. docker-compose up -d
  3. docker-compose run --rm web python manage.py migrate
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "auth_user" does not exist
LINE 3: FROM auth_user
             ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 26, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 398, in execute
    self.check()
  File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 426, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python3.5/site-packages/django/core/checks/registry.py", line 75, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/srv/mygpo/mygpo/users/checks.py", line 17, in check_case_insensitive_users
    cursor.execute(SQL)
  File "/usr/local/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.5/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.5/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "auth_user" does not exist
LINE 3: FROM auth_user

Looking around, folks often advise to run manage.py migrate auth, or manage.py makemigrations <snip> − I tried a lot of those but no chance.

Would that ring a bell to anyone by any chance ? :)

@JeanFred
Copy link

Thoughts @stefankoegl ? :)

@morgenroth
Copy link

Hello,

I tried to run mygpo in docker-compose and got the same error. It looks like there is a missing initialization of the DB, but "manage.py migrate" did not help.

mygpo_1  | The above exception was the direct cause of the following exception:
mygpo_1  | 
mygpo_1  | Traceback (most recent call last):
mygpo_1  |   File "manage.py", line 26, in <module>
mygpo_1  |     execute_from_command_line(sys.argv)
mygpo_1  |   File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
mygpo_1  |     utility.execute()
mygpo_1  |   File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 345, in execute
mygpo_1  |     self.fetch_command(subcommand).run_from_argv(self.argv)
mygpo_1  |   File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 348, in run_from_argv
mygpo_1  |     self.execute(*args, **cmd_options)
mygpo_1  |   File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 398, in execute
mygpo_1  |     self.check()
mygpo_1  |   File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 426, in check
mygpo_1  |     include_deployment_checks=include_deployment_checks,
mygpo_1  |   File "/usr/local/lib/python3.5/dist-packages/django/core/checks/registry.py", line 75, in run_checks
mygpo_1  |     new_errors = check(app_configs=app_configs)
mygpo_1  |   File "/mygpo/mygpo/users/checks.py", line 17, in check_case_insensitive_users
mygpo_1  |     cursor.execute(SQL)
mygpo_1  |   File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 64, in execute
mygpo_1  |     return self.cursor.execute(sql, params)
mygpo_1  |   File "/usr/local/lib/python3.5/dist-packages/django/db/utils.py", line 95, in __exit__
mygpo_1  |     six.reraise(dj_exc_type, dj_exc_value, traceback)
mygpo_1  |   File "/usr/local/lib/python3.5/dist-packages/django/utils/six.py", line 685, in reraise
mygpo_1  |     raise value.with_traceback(tb)
mygpo_1  |   File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 62, in execute
mygpo_1  |     return self.cursor.execute(sql)
mygpo_1  | django.db.utils.ProgrammingError: relation "auth_user" does not exist
mygpo_1  | LINE 3: FROM auth_user
mygpo_1  |              ^
mygpo_1  |

How can I initialize the database properly?

@fabolhak
Copy link

fabolhak commented Sep 4, 2016

With the Dockerfile from @morgenroth I get the same error. I think it is maybe because of python 3.

So I tried it with an older ubuntu version and python 2.7. Unfortunately without any luck :(

root@ecc3f2d6657b:/mygpo# python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 26, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 327, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/mygpo/mygpo/api/__init__.py", line 27, in <module>
    from mygpo.utils import parse_request_body
  File "/mygpo/mygpo/utils.py", line 236
    print('\r', end=' ', file=stream)
                   ^
SyntaxError: invalid syntax

@JeanFred
Copy link

Digging through StackOverflow, that might rather be something due to a Django upgrade?

@fabolhak
Copy link

I tried various commands, including:
python3 manage.py migrate
python3 manage.py migrate auth
python3 manage.py migrate mygpo
python3 manage.py makemigrations auth
python3 manage.py makemigrations mypgo

Without any luck :( .
Always the same error from above.

@elelay
Copy link
Member

elelay commented Apr 8, 2017

This is due to changed exception thrown on by django when a table is missing from the DB.

In mygpo/users/checks.py, import ProgrammingError instead of OperationalError and catch it:

-    except OperationalError as oe:
-        if 'no such table: auth_user' in str(oe):
+    except ProgrammingError as oe:
+        if 'no such table: auth_user' in str(oe) or 'relation "auth_user" does not exist' in str(oe):

This worked for me

JeanFred added a commit to JeanFred/mygpo that referenced this pull request Jul 1, 2017
@JeanFred
Copy link

JeanFred commented Jul 1, 2017

Thanks @elelay ! That did the trick. I got a bit further on in JeanFred@d8d89a2

@elelay
Copy link
Member

elelay commented Jul 2, 2017

Great!

@coveralls
Copy link

coveralls commented Jul 2, 2017

Coverage Status

Coverage decreased (-46.3%) to 0.14% when pulling f180435 on docker into 5cd52a5 on master.

@coveralls
Copy link

coveralls commented Jul 2, 2017

Coverage Status

Coverage decreased (-46.3%) to 0.14% when pulling 3a719f0 on docker into 5cd52a5 on master.

@coveralls
Copy link

coveralls commented Jul 2, 2017

Coverage Status

Coverage increased (+0.03%) to 46.424% when pulling 9ce0fa2 on docker into 5cd52a5 on master.

@stefankoegl
Copy link
Member Author

Hi everyone! I appreciate your interest in that topic, and I'd like to continue working on that pull request. Is anyone of you still working on that? Where did you get stuck exactly?

@elelay
Copy link
Member

elelay commented Jul 23, 2017

My struggles were with compatibility with newer django version (ProgrammingError instead of ProgrammingError) and python 2 compatibility (broken in a few files). I've not tried to dockerize.
My second issues were with setting up periodic tasks to parse feeds, etc..

@elelay
Copy link
Member

elelay commented Jul 23, 2017

Great to hear you're working on it, btw. Thanks!

stefankoegl and others added 6 commits July 23, 2017 10:44
This is useful for development, when there is no
nginx server to serve assets.
This keeps crashing with
` ModuleNotFoundError: No module named 'django_nose'`
even though the package is installed. Let's ignore for now.
@JeanFred
Copy link

JeanFred commented Jul 23, 2017

@stefankoegl I don’t really work actively on it (I just thought it would be a fun app to dockerize :). Glad to hear you are on it :)

With my current setup I got as far as correctly running mygpo using docker-compose. Static assets are served, I could create user account from command line.
What does not work is:

  • e-mail for registration, but I don’t think that’s really needed
  • ElasticSearch setup − I could correctly add an ES container, but it would need a couple of fixtures (indices etc.) − since PostgreSQL fulltext search #38 may get rid of ES, I did not look into it further

All in all, you may be interested in these two commits:

  • JeanFred@89d689f is a complete docker-compose setup, with a base image based on python:3 rather than ubuntu
  • JeanFred@cdcb34f serves static assets using Whitenoise, which avoid having to throw an nginx webserver

Hope that helps! (Note that I’m not very familiar with mygpo so I definitely may have missed obvious things)

@stefankoegl stefankoegl changed the title Docker support Docker support [WIP] Jan 30, 2020
@SiqingYu SiqingYu self-requested a review February 23, 2020 22:58
@SiqingYu SiqingYu self-assigned this Feb 23, 2020
@SiqingYu
Copy link
Contributor

I am currenly triaging this pull request. For more discussions about Docker containerization, please comment under #355 😄

@SiqingYu SiqingYu mentioned this pull request Feb 24, 2020
4 tasks
@SiqingYu SiqingYu linked an issue Feb 24, 2020 that may be closed by this pull request
4 tasks
SiqingYu and others added 7 commits February 24, 2020 15:46
There is no sudo available in the Docker environment.

Let's just move the `apt-get` call command to a variable,
and override it in Makefile call in the Dockerfile.
There was a breaking change recently in Postgres Docker image:
```
Error: Database is uninitialized and superuser password is not specified.
       You must specify POSTGRES_PASSWORD for the superuser. Use
       "-e POSTGRES_PASSWORD=password" to set it in "docker run".

       You may also use POSTGRES_HOST_AUTH_METHOD=trust to allow all connections
       without a password. This is *not* recommended. See PostgreSQL
       documentation about "trust":
       https://www.postgresql.org/docs/current/auth-trust.html
```

This may not be the best setting, but let's go for this.

See docker-library/postgres#681
Without it, the step `compilemessages` fails.
@JeanFred
Copy link

JeanFred commented Apr 14, 2020

I tried spinning up this and ran into a couple of issues, which I submitted as #397. Hope this helps!

This gets me as far as a clean Docker build, and an accessible UI. Static assets (CSS etc.) are however not served.

EDIT: Added one more commit, static assets are now correctly served.

This is one of the few requirements for whitenoise to just work.

See http://whitenoise.evans.io/en/stable/django.html

(This had been done in cdcb34f, but probably lost in a master merge)
jgrocho added a commit to jgrocho/mygpo that referenced this pull request Aug 4, 2020
Using (gpodder#32) and
(gpodder#397) as a starting point, we
implement some changes to get mygpo to run correctly under Docker.

To actually make use of this, we need an as-yet-unpublished `Dockerfile`
and `docker-compose.yaml`.
jgrocho added a commit to jgrocho/mygpo that referenced this pull request Aug 4, 2020
Using (gpodder#32) and
(gpodder#397) as a starting point, we
implement some changes to get mygpo to run correctly under Docker.

To actually make use of this, we need an as-yet-unpublished `Dockerfile`
and `docker-compose.yaml`.
Some fixes for the Docker setup
@oliverkane
Copy link

Hi there. I figure I'd offer this wonderful script I use in my projects to wait for other containers to be there before you start

https://github.com/vishnubob/wait-for-it

Add this to the container that you want to hold up for a service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker containerization
8 participants