Skip to content

Self-hosting a repository

The UnderscoreEnchants repository is self-hostable for those who want to stem from the central one. It is built in Kotiln with Ktor. This guide is about hosting it with Docker. Standalone hosting is also possible, but unreasonable.

Getting started

To begin, clone the repository.

mkdir uebackend
cd uebackend
git clone https://github.com/RoughlyUnderscore/UEBackend.git

Deployment

This guide assumes that you know the basics of Dockerfile and Docker Compose and does not provide in-depth explanations for the files.

First create a fat jar using the command gradle builtFatJar. Navigate to build/libs and you will find a uebackend.jar.

Now you will need to create a Dockerfile to build an image of the jarfile. This is an example Dockerfile:

Dockerfile
FROM amazoncorretto:17
EXPOSE 10005
RUN mkdir /app
COPY ./uebackend.jar /app/server.jar
ENTRYPOINT ["java", "-jar", "/app/server.jar"]

The repository requires environmental variables for accessing the database. Create an .env file in advance to use in docker-compose.yml:

.env
DB_URL=mongo:27017
DB_LOGIN=login
DB_PWD=password
DB=underscoreenchants

Create a docker-compose.yml file to setup multiple services. This is how it can look:

docker-compose.yml
services:
  ue:
    build: ./ue
    restart: unless-stopped
    env_file: "ue/.env"
    ports:
      - 10005:10005
    depends_on:
      mongo:
        condition: service_healthy
    networks:
      - mongo-network

  mongo:
    image: mongo:8.0-rc-jammy
    restart: unless-stopped
    ports:
      - 27017:27017
    env_file: "mongo/.env"
    healthcheck:
      test: echo 'db.runCommand("ping").ok' | mongosh mongo:27017/admin --quiet
      interval: 10s
      timeout: 10s
      retries: 5
    volumes:
      - ./mongo/data:/data/db
      - ./mongo/init.js:/docker-entrypoint-initdb.d/init.js
    networks:
      - mongo-network

networks:
  mongo-network:
    driver: bridge

Additionally, setup the MongoDB with an initialization file and its own .env file:

.env
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=rootpassword
init.js
db.createUser({
    user: "login",
    pwd: "password",
    roles: [ "readWrite" ]
});

You should be all good to go. Run docker-compose up -d && docker-compose logs -f and verify that everything starts up correctly.