Skip to content
This repository was archived by the owner on Feb 8, 2019. It is now read-only.

Clarify Local Hosting Documentation#44

Open
wtokumaru wants to merge 15 commits intochronoscio:masterfrom
wtokumaru:clarify
Open

Clarify Local Hosting Documentation#44
wtokumaru wants to merge 15 commits intochronoscio:masterfrom
wtokumaru:clarify

Conversation

@wtokumaru
Copy link

@wtokumaru wtokumaru commented Oct 7, 2018

Took the liberty to modify the documentation to be more clear (to me at least). I think that we want to err on the side of excessive hand-holding and completeness to minimize inadvertent configuration hazing.

Also added several small comments and linting changes in other files which I can remove if they are too intrusive. I intend to remove and isolate to separate PRs anything particularly controversial.

@wtokumaru
Copy link
Author

wtokumaru commented Oct 7, 2018

Does this repo not have an option to request reviews and assign relevant developers? It also would not let me select any labels before submitting. I suspect it is a permissions thing since I still can not add any after submitting.

.autopep8.py Outdated
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
# TODO: Explain usage here? Why do we need both pylint and pep8?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8 is a Python formatting guideline. Autopep8 is a tool to automatically format python code according to the PEP8 standards. Pylint is a tool to lint python code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, pep8 for format, separately from linting.

Copy link
Author

@wtokumaru wtokumaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some explanation.

.autopep8.py Outdated
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
# TODO: Explain usage here? Why do we need both pylint and pep8?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that this all happens through CI but is it also possible to run these directly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they can be executed normally. VSCode is supposed to call them on save as well but it's not entirely working, see #32

AUTH0_CLIENT_SECRET={SECRET}
API_IDENTIFIER={IDENTIFIER}
AUTH0_DOMAIN=chronoscio.auth0.com
API_IDENTIFIER=https://chronoscio.org/api/
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included defaults here as well because we can.

'interactivemap-frontend-*.now.sh',
)

AUTH0_DOMAIN = os.environ.get('AUTH0_DOMAIN', 'chronoscio.auth0.com')
Copy link
Author

@wtokumaru wtokumaru Oct 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this default because it does not seem to work when combined with empty strings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you mean

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traceback (most recent call last):
  File "project/manage.py", line 29, in <module>
    execute_from_command_line(sys.argv)
  File "/home/tokumaru/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/home/tokumaru/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 317, in execute
    settings.INSTALLED_APPS
  File "/home/tokumaru/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/home/tokumaru/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/tokumaru/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 106, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/tokumaru/chronoscio/backend/project/interactivemap/settings.py", line 174, in <module>
    jwks = json.loads(jsonurl.read())
  File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

I traced it back to precisely this one-line change and checked several times why flipping back and forth between line options. It happens if AUTH0_DOMAIN is 'chronoscio.auth0.com' while the other two are empty strings or None. However, if all 3 are None, it works fine. Might only be a problem when hosting locally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the exact values of your environment variables?

Copy link
Author

@wtokumaru wtokumaru Oct 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The edge case I am describing is when you have none of the django.env sourced. When that happens it can still work with the defaults specified in settings.py except for this. When all the env vars are set, there is no need for defaults. The problem I observed is that the url is not compatible with empty strings or Nones, but if all three are None then they are compatible.

AUTH0_CLIENT_ID = os.environ.get('AUTH0_CLIENT_ID', '')
AUTH0_CLIENT_SECRET = os.environ.get('AUTH0_CLIENT_SECRET', '')
AUTH0_CLIENT_ID = os.environ.get('AUTH0_CLIENT_ID')
AUTH0_CLIENT_SECRET = os.environ.get('AUTH0_CLIENT_SECRET')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three being None though seems to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

.pylint.py Outdated
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
# TODO: Explain usage here? Why do we need both pylint and pep8?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

@wtokumaru
Copy link
Author

wtokumaru commented Oct 7, 2018

The Travis build failed in the same way that this fails when I try to use Docker, suggesting the problem is in the code rather than with my computer. I assume that master usually passes, so which change here makes a difference?

Copy link
Contributor

@quorth0n quorth0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONTRIBUTING.md must be placed in root, it's a GitHub specific thing. Maybe we could make a symlink or something.

README.md Outdated
AUTH0_CLIENT_ID={Client ID}
AUTH0_CLIENT_SECRET={Client Secret}
```
4) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts or doing any setup but you may need to debug OS-specific problems that appear. For example, you may need to install postgis as well. (TODO: Test this on wiped setups to find out specific steps to do this properly.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a little more verbose then necessary. A link should probably be provided to the geodjango setup information. Account handling is up to the user and OS-specific problems are a given so I don't think this sentence is necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the geodjango setup needed for?What link in particular? I do not remember doing it but may have forgotten.

README.md Outdated
AUTH0_CLIENT_SECRET={Client Secret}
```
4) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts or doing any setup but you may need to debug OS-specific problems that appear. For example, you may need to install postgis as well. (TODO: Test this on wiped setups to find out specific steps to do this properly.)
5) Change the HOST variable in the [settings.py](https://github.com/chronoscio/backend/blob/master/project/interactivemap/settings.py) file to be `localhost` instead of `db`. You may also need to change the PORT variable to match whatever you have set for postgis (TODO: investigate this).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/postgis/postgres

Copy link
Author

@wtokumaru wtokumaru Oct 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make sense but the weird thing here is that the final line I had to run to get everything working for me was actually postgis. O_o
See: https://stackoverflow.com/questions/41666196/how-to-change-install-postgis-location-postgres
The answer here sudo apt-get install postgresql-9.6-postgis-scripts did not work for me but the comment on the answer that did more brute force sudo apt install postgis did work. However, you can see from the next comment that this is not the best way to solve the problem and is kind of overkill so I did not want to include it in the docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For geodjango you shouldn't need to install anything past postgresql-x.x, postgresql-x.x-postgis, postgresql-server-dev-x.x, python-psycopg2 according to the documentation.

README.md Outdated
```
7) Migrate and run the server with django.
```bash
# Migrate the project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run SQL migrations*

README.md Outdated

project/api: REST API and a test file (how/why do we run the test)? Defines the Nation, Territory, and DiplomaticRelation classes, which are our primary database items.

project/interactivemap: Django settings and website directory layout?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think documentation here is necessary past the project/ folder as it is standard django architecture.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is standard vs. custom? Which files exactly? If we have a standard directory with a custom subdirectory in it I would like to make it clear what is going on.

README.md Outdated

project/interactivemap: Django settings and website directory layout?

project: Django execution wrapper.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django application directory*

2. Create Application > All Scopes > Authorize
3. See the `client_id`, `client_secret`, and `audience` variables in the example cURL
1. Log into https://manage.auth0.com/#/applications. It does not matter what names you select.
2. Create Application > All Scopes > Authorize. Or just create a SPA (Single Page Application).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to have to look into this for the proper procedure. See #39.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. I had not gotten around to reading that issue yet.

'interactivemap-frontend-*.now.sh',
)

AUTH0_DOMAIN = os.environ.get('AUTH0_DOMAIN', 'chronoscio.auth0.com')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you mean

AUTH0_CLIENT_ID = os.environ.get('AUTH0_CLIENT_ID', '')
AUTH0_CLIENT_SECRET = os.environ.get('AUTH0_CLIENT_SECRET', '')
AUTH0_CLIENT_ID = os.environ.get('AUTH0_CLIENT_ID')
AUTH0_CLIENT_SECRET = os.environ.get('AUTH0_CLIENT_SECRET')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

@quorth0n
Copy link
Contributor

quorth0n commented Oct 7, 2018

Does this repo not have an option to request reviews and assign relevant developers? It also would not let me select any labels before submitting. I suspect it is a permissions thing since I still can not add any after submitting.

It's a permission thing.

@wtokumaru
Copy link
Author

wtokumaru commented Oct 7, 2018

CONTRIBUTING.md must be placed in root, it's a GitHub specific thing. Maybe we could make a symlink or something.

Weird, I never saw this as a problem in other projects. How do you know this? Is it just to make a pop-up when submitting a PR?

@quorth0n
Copy link
Contributor

quorth0n commented Oct 7, 2018

Never mind actually, I just checked GitHub's docs, they say it can be placed in the docs/ directory as well.

