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

Project's DB set-up #25

Open
JSerwatka opened this issue Apr 19, 2021 · 10 comments
Open

Project's DB set-up #25

JSerwatka opened this issue Apr 19, 2021 · 10 comments

Comments

@JSerwatka
Copy link
Contributor

Maybe this is a silly issue, but I'm new to Docker and I got stuck setting up this project.

Problem

Do I need anything more than what is in the original repo to run it?
For example:

  • Do I have to configure anything in settings.py? Like this:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'HOST': 'db',
        'PORT': 5432
    }
}
  • Do I have to make any change in environmental variables? Especially in this part:
#env.local
DATABASE_URL=postgres://postgres@postgres:5432/db
  • Do I have to add POSTGRES_PASSWORD or POSTGRES_USER to docker-compose?

What I've tried

  • Without any changes - Error: Database is uninitialized and superuser password is not specified.
  • With POSTGRES_PASSWORD set in docker-compose I get this error:
    image
    But container seems to be working. When I try to make migration after that I get:
    image

Maybe you know some quick-fix?

@mammuth
Copy link
Owner

mammuth commented Apr 20, 2021

Hey, cool that you want to set up the project locally!

I'm not quite sure which steps are needed. Back then I probably set it up with the divio CLI (divio is the cloud provider it is hosted and where I took the project template from).

The problem is for sure, that the logical database doesn't yet exist in your DB container. By adding the variables, the used image should be able to create it for you I think, but we obviously need to make sure to have the correct DB name, username, and password.

The database settings have to be somewhere already, I think.

Maybe this already helps you to set it up. If not, I'll try to dig in if I find the time.

Btw, we should then also improve the readme by adding all required steps of setting it up.

@JSerwatka
Copy link
Contributor Author

Thanks for the reply!

I've managed to start it with this configuration:

#docker-compose.yml
...
  db:
    image: postgres:9.6-alpine
    environment:
      - POSTGRES_DB=db
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
#.env-local
...
DATABASE_URL=postgres://postgres:postgres@postgres:5432/db
#settings.py

ALLOWED_HOSTS = ['*']  # Documentation says it is required for Windows 10

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': 'db',
        'PORT': 5432
    }
}

Then I ran:

  1. docker-compose up
  2. docker-compose run --rm web python manage.py migrate
  3. I stopped the containers and reran: docker-compose up <- I think you need to migrate first to get the server running

This way I was able to run a server, but I guess something is still not quite right with the db setting, because I get this when trying to create a new account:
image

@JSerwatka
Copy link
Contributor Author

The thing that I'm the least sure of is this aldryn_addons and the configuration of DATABASE_URL.

As you said:

The database settings have to be somewhere already, I think.

My prediction is that the DB settings are set by these two lines:

#settings.py
import aldryn_addons.settings
aldryn_addons.settings.load(locals())

@JSerwatka
Copy link
Contributor Author

Btw, we should then also improve the readme by adding all required steps of setting it up.

I would love to get involved in your project, so I will definitely update the readme when I manage to configure it all.

@mammuth
Copy link
Owner

mammuth commented Apr 23, 2021

Did you, in the end, manage to get it running?

My prediction is that the DB settings are set by these two lines:

aldryn-django does it like this: https://github.com/divio/aldryn-django/blob/support/1.11.x/aldryn_config.py#L88

@JSerwatka
Copy link
Contributor Author

I've already found this configuration file and glanced over it.

This NoReverseMatch is something different. From what I know usage of url tag (% url 'app_name:url-name' %}) requires app_name variable setting inside app_name/urls.py, but I can't find anything like this in your code. Maybe this is some kind of django version difference, because the only thing I've found that is somehow related, is this part inside settings.py:

INSTALLED_APPS.extend([
    ...
   'clipping_manager',
])

I'll look into it tomorrow, or at worst, on Monday. We'll fix it eventually 😉

@mammuth
Copy link
Owner

mammuth commented Apr 24, 2021

From what I know usage of url tag (% url 'app_name:url-name' %}) requires app_name variable setting inside app_name/urls.py, but I can't find anything like this in your code.

Ah, I just checked it, the app is configured as a django cms app hook.

OnPaste 20210424-200915

I guess using this app hook's slug in the code (templates/views/...) was probably a stupid idea, because when setting up the project, you simply don't have this app hook.

Just for the record, this is my .env-local as set up via the divio CLI:

# Please take care that you do not inadvertently commit any configuration secrets
DEBUG=True
STAGE=local
DATABASE_URL=postgres://postgres@postgres:5432/db

@JSerwatka
Copy link
Contributor Author

🎉🎉🎉

Thanks a lot, now it works! Or at least it works for now 😉

I have 2 last questions before closing this issue:

  1. So I created this page in the CMS and hooked it as you said:
    image
    Is there a need to configure anything else in the CMS?

  2. Why are you using this CMS at all? From what I know CMSs are used only to publish content, but there is nothing to publish in this app. Is it because of a better admin panel?

@mammuth
Copy link
Owner

mammuth commented Apr 26, 2021

Thanks a lot, now it works! Or at least it works for now wink

Great! 🎉

Is there a need to configure anything else in the CMS?

Not that I'm aware of. But make sure to publish the page with the apphook, it won't work if it's only a draft.

Why are you using this CMS at all?

I just wanted to try it and used it to build the "website" around the clippings application. So the landing page and all other content pages are purely built with the CMS. There are also static place holders that you can add to django templates, this allows to do stuff like in the second screenshot.

image
image

@JSerwatka
Copy link
Contributor Author

Ohh I see now.

So the plan now is to replicate everything I've done so far and update "Project setup" instruction.
I'll close this issue with a PR.

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

Successfully merging a pull request may close this issue.

2 participants