hackoregon / backend-examplar-2018

an example dockerized geo-aware django backend
MIT License
4 stars 5 forks source link

Run the Sample leads to a non-functional Django app #12

Closed MikeTheCanuck closed 6 years ago

MikeTheCanuck commented 6 years ago

When I run ./bin/start.sh -l, the startup process finalizes with the following console output:

api_development_1  | (0.000) SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"; args=()
api_development_1  | April 12, 2018 - 06:42:06
api_development_1  | Django version 2.0.1, using settings 'dead_songs.settings'
api_development_1  | Starting development server at http://0.0.0.0:8000/
api_development_1  | Quit the server with CONTROL-C.

So, after my experiences last year with the API containers, I browsed to http://0.0.0.0:8000/ and expected some form of 200/OK type reponse, and some basic Django API response.

Instead I see the following:

Page not found (404)

Request Method: | GET
-- | --
http://0.0.0.0:8000/

Using the URLconf defined in dead_songs.urls, Django tried these URL patterns, in this order:

admin/
^ ^schema/
^ ^api/
The empty path didn't match any of these.

The /admin and /schema routes work fine, as documented later, but this could be disconcerting to a new Django developer.

bhgrant8 commented 6 years ago

Hey,

This is basically the same pattern we followed last year, and would provide a not found if going to the root on a local machine. If you remember the load balancer on AWS will point to the /api path and not the root of the directory, so will auto-direct you to the correct location once live. IF i remember correctly, we did remove the Django built in browsable api (what you currently see at the /api path) and just use swagger (what is currently at the /schema path).

This can be done pretty quickly.

Can document the not found though in the readme, more directly. Unless, we expect to make a change to how the load balancer works.

znmeb commented 6 years ago

Also, on Windows hosting, browsing to http://0.0.0.0:8000/ won't work! So this needs to be documented somehow.

On Windows 10 Pro with Docker for Windows, it's http://localhost:8000/api. For other Windows versions with Docker Toolbox, you have to do docker-machine ip and put the IP address where localhost is in the above URL. :-(

bhgrant8 commented 6 years ago

Ok, to update, we actual led to the team name to work with the load balancer:

https://github.com/hackoregon/backend-service-pattern/blob/master/homelessAPI/urls.py#L24

    url(r'^homeless/', include('homelessApp.urls', namespace='homeless'))

the root of which went to the schema_view:

https://github.com/hackoregon/backend-service-pattern/blob/45b3c989817993ac03750118fb2f2199cee42230/homelessApp/urls.py#L9


from django.conf.urls import url
from . import views

from rest_framework_swagger.views import get_swagger_view

schema_view = get_swagger_view(title='Team Homelessness API')

urlpatterns = [
    url(r'^$', schema_view),
    url(r'^disability/$', views.ListDisability.as_view()),
    url(r'^ethnicity/$', views.ListEthnicity.as_view()),
    url(r'^gender/$', views.ListGender.as_view()),
    url(r'^geolocation/$', views.ListGeographiclocation.as_view()),
    url(r'^individuals/$', views.ListHomelessindividuals.as_view()),
    url(r'^veterans/$', views.ListVeterans.as_view()),
    url(r'^sleeping/$', views.ListSleepingLocation.as_view()),
    url(r'^length/$', views.ListLengthOfHomelessness.as_view()),
    url(r'^domesticviolence/$', views.ListDomesticViolence.as_view()),
    url(r'^chronic/$', views.ListChronicHomelessness.as_view()),
    url(r'^agehousecomp/$', views.ListChronicHomelessness.as_view()),
    url(r'^acsage/$', views.ListAcsage.as_view()),
    url(r'^acsdisability/$', views.ListAcsdisability.as_view()),
    url(r'^acsrace/$', views.ListAcsrace.as_view()),
    url(r'^acsveteran/$', views.ListAgeHouseComp.as_view()),
]

This will still return a Not Found locally.

So guess we have a few tasks:

  1. update the docs to state root will return not found locally.
  2. update pathing to point to the team-name at root
  3. (maybe) remove the builtin django-rest-framework browsable API - the current /api endpoint
  4. (maybe) figure out if any scripting/config needs to be done for creating a new project with correct url pathing.
znmeb commented 6 years ago

I'll start on the README - it's Docker host dependent.

znmeb commented 6 years ago

I've updated the README with notes on Windows and Linux Docker hosting. I don't have a Mac; someone else will need to do that one. I think Docker for Mac is the same as Docker for Windows.

MikeTheCanuck commented 6 years ago

@bhgrant8 thank you for reminding me how we got to this state last year (don't know how I forgot that very meaningful switchover to ALB and a single front-end for all the services).

@znmeb thanks for documenting - the Mac scenario works the same both for native Docker and for the Docker Toolbox. It also looked like the Linux scenario was same as native Docker for Windows & MacOS so I rearranged things for clarity: https://github.com/hackoregon/backend-examplar-2018/commit/209c738c869425c34874c1a368330989ed641a75

znmeb commented 6 years ago

The way I run Docker for Windows is via Windows Subsystem for Linux Ubuntu. That's documented at https://github.com/hackoregon/data-science-pet-containers/blob/master/win10pro-wsl-ubuntu-tools/README.md, I had trouble with the git bash window, Most things worked but there were some annoying things that didn't.