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
Merged
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ 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 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
75 changes: 75 additions & 0 deletions python-client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import ru.vyarus.gradle.plugin.python.PythonExtension.Scope.VIRTUALENV
import ru.vyarus.gradle.plugin.python.task.PythonTask

plugins {
id("base")
id("idea")
id("org.sonarqube")
id("ru.vyarus.use-python") version "3.0.0"
}

tasks {
val virtualEnvDirectory = ".venv"
python {
envPath = virtualEnvDirectory
minPythonVersion = "3.8"
scope = VIRTUALENV
installVirtualenv = true
pip(listOf("pdm:2.8.2", "urllib3:1.26.15", "certifi:2023.7.22"))
}

create<PythonTask>("install") {
dependsOn("pipInstall")
var cmd = "install"
if (project.hasProperty("prod")) {
cmd += " --prod"
} else {
cmd += " -G:all"
}

module = "pdm"
command = cmd
}

clean {
delete(virtualEnvDirectory, "coverage.xml", ".coverage")
}

create<PythonTask>("sphinx-autobuild") {
module = "sphinx_autobuild"
command = "--watch giskard docs docs/_build/html"
}

create<PythonTask>("lint") {
dependsOn("install")
module = "pdm"
command = "lint"
}

idea {
module {
excludeDirs.add(file(virtualEnvDirectory))
excludeDirs.add(file("dist"))

// "generated" directory should be marked as both source and generatedSource,
// otherwise intellij doesn"t recognize it as a generated source 🤷‍
testSources.from(file("tests"))
inheritOutputDirs = false
outputDir = file("dist")
testOutputDir = file("dist")

}
}

create<PythonTask>("start") {
module = "giskard.cli"
command = "worker start -s"
}

create<PythonTask>("package") {
dependsOn("pipInstall")

module = "pdm"
command = "build"
}
}
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
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ pluginManagement {
rootProject.name = "giskard"
include(
"backend",
"frontend"
"frontend",
Inokinoki marked this conversation as resolved.
Show resolved Hide resolved
"python-client",
)
5 changes: 3 additions & 2 deletions supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ 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 -c '[ ! -d $PGDATA ] && initdb -D "$PGDATA" -U giskard; bash $GSK_DIST_PATH/file-guard.sh "$PGDATA/postmaster.pid"; postgres -D "$PGDATA"'
Inokinoki marked this conversation as resolved.
Show resolved Hide resolved

[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 -c 'python -m giskard.cli worker stop -s; python -m giskard.cli worker start -s'

[program:frontend]
stdout_logfile=%(ENV_GSK_HOME)s/run/%(program_name)s.log
Expand Down
Loading