docker-entrypoint.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/sh
  2. #
  3. # WyOJ judger entrypoint.
  4. #
  5. # Writes .conf.json (which judge_client/init() requires) from the environment,
  6. # makes sure the runtime directories exist, then runs judge_client in the
  7. # foreground so that its output lands in `docker logs`.
  8. set -e
  9. cd /opt/uoj/judger
  10. mkdir -p uoj_judger/work uoj_judger/result uoj_judger/data log /var/uoj_data_copy
  11. # data/ is expected to be a symlink to /var/uoj_data_copy. The build context
  12. # normally excludes it, so recreate it here.
  13. if [ ! -e uoj_judger/data ]; then
  14. ln -s /var/uoj_data_copy uoj_judger/data
  15. fi
  16. chmod -R 777 uoj_judger/work uoj_judger/result log 2>/dev/null || true
  17. python3 - <<'PY'
  18. import json, os
  19. conf = {
  20. 'uoj_protocol': os.environ.get('UOJ_PROTOCOL', 'http'),
  21. 'uoj_host': os.environ.get('UOJ_HOST', 'uoj-web'),
  22. 'judger_name': os.environ.get('JUDGER_NAME', 'main_judger'),
  23. 'judger_password': os.environ.get('JUDGER_PASSWORD', '_judger_password_'),
  24. 'socket_port': int(os.environ.get('JUDGER_SOCKET_PORT', '2333')),
  25. 'socket_password': os.environ.get('JUDGER_SOCKET_PASSWORD', '_judger_socket_password_'),
  26. }
  27. with open('.conf.json', 'w') as f:
  28. json.dump(conf, f, indent=2)
  29. f.write('\n')
  30. print('wrote .conf.json: judger=%s -> %s://%s, socket :%d'
  31. % (conf['judger_name'], conf['uoj_protocol'], conf['uoj_host'], conf['socket_port']))
  32. PY
  33. echo "==> starting judge_client (foreground)"
  34. exec ./judge_client