README.md Outdated
AUTH0_CLIENT_ID={Client ID}
AUTH0_CLIENT_SECRET={Client Secret}
```
4) Install and run [Postgresql](https://www.postgresql.org/docs/9.3/static/tutorial-install.html) (AKA postgres) locally. You should not need to worry about creating any accounts. You will also need to make sure you have set up [geodjango](https://docs.djangoproject.com/en/2.1/ref/contrib/gis/install/). (TODO: Test this on wiped setups to find out specific steps to do this properly.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation link should refer to .../en/stable/contrib/... so that it's not version specific.

API_IDENTIFIER={IDENTIFIER}
AUTH0_DOMAIN={PROJECT.auth0.com}
AUTH0_CLIENT_ID={Client ID}
AUTH0_CLIENT_SECRET={Client Secret}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was API identifier removed? Also, the sed regex in .travis.yml looks for specific values for these fields which it replaces with our secrets so that will have to be updated as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just separated it elsewhere in the file to look nicer. Will look into updating .travis.yml.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to swap it back to {IDENTIFIER} I suppose for Travis to be the same, though it should not be necessary to include there? Why are some of these set with defaults in the sample env but others set with defaults in settings.py and/or .travis/yml? It seems kind of arbitrary. It feels more natural to be to just have one set of defaults and maaaaybe a second set of test-specific defaults but not 3 separate ones.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, didn't catch that. It's an Auth0-specific thing so I think it'd be better placed in the Auth0 group. I agree about the defaults actually, let's just keep them all here for simplicity's sake. The only test specific defaults are so that all third party libs can use our access tokens and such which is why they aren't publicly displayed.

@amaury1093
Copy link
Contributor

@wtokumaru About the permissions thing, I added you to the repo some time ago, have a look at https://github.com/chronoscio to accept it

@wtokumaru
Copy link
Author

Should I be able to assign, request reviews, and add tags now? I still do not appear to be able to do nay despite the member identification.

@wtokumaru
Copy link
Author

wtokumaru commented Oct 8, 2018

The Travis build failed in the same way that this fails when I try to use Docker,

This was probably due to me not updating the /travis.yml so I am looking into that.
Edit: Updated by following commits.

@wtokumaru
Copy link
Author

wtokumaru commented Oct 8, 2018

Weird, the CI just went from working to not, without adding any commits, anyone have an idea why? Does it just have that much lag?

@quorth0n
Copy link
Contributor

quorth0n commented Oct 8, 2018

My guess would be that it went from "in progress" to failing. Regardless the reason is because of the changes to this line:

API_IDENTIFIER=https://chronoscio.org/api/

.travis.yml needs to be updated for the sed replacement to work:

- sed -i 's#{IDENTIFIER}#https://chronoscio.org/api/#g' ./django.env

I think that as we established it has to be the frontend application's client ID (see my recent posts in #39) we should keep it as {IDENTIFIER}.

README.md Outdated
# ChronoScio Backend [![Build Status](https://travis-ci.org/chronoscio/backend.svg?branch=master)](https://travis-ci.org/interactivemap/backend) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0074e97bc13b476ea3eec279483d3cab)](https://www.codacy.com/app/whirish/backend?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=interactivemap/backend&amp;utm_campaign=Badge_Grade)

## Getting Started
We normally use [Docker](https://en.wikipedia.org/wiki/Docker_(software)) to simplify installation and configuration. Docker makes virtual "containers" as images which allow us to isolate code we run and work around computer-specific weirdnesses. Docker should work on [Linux](https://docs.docker.com/install/linux/docker-ce/ubuntu/) or [macOS](https://docs.docker.com/docker-for-mac/install/) but requires Hyper-V, which is not available on Windows 10 Home edition. If you have trouble with setting up Docker, see the **Local Development** instructions below instead. Otherwise, it should be simple to get started:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that it does works on Windows 10 Pro 64 bit.

README.md Outdated
# Navigate to http://localhost/, if you get a 502 error postgres likely has not been initialized yet,
# try again in a few seconds
```
Use `docker-compose down` to stop hosting when you are done.
Copy link
Contributor

@dwaxe dwaxe Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just make stop or make clean (rebase this pr off latest master)

@quorth0n
Copy link
Contributor

Could you try adding a cat django.env line to your travis.yml so we can ensure its values are correct?

@amaury1093
Copy link
Contributor

@whirish Are you sure about that? Our travis builds are public, anyone can then see our Auth0 credentials

@quorth0n
Copy link
Contributor

@amaurymartiny Doesn't Travis filter out secrets when they're printed? I was thinking worst case we could just delete the build log

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants