Skip to content

Docker Usage

Michael Hale edited this page Feb 10, 2024 · 2 revisions

Ogres supports Docker environments for both production and development. A complete docker-compose.yaml is provided with commented documentation.

Images

Three images are included: frontend, backend, and nginx. The frontend image builds the ClojureScript client application, the backend image builds the Clojure application server which exposes a WebSocket connection, and the nginx image ties together the marketing website, the client application, the application server's WebSocket connection, as well as previous Ogres releases tagged on GitHub.

Image Arguments

  • VERSION - The release tag for the client application. Tags can be accessed with the parameter r (e.g., /play/?r=dev). The latest tag is the default entrypoint for the client. Unless latest is specified, clients will have to use the chosen tag in order to access the Docker client build.
  • MODE - Must be set to either release or watch. The release mode will produce a production build of the client application, whereas the watch mode will produce a developmental client build with support for hot reloading.
  • SERVER_SOCKET_URL - Declares the WebSocket URL for both the frontend and nginx. Within the frontend image, the URL will be the one accessed by the user's browser; in production settings you should set this to your domain (i.e., wss://ogres.domain.com/ws). In the nginx image, this URL will point to the backend container's exposed port (i.e., http://backend:8090/ws).

Running the Environment

Development Mode

To start the environment in development mode, ensure that the MODE argument is set to watch. Then, run the following command in your terminal:

docker compose watch

The environment will start, and hot reloading will be enabled for all changes to the ClojureScript client application. Hot reloading is currently not supported for the application server.

Please note, localhost should not be used to access the client application at this time; instead, use either 127.0.0.1 or 0.0.0.0. Accessing the client with localhost will result in a blank page being displayed.

Production Mode

To start the environment in production mode, ensure that the MODE argument is set to release. You can also comment out the Compose line which opens port 9630 for hot reloading. Then, run the following command in your terminal:

docker compose up -d

Stopping and Deleting

To stop the Docker compose environment, run the following command:

docker compose stop

To delete the Docker compose environment and remove the generated images and volumes, run the following command:

docker compose down --rmi local -v

Hosting a Production Instance

These instructions briefly describe how to run your own production instance of Ogres. In addition to docker, you will need certbot and nginx installed on the host machine for this example.

The following instructions assume you will run Ogres with a subdomain at ogres.domain.com. This is not required -- you can use a root domain.

  1. Start the Docker environment in production mode.
  2. Create the following nginx site configuration on the host machine at /etc/nginx/sites-available/ogres.domain.com:
server {
        server_name ogres.domain.com;
        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_certificate /etc/letsencrypt/live/ogres.domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/ogres.domain.com/privkey.pem;

        include snippets/ssl.conf;

        access_log /var/log/nginx/ogres.domain.com/access.log;
        error_log /var/log/nginx/ogres.domain.com/error.log;

        location / {
                proxy_pass http://127.0.0.1:8080/;
                proxy_http_version 1.1;
                proxy_set_header Connection "upgrade";
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header X-Forwarded-Proto $scheme;

                proxy_read_timeout 1d;
        }
}

server {
        server_name ogres.domain.com;
        listen 80;
        listen [::]:80;

        return 301 https://$server_name$request_uri;
}
  1. Generate an SSL certificate for the subdomain with certbot. This can be completed via several methods, so please refer to the official certbot instructions for more information. The nginx configuration assumes the certificates will be installed to /etc/letsencrypt/live/ogres.domain.com.
  2. Link the sites-available configuration into sites-enabled: ln -s /etc/nginx/sites-available/ogres.domain.com /etc/nginx/sites-enabled/ogres.domain.com.
  3. Reload the nginx server.

Support

Please feel free to open a question on the discussions page.

Clone this wiki locally