Skip to content

GenPare/genpare-backend

Repository files navigation

GenPare: Backend

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.

Running with Docker Compose

Prerequisites:

Building the image

Step 0: Remove an existing image

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

Step 1: Build the necessary files

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.

Step 2: Set environment variables

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.

Step 3: Build the image and run the container

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.

Setting up a development environment

This section explains how to set up a local development environment.

TL;DR:

  • 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 the application folder, or alternatively, run the Application.kt file

More infos, please.

Dependencies

To run the backend from the source code, you need to have a few things installed.

  1. IntelliJ IDEA
  2. MariaDB (Please make sure the port is kept at 3306, the default one!)

Downloading the source code

After opening IDEA, click on File > New > Project from Version Control...

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.

Enter the Git URL

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.

Trust the Gradle project

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.

Check your Java SDK level to be 16!

If you don't have a Java 16 SDK, you can also download one from within IDEA.

Download a Java 16 SDK, if required.

Setting up the database

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.

Setting environment variables

Before running the server, you need to set some environment variables. Do to so, you have to open the run configurations.

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.

Add the environment variables.

This is the place where you have to add the variables, which were given to you by the developers.

Running the server

When you're done with all these steps, you can run the server application. You have two options:

  1. Click on the Gradle tab on the right-hand side and go to genpare-backend > Tasks > application. Here, you can just double-click run.

Run the "run" Gradle task.

  1. In the project view on the left-hand side, go to genpare-backend > src > main > kotlin > de.genpare > Application.kt.

Open the Application.kt file.

In the gutter, you'll see a green arrow. You can click it to run the application, too.

Click the green arrow.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages