This repo contains code for the database and server of the TEDxUWA website
The instructions below will help you set up a development environment
Download and install python 3.6
cd
into the project folder
$ cd tedxuwa-server-backend
Download virtualenv
$ pip install virtualenv
If you have multiple versions of python installed, please run pip3
instead
A virtual environment ensure everyone working on this project will have the same dependencies installed and avoid the "it worked on my machine" bug. Create a new virtualenv with
$ virtualenv env
If you have multiple versions of python installed, run:
$ virtualenv -p python3.6 env
To activate the virtual environment, run
$ source env/bin/activate
You will need to run this command every time you want to continue working on this repo
Installing requirements
$ pip install -r requirements.txt
Run migrations
$ python manage.py migrate
Load dummy data
To start up the server, run
$ python manage.py runserver
The server will now be avalaible at localhost:8000. For more server starting options, visit the django docs for the runserver command
The folder structure is as follows:
root (~/)
└── website
├── back-end
├── deploy.sh
└── front-end
Where back-end
is this repo and front-end
is our front end repo. This structure is embedded in most of
the code (nginx config, deployment script, etc...) so it's a little hard to change.
deploy.sh
is a copy of the deploy.sh
file in this repo. It's copied out to the
website folder so that we don't have to add execute permission to it everytime backend updates.
This is the script to be run when you want to deploy either front end or back end code.
To run the deployment script, run
$ cd ~/website
$ ./deploy.sh
If deploy.sh doesn't have the permission to run, do chmod +x deploy.sh
first then try again. If that still
doesn't work, open up the file and copy paste the commands inside
NOTE: If you made a change to the deployment script, running ./deploy.sh
once will update the deployment script file on the server and running it a second time will make the changes take effect
If you are setting up a brand new server, access the server's console and follow these steps:
NOTE: before you setup a new server, make sure you have a backup of the db.sqlite3
file from
the server available. This IS the database including all the data so copy it out before you delete the old server
$ sudo apt-get update
# python and pip
$ sudo apt-get install python3.6-dev
$ sudo apt-get install -y python3-pip
# c compiler for uWSGI
$ sudo apt-get install build-essential
# nginx
$ sudo apt-get install nginx
$ cd ~/
$ mkdir website
$ cd website
$ git clone https://github.com/TEDxUWA/tedxuwa-server-backend.git ./back-end
$ git clone https://github.com/TEDxUWA/tedxuwa-react.git ./front-end
# copy it out to ~/website
$ cp back-end/deploy.sh ./
# add execute permission
$ sudo chmod +x deploy.sh
# run it
$ ./deploy.sh
The server should now be setup and running!
Certbot can be used to setup https. Head to https://certbot.eff.org/ and select NGINX and the appropriate OS that the new server is running on and follow the instructions.
If you're migrating the server and closing down the old one, you have 2 options to migrate the data over
- Copying
db.sqlite3
If the new server will still be using sqlite as the database, you can simply copy thedb.sqlite3
file from the old server over the the new one and all should be working - Using Django's dumpdata and loaddata
You can use
dumpdata
to dump everything in the database into a json file then useloaddata
on the new server to populate them all again. Using this you can switch from using sqlite to using another database by changing the database driver and load the data into the new database
- Django: a server framework for python
- Nginx: webserver
- uWSGI: application server container
- Sqlite: small imbeded database
- Circleci: continuous intergration service
- Codecov: code coverage service
- Sentry: automated error log capture
- Papertrail: loggin service
- The
db.sqlite3
IS the database. Backup regularly and don't delete it on production - The front end template dir is set to
static/build/
with entry point ofreact_base.html
- set
DEPLOYMENT
environment variable in production - set
DJANGO_SECRET_KEY
environment variable in production - set
PAPERTRAIL_LOG_DESTINATION
environment variable in production - regenerate django secret key
- protect master branch
- run
collectstatic