Source code for the UPE website at UC Berkeley.
General Conventions:
- Simpler models are better
- Commit all of your migration scripts
- Don't commit unnecessary stuff (settings.py...)
- Do not store things like passwords and auth in code/on git
Coding Conventions:
- Use "_" for filenames
- Use "-" for class names
- Use Font Awesome for icons
- Don't use JS if it's doable using CSS3
- Use good markup: Make things extensible, use classes and IDs efficiently, use the right semantics
- snake_case for variables and functions, CamelCase for objects and models
- 4 spaces per tab, spaces only
- For your operating system, install Docker-Engine and Docker Compose
- Docker Compose lets us run the two services (web and database) with their own sub network
- Clone this repo if you haven't already
- Rename
website/upe/settings.py.docker
towebsite/upe/settings.py
- Run
docker-compose up -d
to build and start the containers (run this command in the same directory as theDockerfile
anddocker-compose.yml
file) - Now we need to run
syncdb
. Rundocker-compose run web python3 /opt/website/manage.py syncdb
and create an admin account - Restart our web container so things work well.
docker-compose restart web
- You should be able to access the website now from your machine on port 8001 (i.e. go to your web browser and go to 127.0.0.1:8001). Isn't that simple?
- We defined our Django web application to be part of the "web" service and the MySQL database to be part of the "database" service in the
docker-compose.yml
file - Any edits you make in the should be reflected in your Docker Container - if you look at the compose file, we mounted
.
(current directory containing the website files) to/opt/website
in the container - When you make changes, you may need to restart the container for those changes to be reflected. To do this, use the command
docker-compose restart web
to restart the web service. - When you need to run Django commands (e.g.
makemigrations
), just use docker-compose:docker-compose run web python3 /opt/website/manage.py <command>
- If things don't seem to be working, just try restarting the web service again
- Database volume should persist since we created a volume through Docker
- Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Have Python 3 installed (
brew install python3
) - Have
pip3
installed (Should come with step 2) - Install
virtualenv
by doingpip3 install virtualenv
- Clone this git repo
- In the git repo, create a virtual env
virtualenv --python=/path/to/python3 venv
You probably can get away withvirtualenv venv
, but if you see python2.7 somewhere in the command log. Use the commandwhich python3
to figure out where python3 is installed.
--python
lets you choose which Python installation to use. If you have something like Anaconda-Python, perhaps you want to use the Homebrew Python3 instead
- Start the virtual env:
source venv/bin/activate
- Install mysql 5.5 (Google mysql 5.5. install; on Debian/Ubuntu, should need to use apt to install
mysql-client
,mysql-server
,libmysqlclient-dev
and its dependencies)
- You should get a config asking you to set a root password when installing
mysql-server
. Set this to something you'll remember.
- Install requirements
sudo pip3 install -r requirements.txt
- Ensure your mysql server is running
- Enter the shell with the command
mysql -u root -p
to login as root. Enter the password you made earlier. - Create the
upe
databse by running the commandCREATE DATABASE upe;
my - Also run
CREATE USER admin IDENTIFIED BY 'littlewhale';
. Then grant your user permissions:GRANT ALL PRIVILEGES ON upe.* TO 'admin';
- Type
\q
to quit the mysql server shell.
- Rename the template
settings.py.template
tosettings.py
. Never commit this! - Now you are ready to do
python3 manage.py syncdb
- If successful, Django should ask you to install superusers. Say yes, and use a one-character username/password for ease.
- Now you can run
python3 manage.py runserver
. This will be your go-to command when you develop. - Visit
localhost:8000
in your server. You should now see the UPE website locally! - Wrapping up: you can do Ctrl-C to stop the server, and then run
deactivate
in the terminal to stop the virtualenv.
You can load some of the old data into the database for testing purposes. Here's how
20. Get the database dump json file from your lovely committee chairs
21. Run the following command: python3 manage.py loaddata /path/to/json/file
and your data will be loaded!
- To change the password: follow the instructions here
- To change the username:
python3 manage.py runserver
, then go tolocalhost:8000/admin
>Users and modify the user.
- Make sure models are good to go:
python3 manage.py migrate
. (makemigrations
should be done locally and then committed to Git) - If any static files are changed, update them on the server:
python3 manage.py collectstatic
To make sure that the update script (update.sh
) runs, the owner of all the postfix-related files must be postfix
.
- e.g. if edits to
virtual
changes the owner, dochown postfix virtual
.