Skip to content

lr101/MonaServer

Repository files navigation

Mona Server

Docker Publish contributions welcome Discord Play Store App Store

What is it for?

This spring boot application is the communicating backend server for the app Stick-It Map which can be found in the following repo. The app allows sharing stickers in groups by geotagging images.

TechStack

The packend server is written in kotlin using spring boot.

It uses a postgres (with postgis extension for localization of different boundaries up to administrative 2 zones) database as its storage medium and implements refresh and jwt-auth tokens for login and authentication purposes. The openapi definition can be found in this repo or when starting the server under /public/swagger-ui/index.html Using GitHub actions a docker image is always available at Docker Hub here.

For image storage a minio bucket is used. Everything can be hosted locally and set up with this repo.

For logging the application logs are written to a logback file and metric data is optionally published into influxdb which can be displayed using grafana.

All services are supposed to be running in docker containers using the provided docker compose file.

How to run

Production setup in docker

  1. Clone the repo (or copy docker-compose.yml file and init/ folder)
  2. Create a .env file in the root of the project:
POSTGRES_USER=postgres
POSTGRES_PASSWORD=root
POSTGRES_DB=sticker
PORT=8081
ADMIN_ACCOUNT_NAME=admin
DB_URL=jdbc:postgresql://db:5432/sticker
MAIL_PASSWORD=<YOUR MAIL PASSWORD>
MAIL_USERNAME=<YOUR MAIL USERNAME>
MAIL_HOST=<YOUR EMAIL SERVER HOST>
MAIL_PORT=<YOUR EMAIL SERVER PORT>
MAIL_FROM=<YOUR EMAIL> # when setting --Stick-It Map <YOUR EMAIL>-- the name will be shown
MAIL_BATCH_SIZE=25 # number of emails to send in the MAIL_BATCH_DURATION timeframe
MAIL_BATCH_DURATION=60 # in minutes
MAIL_PROTOCOL=smtp
APP_URL=<YOUR_PUBLIC_FACING_DOMAIN> # Set to public facing api domain
MINIO_ACCESS_KEY=<MINIO_ACCESS_KEY>
MINIO_SECRET_KEY=<MINIO_SECRET_KEY>
MINIO_ENDPOINT=https://minio.example.com # Set to public facing minio domain
MINIO_BUCKET=<MINIO_BUCKET_NAME>
MINIO_ROOT_USER: admin
MINIO_ROOT_PASSWORD: <MINIO_CONSOLE_ADMIN_PASSWORD>
MINIO_PORT=9000
MINIO_CONSOLE_PORT=9001
  1. Add your mail login data, public facing app url and minio information
    • You might need to start the minio container to create your access key through the admin console: docker compose up minio
    • Navigate to the minio console at http://localhost:9001 and login using the specified MINIO_ROOT_PASSWORD
    • Create a bucket with the same name as the MINIO_BUCKET_NAME
    • Create an access token and add it to your .env
  2. Run docker-compose up to start all services

Optional

  1. Add influx for monitoring by setting the following values in your .env:
    INFLUX_ENABLED=true
    INFLUX_TOKEN=
    INFLUX_BUCKET=
    INFLUX_ORG=
    INFLUX_URL=
    
  2. Add the following achievement thresholds in your .env:
    ACHIEVEMENT_MONA_GROUP_ID=<UUID>
    ACHIEVEMENT_CREATED_BEFORE<DATE> # in format ex: 2023-12-10T02:43:44.402768+00:00
    

Development setup (in IntelliJ)

  1. Clone the repo
  2. Open the project with IntelliJ
  3. Set the SDK Version to 17 in the Project Structure setting
  4. Create a .env file in the root of the project:
DB_URL=jdbc:postgresql://localhost:5432/sticker
APP_URL=http://localhost:8080 # Set to public facing domain
MINIO_ENDPOINT=http://localhost:9000 # Set to public facing minio domain
  1. Create a database in an already running instance or start the db in the docker-compose file
  2. Run the server via the main method

FAQ

  1. How do I use my gmail address when using TFA? - See this link for how to generate an app password
  2. What gmail smtp server protocol should I use? - See this Google developer page for mail protocol information*
  3. How do I back up the database? docker exec -it <DB DOCKER ID> /bin/bash -c 'pg_dump -U postgres -Fc mona > /backup/db.dump'
  4. How do I restore a database? docker exec -it <DB DOCKER ID> /bin/bash -c 'pg_restore -d sticker /backup/db.dump
  5. Run spacial data import:
docker exec -it <CONTAINER_ID> ogr2ogr -f "PostgreSQL" PG:"host=localhost user=postgres dbname=geospatial_db password=your_password"     -nln states_provinces -append -t_srs "EPSG:4326"     /docker-entrypoint-initdb.d/world_admin2.geojson

About

Spring Boot backend for the Stick-It App

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •