This repository contains the repository of the supremum.gewis.nl website.
In this README, we treat the following subjects in order:
- The application stack.
- The repository structure.
- Development basics.
- Deployment basics.
- Administration details.
For our stack, we use three key technologies.
- Docker.
Docker
is what 'contains' our application. It provides a convenient way for us to develop the website we want, upload it and host it at the GEWIS server, without the CBC having to worry about our implementation details. In our docker container, we run two applications. - Flask:
Flask
is the framework with which we have created out website. It contains a built in (development) server, which we also (ab)use for hosting the website in the docker container. - Nginx:
Nginx
acts as the "glue" between the outside worlds and ourFlask
application. It takes the requests from the 'outside world' (i.e. people requesting our page on the internet) and either forwards the request to the Flask application, or handles it by itself. Shortly stated, it handles static requests (large files, .css files) itself, and let's the Flask application deal with the HTML.
The website is contained in the app
folder and consists of four modules:
- home. The
home
module contains the majority of the website: essentially everything any (non-administrator) user interacts with. - admin. The
admin
module contains the administration pages and accompanying files. - auth. As the name suggests, the
auth
(orization) module is responsible for logging people in and out from the application. - api. Lastly, our website provides a (small)
api
through which other webpages can access content that our website provides. The primary example here are the random infima that are displayed on all other pages of the GEWIS website; these are (indirectly) requested from our website.
Have a look at the __init.py__
file in the app
folder to see how the modules
have been configured.
Most modules consist of the following folders/files:
__init__.py
. InFlask
, these modules are calledBlueprint
s. In theinit.py
file, these blueprints are defined.routes.py
. This files specifies the routes (urls) that can be requested by a user and performs the steps necessary to provide the page to the user.models.py
. This file specifies the database objects that are used to retrieve the right data from the right location./static
. The static folder contains, as the name suggests, the static files of the module. These are mostly.css
files and images, but any (future).js
files should also be placed here./templates
. The templates folder contains thehtml
templates that are filled in by the flask application (<- server side rendered) and subsequently provided to the user.
For more details on how to work with Flask, you are encouraged to look for the official documentation or a tutorial.
In order to run the repository locally, perform the following steps.
- Clone the repository.
- Open the repository via the command line and setup a virtual environment.
- [Linux] Execute
setup.sh
- [Windows] Execute
setup.bat
- Activate the virtual environment.
- [Linux] Execute
source venv/bin/activate
- [Windows] Execute
cd venv/Scripts
followed byactivate.bat
- Activate the development server.
- [Linux] Execute
python3 serve.py
- [Windows] Execute
cd ../../
followed bypython serve.py
At this moment, you should be able to edit away to your hearts content. For most files
(with the exception of the .env
and config.py
files) holds that if you save them
after editing, the development server will automatically restart, which means that a
simple reload of the page will provide you with your update in place. Please note,
this does not apply for .css
files: for these you will have to perform a force reload:
ctrl + shift + r
. Happy editing!
There is some information that we need to run your application that we DONT
want to end up in the GIT repository. Think of api-keys, database username/password
and the likes. To still be able to use there values, we make use of environment variables.
We store these in the .env
file at the root of the repository. As you can see, this file
is absent by default. However, we do provide an .env.example
file, which you should copy and save as .env
file. After this, you can fill in your database credentials / other
secrets to your hearts content and these variables are automatically read when the
application is run. To see how/which variables are processed, see the config.py
file.
Note: by default, you have to restart the development server before any changes to the
.env
file take effect.
As mentioned, we use Docker
to contain our application and deploy it on the
GEWIS server.
At the time of writing, CBC provides the supremum with two stacks:
- supremum_live which provides the
supremum.gewis.nl
website. - supremumtest which provides the
supremum.test.gewis.nl
website.
You can access the configuration of these containers over on docker.gewis.nl
.
If you cannot login, or do not have access to the stacks, you should get in contact
with the CBC to get this sorted.
Let's quickly discuss how to get the changed repository on the GEWIS server.
- Make sure all the files in your local repository are the way that you want
them to end up in the server image.
Although the
Dockerfile
specifies how the docker image is created from your local files, it does so based on the current files in your directory, not the last committed version. Note: if you know of a better method to approach this, feel free to rewrite the documentation on this. - Set the correct port in the
extra_nginx.conf
file. If you are creating a version for the test-server, set it to9500
; for the live server set it to9501
. WARNING: This is super important, otherwise the server won't operate properly. Note: feel free to change the docker install to circumvent this issue. - Create the image.
- [Linux]:
sudo docker build . -t supremum.docker-registry.gewis.nl/site:v{tag}
, where you replace{tag}
with the version number of your image. - [Windows]: the command above can de executed as long as you have Docker Desktop installed, running on WSL
- Push the image to the GEWIS server.
- [Linux]:
sudo docker push supremum.docker-registry.gewis.nl/site:v{tag}
- [Windows]: the command above can de executed as long as you have Docker Desktop installed, running on WSL
It might be that (during the first time) you are asked for your credentials in order to push
to the GEWIS server. We advise you to have a look at the Docker documentation on this
process and login with your docker.gewis.nl
credentials.
To start using the image on the server, head on over to docker.gewis.nl
and open the
appropriate stack in the stacks
overview. Once there, open the editor
tab and
under flask -> image
change the version number to the appropriate version.
Hereafter, push the update the stack
button and within a couple seconds your new
version is live.
WARNING: at the time of writing, the database used by the test server and the live
server are identical. If you wish to test something related to the database,
head over to mysql.gewis.nl
and create a new database to test on.
The Supremum website stores quite some data. The most notable being
- Infima
- Supremum pdfs.
As these are very asimilar, we employ two different methods to store these.
- Persistent volume. We store the Supremum pdfs as files in a persistent volume
on the docker.gewis server. It is not really possible to directly access this
volume via
docker.gewis.nl
. Instead, you can only update these files via the administration panel on the website itself. - Database. The database contains the infima and the paths to where the suprema
are stored in the persistent volume. The interface for the database is accessible via
mysql.gewis.nl
. You should be able to log in with the same credentials as those fordocker.gewis.nl
. If you don't have credentials or do not have access to the databases, get in contact with CBC.
Below, we provide some basic information on some administrational tasks that one might wish to perform.
Sadly, this is not yet possible on the supremum.gewis.nl
website itself.
Instead, we have to change a value in the database to make someone an admin (or not).
- Head over to
mysql.gewis.nl
and log in. - Open the
supremum_website
database. - Edit/add the entry with the desired GEWIS-id and set them to admin (1) or not (0).