diff --git a/Dockerfile b/Dockerfile index 457da5124c..940e0748a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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/ diff --git a/packaging/nginx.conf.template b/packaging/nginx.conf.template index 0548e071e8..d6df088f18 100644 --- a/packaging/nginx.conf.template +++ b/packaging/nginx.conf.template @@ -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"; diff --git a/scripts/file-guard.sh b/scripts/file-guard.sh new file mode 100644 index 0000000000..fe9312796e --- /dev/null +++ b/scripts/file-guard.sh @@ -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 \ No newline at end of file diff --git a/scripts/start-db.sh b/scripts/start-db.sh new file mode 100644 index 0000000000..0bac80396e --- /dev/null +++ b/scripts/start-db.sh @@ -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" diff --git a/scripts/start-frontend.sh b/scripts/start-frontend.sh new file mode 100644 index 0000000000..2ff8f32fbf --- /dev/null +++ b/scripts/start-frontend.sh @@ -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 diff --git a/scripts/start-worker.sh b/scripts/start-worker.sh new file mode 100644 index 0000000000..152b7401c1 --- /dev/null +++ b/scripts/start-worker.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +python -m giskard.cli worker stop -s +python -m giskard.cli worker start -s diff --git a/supervisord.conf b/supervisord.conf index 8bcdab6aa5..f76a73541e 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -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