We recommend using two separate virtual environments for development and production. Below is how you set up your dev venv, but you can replace credentials with your production credentials to create a production venv.
python3 -m venv dev.venv
source dev.venv/bin/activate
pip install -r requirements.txt
Add env variables to dev.venv/bin/activate
export DJANGO_DEBUG=True
export DB_HOST=db
export DB_NAME=postgres
export DB_PORT=5432
export DB_USER=root
export DB_PASSWORD=password
Create a docker network to use while testing locally with docker-compose
docker network create swecc-default
task | command |
---|---|
run server locally (requires prod.venv) | python server/manage.py runserver |
run server in docker (requires dev.venv) | docker compose up --build |
curl -X PUT -H "Authorization: Api-Key $VERIFICATION_KEY" -H "Content-Type: application/json" -d '{"username": "elimelt", "discord_username": "elimelt", "discord_id": 1234}' http://localhost:8000/members/verify-discord/
- Start the application
docker compose -f docker-compose.local.yml up --build
- Run the migrations
docker exec -it swecc-server-web-1 python server/manage.py migrate
-
Create a regular user on the frontend
-
Create a superuser
docker exec -it swecc-server-web-1 python server/manage.py createsuperuser
-
Access the admin panel at
http://localhost:8000/admin/
, and login with the superuser credentials you created. -
In the admin panel, create a new API key. Doesn't matter what you name it, but make sure to copy the key somewhere safe. I recommend putting it in your
dev.venv/bin/activate
file, e.g.export VERIFICATION_KEY=your_key_here
. -
Verify your discord account, using the API key you just created, and the non-superuser credentials you created in step 3.
curl -X PUT \
-H "Authorization: Api-Key <VERIFICATION_KEY>" \
-H "Content-Type: application/json" \
-d '{"username": <YOUR_USER>, "discord_username": <YOUR_DISCORD>, "discord_id": <SOME_INT>}' \
http://localhost:8000/members/verify-discord/
- Windows
Warning: Before running the script make sure to setup dev env first and migrate the db.
- Run
script/userCreate.bat <username>
to create a new verified user. Default password for each created user when using the script is123456
. - Run
script/makeAdmin.bat <username>
to make an existing user admin - Run
script/populateUser.bat <num users>
to add<num user>
verfied users dev db.
- Unix
- To be developed
Everything is run in EC2. A common problem seems to be running out of space, probably because of our log files. If you're ever in what seems to be an unrecoverable state (e.g. can't remove or clean because writes fail due to no more space), try this:
After sshing in, kill all docker
sudo systemctl stop docker
sudo rm -rf /var/lib/docker
Then, reboot
sudo reboot
Cleanup
sudo apt autoclean
Restart docker
sudo systemctl start docker
sudo docker network create swag-network
pushd ~/swag; docker-compose up -d; popd
Finally, restart containers by triggering a deploy.
Just ssh and remove the current actions-runner
directory and follow these docs to add a new actions runner, which should pick up the job shortly after. You should start the runner as a service
sudo ./svc.sh install
sudo ./svc.sh start
If you see this in the logs
You're accessing the development server over HTTPS, but it only supports HTTP.
and in network tab you get status (failed)net::ERR_CONNECTION_REFUSED
, you might need to start the swag container.
cd ~/swag; docker-compose up -d