Skip to content

Commit

Permalink
refactor: remove supervisord
Browse files Browse the repository at this point in the history
  • Loading branch information
mikucat0309 committed Feb 4, 2024
1 parent ca6bda9 commit ae959e8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 84 deletions.
3 changes: 1 addition & 2 deletions container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ EOS
COPY ./ /app/
RUN chmod -R u=rwX,go=rX ./ && chmod +x /app/container/entrypoint.sh

HEALTHCHECK --interval=5s CMD [ "/usr/local/bin/python3", "/app/container/health_check.py" ]
EXPOSE 8080
ENTRYPOINT [ "/app/container/entrypoint.sh" ]
CMD [ "/app/container/entrypoint.sh" ]
46 changes: 18 additions & 28 deletions container/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
set -ex

APP=/app
DATA=/data
Expand All @@ -17,34 +18,23 @@ if [ ! -f "$DATA/public/website/favicon.ico" ]; then
cp data/public/website/favicon.ico $DATA/public/website
fi

if [ -z "$MAX_WORKER_NUM" ]; then
export CPU_CORE_NUM=$(grep -c ^processor /proc/cpuinfo)
if [[ $CPU_CORE_NUM -lt 2 ]]; then
export MAX_WORKER_NUM=2
else
export MAX_WORKER_NUM=$(($CPU_CORE_NUM))
fi
fi
python manage.py migrate --no-input
python manage.py inituser --username=root --password=rootroot --action=create_super_admin
echo "from options.options import SysOptions; SysOptions.judge_server_token='$JUDGE_SERVER_TOKEN'" | python manage.py shell
echo "from conf.models import JudgeServer; JudgeServer.objects.update(task_number=0)" | python manage.py shell

addgroup -g 903 spj
adduser -u 900 -S -s /sbin/nologin -H -G spj server

cd $APP

n=0
while [ $n -lt 5 ]
do
python manage.py migrate --no-input &&
python manage.py inituser --username=root --password=rootroot --action=create_super_admin &&
echo "from options.options import SysOptions; SysOptions.judge_server_token='$JUDGE_SERVER_TOKEN'" | python manage.py shell &&
echo "from conf.models import JudgeServer; JudgeServer.objects.update(task_number=0)" | python manage.py shell &&
break
n=$(($n+1))
echo "Failed to migrate, going to retry..."
sleep 8
done

addgroup -g 12003 spj
adduser -u 12000 -S -G spj server

chown -R server:spj $DATA $APP/dist
chown -R server:spj $DATA
find $DATA/test_case -type d -exec chmod 710 {} \;
find $DATA/test_case -type f -exec chmod 640 {} \;
exec supervisord -c /app/container/supervisord.conf

CPU_CORE_NUM="$(nproc)"
if [ "$CPU_CORE_NUM" -lt 2 ]; then
export WORKER_NUM=2;
else
export WORKER_NUM="$CPU_CORE_NUM";
fi

gunicorn oj.wsgi --user server --group spj --bind 0.0.0.0:8080 --workers $WORKER_NUM
11 changes: 0 additions & 11 deletions container/health_check.py

This file was deleted.

40 changes: 0 additions & 40 deletions container/supervisord.conf

This file was deleted.

31 changes: 28 additions & 3 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ services:
oj-postgres:
image: postgres:10-alpine
restart: always
healthcheck:
test: [ "CMD", "pg_isready", "-U", "onlinejudge" ]
start_period: 1m
volumes:
- ./data/postgres:/var/lib/postgresql/data
environment:
Expand All @@ -21,6 +24,9 @@ services:
image: ghcr.io/qingdaou/oj-judge:1.6.0
# image: oj-judge
restart: always
depends_on:
oj-backend:
condition: service_started
read_only: true
cap_drop:
- SETPCAP
Expand All @@ -46,9 +52,28 @@ services:
# image: oj-backend
restart: always
depends_on:
- oj-redis
- oj-postgres
- oj-judge
oj-redis:
condition: service_started
oj-postgres:
condition: service_healthy
volumes:
- ./data/backend:/data
environment:
- POSTGRES_DB=onlinejudge
- POSTGRES_USER=onlinejudge
- POSTGRES_PASSWORD=onlinejudge
- JUDGE_SERVER_TOKEN=CHANGE_THIS

oj-dramatiq:
image: ghcr.io/qingdaou/oj-backend:1.7.0
# image: oj-backend
restart: always
depends_on:
oj-redis:
condition: service_started
oj-postgres:
condition: service_healthy
command: [ "python3", "manage.py", "rundramatiq" ]
volumes:
- ./data/backend:/data
environment:
Expand Down

0 comments on commit ae959e8

Please sign in to comment.