This repository is concerned with the backend of the web application GenPare. It is written in Kotlin using Ktor. It also uses a MariaDB instance.
- Docker
- Docker Compose
- A JDK
If you already have a backend image present, you need to remove it, or changes won't be applied.
docker-compose rm -vf
docker image rm genpare-backend_genpare-backend
Open a terminal in the project root and run the Gradle installDist
task.
# Windows
gradlew.bat installDist
# *nix
./gradlew installDist
This step will take quite some time, as Gradle will download all necessary libraries and compile the backend, so grab a coffee for this part.
Copy the contents of .env.example
to a new file called .env
. Then set a database name and password. It doesn't
matter what they are, even if the password is very unsecure, since it's going to be a local container. For the audience
and issuer use the Auth0 development credentials.
Now you can let Docker Compose do the rest for you.
docker-compose up
The first time you execute this command, Docker Compose will build the image. Every subsequent time, it will just start the containers without rebuilding them.
This section explains how to set up a local development environment.
- Clone the repo
- Open it in IDEA
- Check that you're using Java SDK 16
- Create a MariaDB database and user:
CREATE DATABASE `genpare`;
CREATE USER 'genpare' IDENTIFIED BY 'testing123';
GRANT USAGE ON *.* TO 'genpare'@localhost IDENTIFIED BY 'testing123';
GRANT ALL PRIVILEGES ON `genpare`.* TO 'genpare'@localhost;
FLUSH PRIVILEGES;
- Run the
run
Gradle task in theapplication
folder, or alternatively, run the Application.kt file
To run the backend from the source code, you need to have a few things installed.
- IntelliJ IDEA
- MariaDB (Please make sure the port is kept at
3306
, the default one!)
After opening IDEA, click on File
> New
> Project from Version Control...
In the resulting dialog, enter the Git URL of this repository (https://github.com/GenPare/genpare-backend.git) and a directory to clone the repo to.
Then, click Clone
. After this, IDEA will clone the repository. It will also ask you if you want to trust the
repository. You can always check the
build.gradle.kts file to check if you actually
want to trust the project. This is an important safety feature of IDEA, so please always make sure to preview unknown
projects in Safe Mode. If you do trust us, click Trust Project
. Else, click Preview in Safe Mode
. Do keep in mind
however that you will need to trust the project at some point to actually build it.
At this point, Gradle will automatically download all required dependencies and cache them locally, so they don't need
to be downloaded again. After the Gradle project was fully imported, please check your SDK version to ensure the built
files are built with Java 16. For this, go to File
> Project Structure...
> Project Settings
> Project
. Here,
the selected project SDK should be 16. Relevant is the number written in gray text to the right, not the identifier to
the left written in white text. If not, change the version to be 16.
If you don't have a Java 16 SDK, you can also download one from within IDEA.
Make sure you have installed MariaDB. Also, please make sure that the database is running on port 3306
.
Open the MariaDB console from the start menu. Then, run the following commands:
CREATE DATABASE `genpare`;
CREATE USER 'genpare' IDENTIFIED BY 'testing123';
GRANT USAGE ON *.* TO 'genpare'@localhost IDENTIFIED BY 'testing123';
GRANT ALL PRIVILEGES ON `genpare`.* TO 'genpare'@localhost;
FLUSH PRIVILEGES;
They create a new database called genpare
, a new user genpare
with the password testing123
, grant permissions to
this user for only the newly created database, and lastly flush these permissions for them to take effect immediately.
Before running the server, you need to set some environment variables. Do to so, you have to open the run configurations.
Then make sure, you have the correct configuration selected on the left-hand site.
Afterwards you have to add the variables to the Environment variables
field.
This is the place where you have to add the variables, which were given to you by the developers.
When you're done with all these steps, you can run the server application. You have two options:
- Click on the Gradle tab on the right-hand side and go to
genpare-backend
>Tasks
>application
. Here, you can just double-clickrun
.
- In the project view on the left-hand side, go to
genpare-backend
>src
>main
>kotlin
>de.genpare
>Application.kt
.
In the gutter, you'll see a green arrow. You can click it to run the application, too.