Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PID lockfile issue for both Hugging Face Spaces and Docker #1403

Merged
merged 8 commits into from
Sep 15, 2023
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ COPY .git .git

COPY build.gradle.kts gradle.properties gradlew settings.gradle.kts ./

RUN ./gradlew clean install -Pprod --parallel --info --stacktrace
RUN ./gradlew clean -Pprod --parallel --info --stacktrace
RUN ./gradlew :backend:package -Pprod --parallel --info --stacktrace
RUN ./gradlew :frontend:package -Pprod --parallel --info --stacktrace
RUN ./gradlew :python-client:package -Pprod --parallel --info --stacktrace

RUN pip install pdm==2.8.2 urllib3==1.26.15 certifi==2023.7.22 && \
cd /app/python-client && \
pdm install --prod -G:all && \
pdm build && \
cd /app

# Create an environment and install giskard wheel. Some dependencies may require gcc which is only installed in build
# stage, but not in the production one
Expand Down Expand Up @@ -70,6 +73,8 @@ COPY --from=build /app/python-client/dist $GSK_DIST_PATH/python-client
COPY --from=build /app/python-client/.venv-prod $VENV_PATH
COPY --from=build /app/backend/build/libs/backend*.jar $GSK_DIST_PATH/backend/giskard.jar
COPY --from=build /app/frontend/dist $GSK_DIST_PATH/frontend/dist
COPY scripts/file-guard.sh $GSK_DIST_PATH/file-guard.sh
COPY scripts/start-*.sh $GSK_DIST_PATH/

COPY supervisord.conf ./
COPY packaging/nginx.conf.template $GSK_DIST_PATH/frontend/
Expand Down
2 changes: 1 addition & 1 deletion packaging/nginx.conf.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error_log stderr info;
error_log stderr notice;
pid "${GSK_HOME}/run/nginx/nginx.pid";
daemon off;
working_directory "${GSK_HOME}/run/nginx";
Expand Down
26 changes: 26 additions & 0 deletions scripts/file-guard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Script to guard lockfile with timeout

if [ -z "$1" ]
then
echo "No lockfile to monitor"
exit 0
fi

MAX_RETRY=${2:-100}
INTERNAL=${3:-0.2}
retry=0
LOCKFILE="$1"
while [ -f "$LOCKFILE" ] && [ $retry -lt $MAX_RETRY ]
do
echo "Waiting for \"$LOCKFILE\" file to be removed"
sleep $INTERNAL
retry=$(( $retry + 1 ))
done

if [ -f "$LOCKFILE" ]
then
echo "Warning: \"$LOCKFILE\" is still there after $MAX_RETRY retries"
echo " Force to remove $LOCKFILE"
rm "$LOCKFILE"
fi
5 changes: 5 additions & 0 deletions scripts/start-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

[ ! -d $PGDATA ] && initdb -D "$PGDATA" -U giskard
bash $GSK_DIST_PATH/file-guard.sh "$PGDATA/postmaster.pid"
postgres -D "$PGDATA"
4 changes: 4 additions & 0 deletions scripts/start-frontend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

envsubst '\$GSK_HOME \$GSK_DIST_PATH' < $GSK_DIST_PATH/frontend/nginx.conf.template > $GSK_DIST_PATH/frontend/nginx.conf
nginx -c $GSK_DIST_PATH/frontend/nginx.conf
4 changes: 4 additions & 0 deletions scripts/start-worker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

python -m giskard.cli worker stop -s
python -m giskard.cli worker start -s
7 changes: 4 additions & 3 deletions supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ command=java -jar %(ENV_GSK_DIST_PATH)s/backend/giskard.jar
stdout_logfile=%(ENV_GSK_HOME)s/run/%(program_name)s.log
autorestart=true
redirect_stderr=true
stopsignal=INT
startsecs=5
command=/bin/bash -c '[ ! -d $PGDATA ] && initdb -D "$PGDATA" -U giskard; postgres -D "$PGDATA"'
command=/bin/bash %(ENV_GSK_DIST_PATH)s/start-db.sh

[program:worker]
stdout_logfile=%(ENV_GSK_HOME)s/run/%(program_name)s.log
autorestart=true
redirect_stderr=true
startsecs=5
command=python -m giskard.cli worker start -s
command=/bin/bash %(ENV_GSK_DIST_PATH)s/start-worker.sh

[program:frontend]
stdout_logfile=%(ENV_GSK_HOME)s/run/%(program_name)s.log
autorestart=true
redirect_stderr=true
startsecs=5
command=/bin/bash -c "envsubst '\$GSK_HOME \$GSK_DIST_PATH' < $GSK_DIST_PATH/frontend/nginx.conf.template > $GSK_DIST_PATH/frontend/nginx.conf && nginx -c $GSK_DIST_PATH/frontend/nginx.conf"
command=/bin/bash %(ENV_GSK_DIST_PATH)s/start-frontend.sh
Loading