-
Notifications
You must be signed in to change notification settings - Fork 1
Setting up backend
Add the following to the end of your ~/.bashrc file. Fill out the variables with the ones that you would like to use.
In production, OSOC_GMAIL_ADDRESS
should be set to a gmail address owned by OSOC and OSOC_GMAIL_APP_PASSWORD
should contain the app password of that gmail account. How to get an app password is explained in the following help page: App Passwords.
In development you can use your own gmail address here.
export OSOC_DB_USERNAME=<your-db-username>
export OSOC_DB_PASSWORD=<your-db-password>
export OSOC_DB_DBNAME=<your-db-name>
export OSOC_DB_URL="jdbc:postgresql://localhost:5432/$OSOC_DB_DBNAME"
export OSOC_SCHEME=https
export OSOC_FRONTEND_URL=https://sel2-1.ugent.be
export OSOC_GMAIL_ADDRESS=<gmail-address>
export OSOC_GMAIL_APP_PASSWORD=<app-password>
Note: After adding the variables to the ~/.bashrc file, you should either restart your terminal or run the following
source ~/.bashrc
To run the database used for the backend, you can use either a docker container or just run postgres locally.
If you want to run the postgres database locally, please go directly to the postgres setup.
Before starting, please make sure docker is installed on your device.
Note: It doesn't matter whether you do this in a windows command prompt or a linux terminal as long as the docker is running on port 5432 on your device. This is helpful if you are using WSL 1 so you don't have to upgrade to WSL 2 just so you can link docker to your WSL. If you are running this in command prompt, make sure you remove the sudo before running it.
First head into the docker directory. Then we want to build a docker image based upon our Dockerfile.
sudo docker build -t osoc_postgres_image:latest .
After that, we want to run the docker image in a container with the login properties and expose port 5432.
We want to create a volume that connects /var/lib/postgresql/data:/var/lib/postgresql/data
so that the data doesn't get lost when the docker gets deleted.
sudo docker run -d \
--name osoc_postgres_container \
-p 5432:5432 \
-v /var/lib/postgresql/data:/var/lib/postgresql/data \
-e POSTGRES_USER=$OSOC_DB_USERNAME \
-e POSTGRES_PASSWORD=$OSOC_DB_PASSWORD \
-e POSTGRES_DB=$OSOC_DB_DBNAME \
osoc_postgres_image:latest
Note: restarting your device will stop the docker image but will not delete the container. To start the container again, you have to run
sudo docker container start osoc_postgres_container
Please make sure postgres is installed on your device.
We want to create a database with the correct login properties in the postgres application.
sudo -u postgres psql -c "CREATE DATABASE $OSOC_DB_DBNAME;"
sudo -u postgres psql -c "CREATE USER $OSOC_DB_USERNAME WITH ENCRYPTED PASSWORD $OSOC_DB_PASSWORD;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $OSOC_DB_DBNAME TO $OSOC_DB_USERNAME;"
Please make sure openJDK 17 is installed on your device.
Navigate to the backend directory. Then we want to compile and run the backend project.
./mvnw spring-boot:run
Please make sure Maven 3.8.4 is installed on your device.
Navigate to the backend directory. Then we want to build the backend project using Maven.
mvn -B package --file pom.xml
After that, run the jar file
sudo -E java -jar {repo_dir}/backend/target/backend-0.0.1-SNAPSHOT.jar &
The backend should now be available on
http://localhost:8080/api/