cfahlgren1 / Bounce

A Django web application that uses MapBox to show thousands of outdoor basketball courts all around the United States
https://bouncemap.com
19 stars 9 forks source link

First docker implementation #14

Closed marcorichetta closed 4 years ago

marcorichetta commented 4 years ago

Fixes #12

marcorichetta commented 4 years ago

@cfahlgren1 I had to comment out this entire viewset to be able to run the project https://github.com/cfahlgren1/Bounce/blob/fb9dc4f0e2600c8952592260e85b21e1e13a615b/courts/views.py#L160

Error

  queryset = MapStyle.objects.get(active=True)  # get map that is currently active
File "/usr/local/lib/python3.8/site-packages/django/db/models/manager.py", line 82, in manager_method
  return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 415, in get
  raise self.model.DoesNotExist(
courts.models.DoesNotExist: MapStyle matching query does not exist.

Possible solution

To me it seems that the error comes from .get(active=True).

The MapStyle model inherits from SingleActiveModel but when you call MapStyle.objects.get you're using the MapStyle manager, which doesn't know the existence of the active field. (Django custom managers)

cfahlgren1 commented 4 years ago

Wow! This looks like great work. I am glad you were able to find the GEO libraries. Getting the GEO libraries setup correctly, is the hardest part of the setup!

marcorichetta commented 4 years ago

@cfahlgren1 I've had project set up with postgis so I didn't had much problem haha Anyway I marked the PR as "draft" because I didn't tried to save a Court, so I don't really know if the DB is correctly configured.

It's up to you to merge this PR.

cfahlgren1 commented 4 years ago

@cfahlgren1 I've had project set up with postgis so I didn't had much problem haha Anyway I marked the PR as "draft" because I didn't tried to save a Court, so I don't really know if the DB is correctly configured.

It's up to you to merge this PR.

Okay thank you for working on this. Having the docker working correctly is the most important moving forward to streamline a CI/CD process and testing. I will do some test and review the PR tomorrow and make sure it works with the DB and everything! In the mean time, feel free to join the slack. I have connected Sentry with a channel and will use it for any discussions outside of Git.

marcorichetta commented 4 years ago

I am getting "web_1 : no destination" in the docket-compose logs and am not able to get a response from the URL. Everything else in the docker process seems good however.

@cfahlgren1 Oh. This was the error I struggled the most with. I just realized I never commited the .env variables used by docker.

This are for local development so no worries.

### DATABASE
ENGINE=django.contrib.gis.db.backends.postgis
DATABASE=postgres
NAME=postgres
PASSWORD=postgres
DB_HOST=db
PORT=5432

### Docker entrypoint
DATABASE_HOST=db
DATABASE_PORT=5432

Make sure to add to .env.template the ones that are missing so others don't have to struggle so much :laughing:

cfahlgren1 commented 4 years ago
```shell
courts.models.DoesNotExist: MapStyle matching query does not exist.

@marcorichetta The issue is actually because a mapstyle and api key to load the map isn't being found in the database. I just added a fixture file that can be used with python manage.py loaddata bounce_data.json which should import the data into the db. This should fix that issue you are having when loading the page.

marcorichetta commented 4 years ago
```shell
courts.models.DoesNotExist: MapStyle matching query does not exist.

@marcorichetta The issue is actually because a mapstyle and api key to load the map isn't being found in the database. I just added a fixture file that can be used with python manage.py loaddata bounce_data.json which should import the data into the db. This should fix that issue you are having when loading the page.

I'll try to load the sample data you provided and also check the collectstatic issue.

cfahlgren1 commented 4 years ago
```shell
courts.models.DoesNotExist: MapStyle matching query does not exist.

@marcorichetta The issue is actually because a mapstyle and api key to load the map isn't being found in the database. I just added a fixture file that can be used with python manage.py loaddata bounce_data.json which should import the data into the db. This should fix that issue you are having when loading the page.

I'll try to load the sample data you provided and also check the collectstatic issue.

Obviously soon, both will be grabbed from the API instead of having to put it in the DB so you can rotate keys etc. Thank you for tackling the big docker stuff, I know it isn't easy 😆

marcorichetta commented 4 years ago

@cfahlgren1 You were right with the ObjectDoesNotExist exception. Anyway, I changed from .get, which returns only one object, to .filter which returns a queryset.

I think it's what you need, but correct me if I'm wrong.


Staticfiles

I had to change the slashes because the docker container runs on Ubuntu. Also, to run collect the static files I had to specify the settings to use.

python manage.py collectstatic --settings settings.dev

Testing with DEBUG = False throws the following error.

ValueError: Missing staticfiles manifest entry for 'style.css' even though I collected all the files. Maybe I'm missing some configuration.

cfahlgren1 commented 4 years ago

@cfahlgren1 You were right with the ObjectDoesNotExist exception. Anyway, I changed from .get, which returns only one object, to .filter which returns a queryset.

I think it's what you need, but correct me if I'm wrong.

Staticfiles

I had to change the slashes because the docker container runs on Ubuntu. Also, to run collect the static files I had to specify the settings to use.

python manage.py collectstatic --settings settings.dev

Testing with DEBUG = False throws the following error.

ValueError: Missing staticfiles manifest entry for 'style.css' even though I collected all the files. Maybe I'm missing some configuration.

@marcorichetta Awesome, I will take a look at this today and see if I can figure out the error.

marcorichetta commented 4 years ago

@cfahlgren1 Not on my computer right now but if you can take a look at this answer for the missing static files error.

cfahlgren1 commented 4 years ago

@cfahlgren1 Not on my computer right now but if you can take a look at this answer for the missing static files error.

@marcorichetta , I have pulled down your new changes and tested everything. I was able to collect the static files, and run everything correctly. I also tested the DB connections as well. Everything looks great on my end and seems ready to merge. Are you still getting that error?

marcorichetta commented 4 years ago

Are you still getting that error?

@cfahlgren1 Just tried to fix that error today but it didn't happen again, so I think it's up to you to merge! :tada: