Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,3 @@ cafesys/collected-static

# We don't need to copy this folder as its only purpose is deploying to production
kubernetes/
database/

docker-compose.yaml
Dockerfile
Procfile
README.md
Vagrantfile
.gitignore
.dockerignore
cafesys/baljan/static
7 changes: 2 additions & 5 deletions .env.docker.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
# Used by cafesys
AUTH_LIU_CLIENT_ID=ddb3968d-5305-4249-975a-cb5cedc4583c
AUTH_LIU_RESOURCE=https://www.baljan.org

DJANGO_DEBUG=True
DJANGO_EMAIL_URL=consolemail://
DJANGO_REDIS_URL=redis://redis:6379/0
DJANGO_DATABASE_URL=postgres://cafesys:cafesys@postgres:5432/baljan_local
DJANGO_DATABASE_URL=postgres://cafesys:cafesys@postgres:5432/cafesys
DJANGO_SECRET_KEY=unsafe-dev-key-must-be-changed-for-production
DJANGO_SETTINGS_MODULE=cafesys.settings.development

GUNICORN_LOG_LEVEL=debug
GUNICORN_RELOAD=True
GUNICORN_WORKERS=2

# Used by postgres
POSTGRES_DB=baljan_local
POSTGRES_DB=cafesys
POSTGRES_USER=cafesys
POSTGRES_PASSWORD=cafesys
12 changes: 1 addition & 11 deletions .env.tmpl
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
# This is the default environment used by cafesys when developing locally.
# Get started by copying this to .env

# Used by cafesys
AUTH_LIU_CLIENT_ID=ddb3968d-5305-4249-975a-cb5cedc4583c
AUTH_LIU_RESOURCE=https://www.baljan.org

DJANGO_DATABASE_URL=postgres://cafesys:cafesys@localhost:5432/cafesys
DJANGO_DEBUG=True
DJANGO_EMAIL_URL=consolemail://
DJANGO_REDIS_URL=redis://localhost:6379/0
DJANGO_DATABASE_URL=postgres://cafesys:cafesys@localhost:5432/baljan_local
DJANGO_SECRET_KEY=unsafe-dev-key-must-be-changed-for-production
DJANGO_SETTINGS_MODULE=cafesys.settings.development

GUNICORN_LOG_LEVEL=debug
GUNICORN_RELOAD=True
GUNICORN_WORKERS=2

# Used by postgres
POSTGRES_DB=baljan_local
POSTGRES_USER=cafesys
POSTGRES_PASSWORD=cafesys
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ vagrant-*
/kubernetes/.env

# Node
node_modules

latest.dump
node_modules
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ ARG DJANGO_SECRET_KEY=build
RUN mkdir ${APP_ROOT}
WORKDIR ${APP_ROOT}


RUN pip3 install -U pip setuptools

COPY ./requirements.txt ${APP_ROOT}/requirements.txt
RUN pip3 install --ignore-installed -r ${APP_ROOT}/requirements.txt

COPY ./bin ./bin
COPY ./cafesys ./cafesys
COPY ./gunicorn-conf.py ./gunicorn-conf.py
COPY ./manage.py ./manage.py

EXPOSE 8000
COPY . ${APP_ROOT}

RUN django-admin collectstatic --noinput

EXPOSE 80
# It seems there's no way to do variable substitution here.
CMD ["/app/bin/run-django"]
16 changes: 0 additions & 16 deletions Makefile

This file was deleted.

5 changes: 3 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
web: gunicorn -c gunicorn-conf.py cafesys.wsgi --preload
web: gunicorn cafesys.wsgi --preload

worker: celery -A cafesys worker --beat -l info

worker: celery -A cafesys worker --beat -l info
193 changes: 166 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,194 @@
Cafesys is the Django application driving the website of Sektionscafé Baljan. It features staff management and the
fantastic *Blipp* system for coffee.

## Setting up a development environment using Docker
## Setting up a development environment using heroku local
If you are using windows as OS start by downloading WSL.

> **Note:** This guide requires that you have installed Docker and Docker Compose (see https://docs.docker.com/compose/install/).
Start by ensuring that all necesary requirements are satisfied by navigating to the project directory and running:
pip install -r requirements.txt

If you are using Windows as OS, start by downloading WSL.

Install the Heroku client:
``` sh
# WSL/Linux:
Install the heroku client:
WSL/Linux:
curl https://cli-assets.heroku.com/install.sh | bash

# macOS:
or
sudo snap install --classic heroku
macOS:
brew tap heroku/brew && brew install heroku

login to heroku through the termnial by running:
heroku login

Create a backup of the postgressql database by running:
heroku pg:backups:capture --app baljan

Download a dump of the database to the current directory:
heroku pg:backups:download --app baljan

Enable postgressql:
sudo systemctl enable postgresql

Start postgressql command-line tool, and run the following lines. The parameters myuser, mypassword and baljan_local can be changed to any arbitrary string but make sure to remember them if changed:
sudo -u postgres psql

CREATE DATABASE baljan_local;

CREATE USER myuser WITH PASSWORD 'mypassword';

ALTER ROLE myuser SET client_encoding TO 'utf8';
ALTER ROLE myuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE myuser SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE baljan_local TO myuser;

Exit the command-line tool for postgressql:
\q

Populate the newly created database, baljan_local in this case, with the dump file containing the database. Your dumpfile might have another name:
pg_restore --verbose --no-acl --no-owner -h localhost -U myuser -d baljan_local latest.dump

If you changed the parameters myuser, mypassword or baljan_local, then go to the .env file in the project directory and change the following lines to match your parameters:
DJANGO_DATABASE_URL=postgres://myuser:mypassword@localhost:5432/baljan_local

The setup is now complete, each time you wish to start the environment run the following:
for WSL2/Linux:
sudo service redis-server start
sudo service postgresql start
heroku local

for macOS:
brew services start redis
brew services start postgresql
heroku local



## Setting up a development environment in Docker
Install node.js
```sh
npm install
```
This assumes you already have Docker and Docker Compose installed.
```sh
cp .env.docker.tmpl .env.docker
docker-compose up
```

If your machine has `make` available, you can run:
The first time, run in another shell session:
```sh
make setup
docker-compose run --rm cafesys-django ./manage.py migrate
docker-compose run --rm cafesys-django ./manage.py collectstatic --noinput
docker-compose run --rm cafesys-django ./manage.py createsuperuser
docker-compose run --rm cafesys-django ./manage.py shell
```

Otherwise, follow the steps below:
In the Python shell, run
```python
from django.contrib.sites.models import Site
Site.objects.create()
```

1. Login to heroku through the terminal by running:
When making changes to the code, you might need to rebuild the environment:
```sh
heroku login
docker-compose build
docker-compose run --rm cafesys-django django-admin.py collectstatic --noinput
```

2. Create a backup of the PostgreSQL database by running:
This environment will use the `.env.docker` file for environment variables, **not** `.env`.

## Setting up a local development environment
### macOS
**Note: This guide requires that you have installed Docker and Docker Compose (see https://docs.docker.com/compose/install/).**

This assumes you already have Homebrew installed and have basic knowledge on Python and its virtual environments.

Install system dependencies:
```sh
heroku pg:backups:capture --app baljan
brew tap homebrew/science
brew install python3 postgresql glpk
```
*FIXME:* the list of Homebrew packages is probably incomplete.

Create a virtualenv with a Python 3 interpreter and activate it:
```sh
# Install virtualenv if not already installed
pip install virtualenv

# Setup and activate virtualenv
virtualenv -p python3 .venv
source .venv/bin/activate
```

Then install the needed Python dependencies:
```sh
pip install -r requirements.txt
```

Start the `postgres` and `redis` services with Docker:
```sh
cp .env.docker.tmpl .env.docker
docker-compose up -d postgres redis
```

The first time, run in another shell session:
```sh
cp .env.tmpl .env
./manage.py migrate
```

Start the Django development server and Celery daemons. You will need to open at least three shell sessions.
Make sure to activate the virtualenv with `source .venv/bin/activate` in every new shell session.
```sh
./manage.py runserver
celery -A cafesys beat
celery -A cafesys worker

```

This environment will use the `.env` file for environment variables, **not** `.env.docker`.

### Ubuntu 16.04
**Note: This guide requires that you have installed Docker and Docker Compose (see https://docs.docker.com/compose/install/).**

This might work for other versions of Ubuntu but has only been tested on Ubuntu 16.04.

Start by installing all dependencies. This can be done in a terminal by running the following commands:
```sh
add-apt-repository ppa:jonathonf/python-3.6
apt-get update
apt-get install python3.6 python3.6-dev python3-pip libpq-dev build-essential libssl-dev g++ libffi-dev python3-dev pypy glpk-utils
pip3 install virtualenv
```

3. Download a dump of the database to the current directory:
The following steps are quite similar to the installation procedure on MacOS but differs slightly. First we setup the virtual environment: run the following command in a terminal at the repository root:
```sh
heroku pg:backups:download --app baljan -o docker-entrypoint-initdb.d/latest.dump
virtualenv -p python3.6 .venv
source .venv/bin/activate
```

4. Copy `.env.docker.tmpl` to `.env.docker`
Next, you should be able to follow the MacOS guide from the step "Then install the needed Python dependencies:".

### Vagrant (mainly for development on Windows)
Start by downloading and installing Vagrant from https://www.vagrantup.com/.

5. Create a superuser for the admin
Open a terminal in the root of the git repository and run `vagrant up`. This process may take a while, but please be patient.

Now you have a virtual machine setup for the entire Baljan stack. This stack can be accessed using a wrapper
around `manage.py` named `vmanage.py`. This means that the normal commands has been replaced with the wrapped
version. As a consequence of the wrapper implementation, it introduces some delay before every command is executed.

Migrate the database by running manage.py locally:
```sh
docker compose run --rm django ./manage.py createsuperuser
python vmanage.py migrate
```

Then you're ready to go!
Start the server on the interface `0.0.0.0` by running:
```sh
python vmanage.py runserver 0.0.0.0:8000
```

## Livereload

When doing work on the frontend it can be handy to see your changes in real-time. This can be achieved by using a tool called "Livereload". To activate this when developing, run this command instead of runserver (make sure to have sourced the virtualenv):

To start the project, run:
```sh
make start
# or
docker compose up --build -d django celery-worker
```
./manage.py livereload
```
29 changes: 29 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: '127.0.0.1'

config.vm.provision "docker" do |d|
d.run "postgres", args: "-p 5432:5432 --env-file /vagrant/.env.docker.tmpl"
d.run "redis", args: "-p 6379:6379 --env-file /vagrant/.env.docker.tmpl"
end

config.vm.provision "shell", inline: <<-SHELL
add-apt-repository -y ppa:jonathonf/python-3.6
apt-get update
apt-get install -y python3.6 python3.6-dev python3-pip libpq-dev build-essential libssl-dev g++ libffi-dev python3-dev pypy glpk-utils
pip3 install virtualenv
cd /vagrant
cp -n .env.tmpl .env
mkdir /venv
chmod 777 /venv
virtualenv -p python3.6 /venv --always-copy
SHELL

config.vm.provision "shell", run: 'always', inline: <<-SHELL
cd /vagrant
source /venv/bin/activate
pip3 install -r requirements.txt
SHELL
end
4 changes: 2 additions & 2 deletions bin/run-django
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
gunicorn -c gunicorn-conf.py cafesys.wsgi
web: gunicorn cafesys.wsgi -c ${APP_ROOT}/gunicorn-conf.py

Binary file added cafesys/baljan/static/img/styrelsen/Albin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Albin.webp
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Astrid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Astrid.webp
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Bogos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Bogos.webp
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Emma.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Emma.webp
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Filippa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Filippa.webp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Gustav.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Gustav.webp
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Helles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Helles.webp
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Henry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Henry.webp
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Inge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Inge.webp
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Isac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Isac.webp
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Josie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Josie.webp
Binary file not shown.
Binary file added cafesys/baljan/static/img/styrelsen/Judit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cafesys/baljan/static/img/styrelsen/Judit.webp
Diff not rendered.
Binary file added cafesys/baljan/static/img/styrelsen/Line.png
Binary file removed cafesys/baljan/static/img/styrelsen/Line.webp
Diff not rendered.
Binary file added cafesys/baljan/static/img/styrelsen/Louise.png
Binary file removed cafesys/baljan/static/img/styrelsen/Louise.webp
Diff not rendered.
Binary file added cafesys/baljan/static/img/styrelsen/Love.png
Binary file removed cafesys/baljan/static/img/styrelsen/Love.webp
Diff not rendered.
Binary file added cafesys/baljan/static/img/styrelsen/Matea.png
Binary file removed cafesys/baljan/static/img/styrelsen/Matea.webp
Diff not rendered.
Binary file added cafesys/baljan/static/img/styrelsen/Molly.png
Binary file removed cafesys/baljan/static/img/styrelsen/Molly.webp
Diff not rendered.
Binary file added cafesys/baljan/static/img/styrelsen/Obbe.png
Binary file removed cafesys/baljan/static/img/styrelsen/Obbe.webp
Diff not rendered.
Binary file added cafesys/baljan/static/img/styrelsen/Ogge.png
Binary file removed cafesys/baljan/static/img/styrelsen/Ogge.webp
Diff not rendered.
Binary file added cafesys/baljan/static/img/styrelsen/Shakeer.png
Binary file removed cafesys/baljan/static/img/styrelsen/Shakeer.webp
Diff not rendered.
Binary file added cafesys/baljan/static/img/styrelsen/Viktor.png
Binary file removed cafesys/baljan/static/img/styrelsen/Viktor.webp
Diff not rendered.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[ZoneTransfer]
ZoneId=3
HostUrl=https://drive.usercontent.google.com/download?id=13K4_4WqcMCuaLE1HxJMGdzWud6zmxZEQ&export=download&authuser=0&confirm=t&uuid=7ae72402-9b30-430c-985a-cac1bf27ad55&at=APZUnTWosswl0K9XlMOax8HOgj5v:1713778117341
Diff not rendered.
Diff not rendered.
Loading