Skip to content

How to deploy Codabench on your server

acletournel edited this page Mar 10, 2023 · 18 revisions

Overview

This document focuses on how to deploy the current project to the local machine or server you are on.

Pull codabench develop branch code locally

You need to complete the following steps

Installing docker and common docker commands

Modify .env file configuration

  • go to the folder where codabench is located
  • cp .env_sample .env :generate an .env file to set the environment variables required by the service
  • get the ip address of the local machine
    • The following commands will get you the private IP address of your interfaces:
      • ifconfig -a.
      • **ip** addr (**ip** a)
      • hostname -I | awk '{print $1}'
      • nmcli -p device show.
  • replace the value of ip address in the following environment variables according to your infrastructure configuration:

Open Access Permissions for following port number

If you are deploying on a linux server, which usually has a firewall, you need to open access permissions to the following port numbers

  • 5672: rabbit mq port
  • 8000: django port
  • 9000: minio port

Modify django-related configuration

  • go to the folder where codabench is located

  • Go to the settings directory and modify [base.py](http://base.py) file

    • cd src/settings/
    • vi base.py
  • Change the value of DEBUG to True

    • DEBUG = os.environ.get("DEBUG", True)
    • notice: If not set to true, then you will not be able to load to the static resource file
  • Comment out the following code

    image

Start Service

  • execute command sudo docker-compose up -d
  • Check if the service is started properly sudo docker-compose ps -a
codabench_compute_worker_1   "bash -c 'watchmedo …"   running      
codabench_caddy_1            "/bin/parent caddy -…"   running      0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 2015/tcp
codabench_site_worker_1      "bash -c 'watchmedo …"   running      
codabench_django_1           "bash -c 'cd /app/sr…"   running      0.0.0.0:8000->8000/tcp, :::8000->8000/tcp
codabench_flower_1           "flower"                 restarting   
codabench_rabbit_1           "docker-entrypoint.s…"   running      4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp
codabench_minio_1            "/usr/bin/docker-ent…"   running      0.0.0.0:9000->9000/tcp, :::9000->9000/tcp
codabench_db_1               "docker-entrypoint.s…"   running      0.0.0.0:5432->5432/tcp, :::5432->5432/tcp
codabench_builder_1          "docker-entrypoint.s…"   running      
codabench_redis_1            "docker-entrypoint.s…"   running      0.0.0.0:6379->6379/tcp, :::6379->6379/tcp
  • create the required tables in the database: sudo docker-compose exec django ./manage.py migrate
  • eventually generate mock data: sudo docker-compose exec django ./manage.py generate_data
  • generate the required static resource files: sudo docker-compose exec django ./manage.py collectstatic --noinput

Set public bucket policy to read/write!

This can easily be done via the minio web console (local url minio:9000) minio-9000-bucketPolicy

Checkout the log of the specified container

The following commands can help you debug

  • sudo docker logs -f codabench_django_1 : checkout django container logs in the docker-compose service
  • sudo docker logs -f codabench_site_worker_1 : checkout site-worker container logs in the docker-compose service
  • sudo docker logs -f codabench_compute_worker_1 : checkout compute-worker container logs in the docker-compose service
  • sudo docker logs -f codabench_minio_1 : checkout minio container logs in the docker-compose service

Stop Service

  • execute command sudo docker-compose down --volumes

FAQs

Invalid HTTP method

Exception detail(by using sudo docker logs -f codabench_django_1)

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 165, in data_received
    self.parser.feed_data(data)
  File "httptools/parser/parser.pyx", line 193, in httptools.parser.parser.HttpParser.feed_data
httptools.parser.errors.HttpParserInvalidMethodError: invalid HTTP method
[2021-02-09 06:58:58 +0000] [14] [WARNING] Invalid HTTP request received.
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 165, in data_received
    self.parser.feed_data(data)
  File "httptools/parser/parser.pyx", line 193, in httptools.parser.parser.HttpParser.feed_data
httptools.parser.errors.HttpParserInvalidMethodError: invalid HTTP method

image

Solution

  • first, modify the .env file and set DJANGO_SETTINGS_MODULE=settings.develop
  • then, restart services by using following docker-compose command
    • sudo docker-compose down --volumes
    • sudo docker-compose up -d

missing static resources(css/js)

Solution: Change the value of the DEBUG parameter to True

  • vi competitions-v2/src/settings/base.py
  • DEBUG = os.environ.get("DEBUG", True)

image

  • Also comment out the following code in base.py

image

CORS Error(could not upload bundle)

Exception detail(by checkout google develop tools)

botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "[http://docker.for.mac.localhost:9000/private/dataset/2021-02-18-1613624215/24533cfc523e/competition.zip](http://docker.for.mac.localhost:9000/private/dataset/2021-02-18-1613624215/24533cfc523e/competition.zip)"

Solution: Set AWS_S3_ENDPOINT_URL to an address that is accessible to the external network

  • vi codabench/.env

image

Make sure the ip address and port number is accessible by external network, You can check this by :

  • telnet {ip-address-filling-in AWS_S3_ENDPOINT_URL} {port-filling-in AWS_S3_ENDPOINT_URL}
  • Make sure the firewall is closed on port 9000

ps: This problem may also be caused by a bug in minio, you need to do the following steps

  • Upgrade the minio docker image to the latest version
  • delete the previous minio directory folder in your cdabench code under /var/minio directory
  • stop the current minio container
  • delete the current minio container and the corresponding image
  • re-execute docker-compose up -d

display logos error: logos don't upload from minio:

Check bucket policy of public minio bucket: read/write access should be allowed. This can easily be done via the minio web console (local url minio:9000) minio-9000-bucketPolicy

Compute worker execution with insufficient privileges

This issue may be encountered when starting a docker container in a compute worker, the problem is caused by the installation of snap docker(if you are using ubuntu)

Solution

  • Uninstall snap docker
  • Install the official version of docker
Clone this wiki locally