This the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Deploy

Learn how to use it in production

Choose from an option and deploy

Options

You can either deploy it using Docker or you do it by hand. As you may already have built the project following the getting started instructions you can also do it by hand.

Example Environment

The two described options docker and manual will be using an example environment you can relate to.

The environment will be described in this section.

Consider a root server running Debian hosted by a provider online. You have root access to it via ssh and you have a domain pointing towards the public IP of this root server. Let’s assume the domain you own is dascr.org.

❯ host dascr.org
dascr.org has address 45.142.179.121

patrick@ssh-dascr-org ❯ pwd
/home/patrick/projects/dascr-board

You already at least have the prerequirements setup and cloned the code to disk on this root server.

Now you might wanna look at one or both of the deployment options then.

1 - Docker Deployment

How to use docker do deploy it

Instead of building everything by hand like described in the getting started guide you can also use docker.

Locally

There are two Dockerfiles, one in the root of the directory and one in the frontend directory. Those will build two independant docker images you can run like this:

docker build . -t dascr-board-backend
docker build ./frontend -t dascr-board-frontend

Running it

When running you need to be sure to let them run in the same network and to expose the corresponding ports (5000 - frontend, 8000 - backend) to be able to use the container.

Docker-Compose

As there is a docker-compose-local.yml in the root folder you can do all of this by just issuing:

docker network create dascr
docker-compose -f docker-compose-local.yml up

Different IP Address than localhost

By default the procedure above will build the docker image in a way where the scoreboard will only work on the system it was built on. If you need to separate the “viewing client” from the client running the scoreboard, you will need to use the Makefile to build and first run the docker image.

Step 1 will be to create a file called .env in the folder frontend as described at Installation#Frontend and fill in the corresponding ip address of the host running the scoreboard. Then you issue make run-docker for the customization to be applied at build time.

It should run the Scoreboard on port 8080 on that ip you chose and also it should be reachable and functional from within your network.

For the second startup docker-compose -f docker-compose-local.yml up should be enough.

Docker Release Image

If you do not want to build the docker images yourself this repository also has the latest version as an Release Package. I provide the file docker-compose-repo.yml for easy running as well.

docker network create dascr
docker-compose -f docker-compose-repo.yml up

After a successful startup you can access the web ui at port 8080.

What’s next?

When running the container successfully you can continue with webserver setup.

  • Caddy2: You might wanna continue setting up caddy2 server to serve the frontend UI

2 - Manual Deployment

How to build and autostart DaSCR-Board using systemd

Basically it is as easy as running through the getting started guide on your remote server.

Autostart backend using systemd

If you have successfully built the backend and the frontend you will have the backend binary in place and the public folder for serving with for example caddy2.

You can now use this systemd service file to automate the startup of the backend binary like so:

[Unit]
Description=DaSCR Board - Backend API
After=network.target

[Service]
Type=simple
User=patrick
Group=patrick
Restart=always
RestartSec=5s

Environment=API_IP=0.0.0.0
Environment=API_PORT=8000

WorkingDirectory=/home/patrick/projects/dascr-board
ExecStart=/home/patrick/projects/dascr-board/dist/linux_amd64/dascr-board
SyslogIdentifier=dascr-board

[Install]
WantedBy=multi-user.target

Save it at /etc/systemd/system/dascr-board.service.

Then run:

sudo systemctl daemon-reload
sudo systemctl start dascr-board
sudo systemctl enable dascr-board

Now the service should be up and running and be started at system boot time automatically.

You can check running sudo systemctl status dascr-board.

What’s next?

  • Caddy2: You might wanna continue setting up caddy2 server to serve the frontend UI

3 - Webserver setup

How to use caddy2 to serve the frontend UI

This section can also be solved using Apache2 or Nginx. I personally like Caddy2 much so I used it to deploy it. Therefore I will show my config as an example here.

You will need to install it yourself, though. It is kinda easy, I guess.

Caddyfile

My caddy file written to /etc/caddy/Caddyfile looks like this:

dascr.org {
	root * /home/patrick/projects/dascr-board/frontend/build
	encode gzip

	handle /api/* {
		reverse_proxy localhost:8000
	}

	handle /images/* {
		reverse_proxy localhost:8000
	}

	handle /uploads/* {
		reverse_proxy localhost:8000
	}

	handle /ws/* {
		reverse_proxy localhost:8000
	}

	handle {
		try_files {path} {file} /index.html
		file_server
	}

	header {
	# enable HSTS
	Strict-Transport-Security max-age=31536000;

	# disable clients from sniffing the media type
	X-Content-Type-Options nosniff

	# clickjacking protection
	X-Frame-Options DENY

	# keep referrer data off of HTTP connections
	Referrer-Policy no-referrer-when-downgrade
	}

	log {
		output file /var/log/caddy/dascr-board.log {
			roll_size 1gb
			roll_keep 5
			roll_keep_for 720h
		}
	}
}

Running this config you should have the frontend up and running at the domain https://dascr.org.

Basic Auth

If you want to protect your page from beeing used publicly you can also apply basic authentication by generating a user:pass combination like so (’test’ is the password in this example):

caddy hash-password -plaintext test
JDJhJDE0JGw1Ti43eW8ycW5vVTc1TDZVbDZBc09XVnI2YVJmYkM1VlguV0lHL1RsMkNBejkvLlFBUFFx

You can also completely omit -plaintext ... and will be prompted to insert the password without it landing in the history of the server.

Then you add this configuration bit to the Caddyfile:

basicauth * {
		username JDJhJDE0JGw1Ti43eW8ycW5vVTc1TDZVbDZBc09XVnI2YVJmYkM1VlguV0lHL1RsMkNBejkvLlFBUFFx
	}

What’s next?

  • Development: Wanna contribute? Have ideas? Go ahead!
  • API: Wanna use your own recognition software? Read the API specs.