Local development
In this section, we start with the base. We are going to set up a local development environment with a GitHub public repository, so you could share your code with the community and keep sensitive data safe. To start, you need to have python3.6, npm, and git.
Getting started
Fork the repo and change the repository name to your own. Then clone it locally:
$ git clone git@github.com:username/your-app-name.git
$ cd your-app-nameDjango server
Install, create, and start a virtual environment to work with a Django server:
$ python3.6 -m pip install virtualenv
...
$ cd src/django_server/
$ virtualenv -p python3.6 venv
...
$ source venv/bin/activateInstall dependencies:
$ pip install -r requirements.txtPrepare settings. Duplicate and rename settings_example folder as settings withing the django_server app folder:
$ cp -r django_server/settings_example django_server/settingsGenerate SECRET_KEY:
$ python redfish/generate_secret_key.py
Paste the next string to the settings.py SECRET_KEY constant
kpvmoz93s_3*rs7i*$t5-g%x5df7!vr(7=$ie2$6pj%!5=e*8@Copy and paste it to the SECRET_KEY constant inside of the settings/common.py file:
# settings/common.py
SECRET_KEY = 'kpvmoz93s_3*rs7i*$t5-g%x5df7!vr(7=$ie2$6pj%!5=e*8@'Create a Google mail app password and set up an SMTP server:
- Go to google app passwords: https://myaccount.google.com/apppasswords. Make sure you turned on 2-step verification. Google restricts app passwords for users who don't.
- Select app:
mail; - Select device:
Other (custom name); - Fill the name, e.g.,
redfish-django-server; - Press
Generatebutton; - Copy and paste the
passwordto thesettings/common.pyfile and provide yourGMail email:
# settings/common.py
...
EMAIL_HOST_USER = 'example@gmail.com'
EMAIL_HOST_PASSWORD = 'vcnstblmegxxkvkf'
...Apply migrations:
$ python manage.py migrate --run-syncdbCreate a superuser:
$ python manage.py createsuperuser
Provide username and passwordInstall React App dependencies
$ cd ../react-app/
$ npm installAnd Landing Page dependencies as well
$ cd ../landing-page/
$ npm installStart development servers
We have three development servers here: Django, Create React App, and GatsbyJS. You can start them withing 3 console windows, or, as we highly recommend, withing tmux.
Start with terminal windows
Prepare 3 terminal instances and start django_server in first:
$ cd src/django_server/
$ python manage.py runserver 0.0.0.0:9000Start react-app development server in second:
$ cd src/react-app/
$ npm startAnd landing-page development server in third:
$ cd src/landing-page/
$ gatsby developStart with tmux [alternative and preferable way].
We already made a python script, which creates tmux windows and starts Django, CRA, and GatsbyJS development servers.
Note: Make sure that the location of your virtual environment is /src/django_server/venv folder
Execute the tmux.devlocal.py script withing the root directory:
$ python tmux.devlocal.pyRead tmux man. Some basics to play with it:
ctrl+bw- navigate through windows usingupanddownarrow keys;ctrl+bd- minimize tmux and save session;$ tmux a- back to tmux after minimize it;ctrl+d- terminate tmux and session;ctrl+b[- scroll through the content. Useupanddownarrow keys andescto exit mode;ctrl+bc- create new window.
Change site's domain and display name
Redfish sends emails for users, and there is should be a proper link. So please do the next:
- Log in to the Django admin: http://localhost:9000/admin
- Go to
Sitesand edit the first instance - Domain name set to
http://localhost:8000and Display name tolocalhost:8000. - Click save
You are ready to develop locally!
Available endpoints for you:
- http://localhost:8000/ - landing page
- http://localhost:3000/ - application
- http://localhost:9000/graphql - IDE for exploring GraphQL
- http://localhost:9000/admin - Django admin