Quick note: this uses Docker and Docker Compose and we will keep the Python environment at 3.6 for now.
Clone the repository
$ git clone https://github.com/stoltzmaniac/foco_ds_portal.gitUpdate the environment variables in docker-compose.yml by:
- Rename
.env.exampleto.env - Fill in the variables (a few are prepopulated for debug mode)
- Copy the project/nginx/default.conf.example (remove .example) replace your server/domain
- This will be ignored via
.gitignore
Build images and spin up containers!
$ sh initial_deploy.shAccess the application at the address http://localhost:5002
Test without coverage:
$ docker-compose run web python manage.py testTest with coverage:
$ docker-compose run web python manage.py covLint:
$ docker-compose run web flake8 projectDo you have the desire to add something to this project? If so, please follow the steps outlined below.
- After cloning, create a branch and name it with your GitHub username
- Pop into the
project/serverdirectory and create a directory with your GitHub username- You can follow the example of
new_user_addition_example - Basically copy the directory and find / replace
new_user_addition_examplewith your username - I left a bunch of imports in there to help you understand what's going on in
projects/server/stoltzmaniac
- You can follow the example of
- Pop into the
project/client/templatedirectory and create a directory with your GitHub username- You can follow the example of
new_user_addition_example - Basically copy the directory and find / replace
new_user_addition_examplewith your username
- You can follow the example of
- Register your the Blueprint you just made (
project/new_user_addition_example/views)- This is done in
project/server/__init__.py - Add it directly underneath the other
register_blueprintsections (same with your import) - Keeping with our
new_user_addition_exampleyou would add two lines:from project.server.new_user_addition_example.views import new_user_addition_example_blueprintapp.register_blueprint(new_user_addition_example_blueprint
- This is done in
- Make something awesome!
- Any requirements must go at the bottom of the
requirements.txtfile. - If you need environment variables, please just add a blank line with the name in
.env.example - Don't forget to add tests in the
project/server/testsdirectory - call your filetest_<your_username> - Use the
test_useras an example if you're just getting started with testing
- Any requirements must go at the bottom of the
- Clean your code by using black
black project- If you don't already have black
pip install black
- If you don't already have black
- Commit everything and make a pull request
If you are going to add a data source, try to follow what's going on in the project/twitter directory.
If your data sources require environment variables please let me know how to make my own accounts for those
services so we can allow everyone to access that data!
The Nginx container has a Let's Encrypt client installed called certbot. If you are running on a server that a valid domain name points to, you can obtain certificates and instruct Nginx to use them for SSL / TLS. You must first execute certbot and provide information specific to your server / domain.
- Before you begin, change the
server_nameparameter in yourprojects/nginx/nginx.conffile fromlocalhostto your domain name (e.g.example.com). - You need to rebuild your Nginx container for the changes to take effect. Alternatively, you can manually copy the new file into the container but you will have to restart the container or enter the shell and reload Nginx.
- Open a shell in the running Nginx container.
docker-compose exec web-nginx sh
- Once at the Nginx containers shell prompt, run the
certbotclient.
certbot --authenticator webroot --installer nginx --webroot-path /var/letsencrypt --staging- You will be prompted for information and decisions. Specifically:
- The domain name you are obtaining a certificate for. This can be provided on the command line with the
--domainoption. - An email address to receive information from Let's Encrypt like certificate expiration notices. This can be provided on the command line with the
--emailoption. - You will have to agree to the terms of service. This can be skipped on the command line with
--agree-tos. - Do you want to configure Nginx to redirect all insecure requests (port 80) to the secure port, 443? This can be specified on the command line with
--redirector--no-redirect.
- The domain name you are obtaining a certificate for. This can be provided on the command line with the
- The above command uses the
--stagingoption which will test your configuration but not obtain valid certificates. This is useful so that you do not hit any request limits with Let's Encrypt while you are testing.
- At this point you should be able to connect to your site using HTTPS but the certificate will not be valid and the browser will likely complain.
- Once you are satisfied that the request is successful, re-run the above command without
--staging. - Exit the Nginx shell with
exit.
You should now be able to establish a secure connection to your server.