Skip to content

Self Hosting

Bodhi Mulders edited this page Apr 4, 2021 · 6 revisions

Here you will find instructions on how to host your own instance of ShiraKamiSRS.

ShiraKamiSRS is provided as a Docker image to run as a container. It requires access to a MariaDB instance. The instructions below will guide you through setting up both.

Prerequisites

The only requirement is that you have a machine with Docker and Docker Compose installed. If you plan on exposing your instance publicly, it might be useful to have a custom domain configured with DNS records pointing to your machine.

Setup

In this setup guide we will set up both ShiraKamiSRS and MariaDB using Docker and Docker Compose. While it certainly is not a requirement to use Docker Compose, or to run MariaDB as a Docker container, this is the route that will be taken here. In case you are looking for a setup different from this, you probably know what to do already.

Writing your compose file

Create a docker-compose.yml file and set it up as follows:

version: '3'

services:

  shirakamisrs:
    container_name: shirakamisrs
    image: ghcr.io/bemacized/shirakami-srs:latest
    restart: unless-stopped
    ports:
      - <WEB_PORT>:3000
    environment:
      - MYSQL_HOST=mariadb
      - MYSQL_PASSWORD=<YOUR_DB_PASSWORD>
      - JWT_SECRET=<RANDOM_SECRET>

  mariadb:
    container_name: mariadb
    image: mariadb
    restart: unless-stopped
    volumes:
      - ./mariadb/data:/var/lib/mysql
    environment:
      - MYSQL_DATABASE=shirakami
      - MYSQL_USER=shirakami
      - MYSQL_PASSWORD=<YOUR_DB_PASSWORD>

Make sure to:

  • Replace the two <YOUR_DB_PASSWORD> cases with a sufficiently safe password to protect your database
  • Replace <RANDOM_SECRET> with your own random string. This is used for signing authentication tokens and should be unique to your instance.
  • Replace <WEB_PORT> with the port you want to expose ShiraKamiSRS on. If you don't know, use 80.

There are many more configuration options for ShiraKamiSRS. Find out on the Image Configuration page what they are and what they do.

Starting ShiraKamiSRS

You can now start ShiraKamiSRS by running the following command in the directory where you saved your docker-compose.yml:

docker-compose up

or as follows if you want to run it in detached mode:

docker-compose up -d

You can now visit your ShiraKamiSRS instance at http://<your_machine_ip>:<web_port>.

Custom domain and HTTPS

In case you are planning on running your ShiraKamiSRS instance publicly, it might be a good idea to:

  • Set up a custom domain (for ease of use)
  • Enable HTTPS/SSL for security

Setting up HTTPS is especially important for public instances, as it makes sure your users credentials are not sent in plaintext.

As ShiraKamiSRS does not support HTTPS out of the box, you are expected to use a reverse proxy. Below will be described how to set this up using Caddy as your reverse proxy, which will automatically set up a SSL certificate for you using Lets Encrypt.

We will assume you have already pointed your custom domain at your machine. You can do this by adding a DNS "A" record pointing towards your public IP. This guide will not go over how to do this.

  1. First, start off by removing the exposed port on your ShiraKamiSRS instance. You can do this by removing the following two lines from your docker-compose.yml:

    ports:
      - <WEB_PORT>:3000
  2. Add the following service at the bottom of your docker-compose.yml:

    caddy:
      container_name: caddy
      image: caddy:2.3.0-alpine
      restart: unless-stopped
      ports:
        - 80:80
        - 443:443
      volumes:
        - ./caddy/data:/data
        - ./caddy/config:/config
        - ./caddy/Caddyfile:/etc/caddy/Caddyfile
  3. Create a Caddyfile at ./caddy/Caddyfile relative to your docker-compose.yml:

    yourcustomdomain.com {
      reverse_proxy shirakamisrs:3000
    }
    

    Replace yourcustomdomain.com with the custom domain you pointed towards your machine. In case you changed the service name for your ShiraKamiSRS container in your docker-compose.yml, make sure to update shirakamisrs in your Caddyfile to be identical to this one, as it functions as the hostname of your container.

  4. Run docker-compose up or docker-compose up -d to update ShiraKamiSRS and launch Caddy.

ShiraKamiSRS should now be running on your custom domain. It might take a few minutes for Caddy to provision your Lets Encrypt certificate.

What's next?

The best idea would be to look through the configurable options on the Image Configuration page, as there are a few optional features you might want to configure next.

A few examples could be: