Giter VIP home page Giter VIP logo

hnoj-docker's Introduction

DMOJ Docker Build Status

This repository contains the Docker files to run a clone of the HNOJ site. It configures some additional services, such as mathoid, pdfoid, and texoid.

Installation

First, Docker and Docker Compose must be installed. Installation instructions can be found on their respective websites.

Clone the repository:

$ git clone https://github.com/hnojedu/hnoj-docker
$ cd hnoj-docker
$ git submodule update --init --recursive
$ cd dmoj

From now on, it is assumed you are in the dmoj directory.

Initialize the setup by moving the configuration files into the submodule and by creating the necessary directories:

$ ./scripts/initialize

Configure the environment variables in the files in dmoj/environment/. In particular, set the MYSQL passwords in mysql.env and mysql-admin.env, and the host and secret key in site.env. Also, configure the server_name directive in dmoj/nginx/nginx.conf.

Next, build the images:

$ docker compose build

Start up the site, so you can perform the initial migrations and generate the static files:

$ docker compose up -d site

You will need to generate the schema for the database, since it is currently empty:

$ ./scripts/migrate

You will also need to generate the static files:

$ ./scripts/copy_static

Finally, the DMOJ comes with fixtures so that the initial install is not blank. They can be loaded with the following commands:

$ ./scripts/manage.py loaddata navbar
$ ./scripts/manage.py loaddata language_small
$ ./scripts/manage.py loaddata demo

Usage

$ docker compose up -d

Notes

Migrating

As the DMOJ site is a Django app, you may need to migrate whenever you update. Assuming the site container is running, running the following command should suffice:

$ ./scripts/migrate

Managing Static Files

If your static files ever change, you will need to rebuild them:

$ ./scripts/copy_static

Updating The Site

Updating various sections of the site requires different images to be rebuilt.

If any prerequisites were modified, you will need to rebuild most of the images:

$ docker compose up -d --build base site celery bridged wsevent

If the static files are modified, read the section on Managing Static Files.

If only the source code is modified, a restart is sufficient:

$ docker compose restart site celery bridged wsevent

Multiple Nginx Instances

The docker-compose.yml configures Nginx to publish to port 80. If you have another Nginx instance on your host machine, you may want to change the port and proxy pass instead.

For example, a possible Nginx configuration file on your host machine would be:

server {
    listen 80;
    listen [::]:80;

    add_header X-UA-Compatible "IE=Edge,chrome=1";
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";

    location / {
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_pass http://127.0.0.1:10080/;
    }
}

In this case, the port that the Nginx instance in the Docker container is published to would need to be modified to 10080.

Common Errors

502 Bad Gateway

Ensure that you also restart the Nginx container if you restart the site container as Nginx caches DNS queries. Otherwise, Nginx will try to hit the old IP, causing a 502 Bad Gateway. See this issue for more information.

hnoj-docker's People

Contributors

ninjaclasher avatar magnified103 avatar powergee avatar

Stargazers

 avatar

Watchers

cxa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.