Skip to content

Commit

Permalink
Copy data to static volume during docker-compose startup (HumanSignal…
Browse files Browse the repository at this point in the history
  • Loading branch information
farioas authored Aug 27, 2021
1 parent ed8add9 commit 49d7b66
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ deploy/license.txt
deploy/logs/
deploy/redis-data/
deploy/dockerfiles/postgres-data
postgres-data

label_studio/core/media
label_studio/core/downloads
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ EXPOSE 8080
RUN ./deploy/prebuild_wo_frontend.sh

ENTRYPOINT ["./deploy/docker-entrypoint.sh"]
CMD bash /label-studio/deploy/start_label_studio.sh
CMD ["label-studio"]
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#!/bin/sh
# wait-for-postgres.sh

set -e


echo >&3 "=> Waiting for postgres..."
until PGPASSWORD=$POSTGRE_PASSWORD psql -h "$POSTGRE_HOST" -p $POSTGRE_PORT -U "$POSTGRE_USER" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
echo >&3 "==> Postgres is unavailable - sleeping..."
sleep 1
done

>&2 echo "Postgres is up - executing command"
echo >&3 "=> Postgres is up."
7 changes: 7 additions & 0 deletions deploy/docker-entrypoint.d/20-run-db-migrations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

echo >&3 "=> Do database migrations..."
cat /label-studio/label_studio/manage.py
python3 /label-studio/label_studio/manage.py migrate >&3
echo >&3 "=> Migrations completed."
16 changes: 16 additions & 0 deletions deploy/docker-entrypoint.d/30-copy-static-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
set -e

DATA_SOURCE="/label-studio/label_studio"
DATA_TARGET="/label-studio/static_volume"

if [ -z "${LABEL_STUDIO_COPY_STATIC_DATA:-}" ]; then
echo >&3 "=> Skipping copy data."
else
echo >&3 "=> Copy static data to a shared folder..."
if [ -d $DATA_SOURCE ] && [ -d $DATA_TARGET ]; then
rm -rf $DATA_TARGET/* || true
cp -r $DATA_SOURCE/* $DATA_TARGET/
fi
echo >&3 "=> Successfully copied."
fi
37 changes: 26 additions & 11 deletions deploy/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
#!/usr/bin/env bash
#!/bin/sh

set -e

# if wait-for-postgres script is specified, we sleep in the loop until Postgre is up
if [[ "$1" = "./deploy/wait-for-postgres.sh" ]]; then
# ./deploy/wait-for-postgres.sh db
$1
shift 1
fi
# Redirect all scripts output + leaving stdout to container payload.
exec 3>&1

echo "=> Do database migrations..."
python3 label_studio/manage.py migrate
if [ "$1" = "label-studio" ]; then
if /usr/bin/find "/label-studio/deploy/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
echo >&3 "$0: Looking for init scripts in /label-studio/deploy/docker-entrypoint.d/"
find "/label-studio/deploy/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
case "$f" in
*.sh)
if [ -x "$f" ]; then
echo >&3 "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
echo >&3 "$0: Ignoring $f, not executable";
fi
;;
*) echo >&3 "$0: Ignoring $f";;
esac
done

echo "=> Run $@..."
exec "$@"
echo >&3 "$0: Configuration complete; ready for start up"
else
echo >&3 "$0: No init scripts found in /label-studio/deploy/docker-entrypoint.d/, skipping configuration"
fi
fi

exec "$@"
5 changes: 0 additions & 5 deletions deploy/start_label_studio.sh

This file was deleted.

18 changes: 14 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ services:
nginx:
image: nginx:latest
ports:
- 8080:80
- "8080:80"
depends_on:
- app
volumes:
- static:/label-studio/label_studio:rw
# keep in sync with deploy/docker-entrypoint.d/30-copy-static-data.sh
- source: static
target: /label-studio/label_studio
type: volume
volume:
nocopy: true
- ./mydata:/label-studio/data:rw
- ./deploy/nginx/${NGINX_FILE:-default.conf}:/etc/nginx/conf.d/default.conf:ro
command: nginx -g "daemon off;"
Expand All @@ -31,10 +36,15 @@ services:
- POSTGRE_PORT=5432
- POSTGRE_HOST=db
- LABEL_STUDIO_HOST=${LABEL_STUDIO_HOST:-}
- LABEL_STUDIO_COPY_STATIC_DATA=true
volumes:
- ./mydata:/label-studio/data:rw
- static:/label-studio/label_studio:rw
command: [ "./deploy/wait-for-postgres.sh", "bash", "/label-studio/deploy/start_label_studio.sh" ]
# keep in sync with deploy/docker-entrypoint.d/30-copy-static-data.sh
- source: static
target: /label-studio/static_volume
type: volume
volume:
nocopy: true

db:
image: postgres:11.5
Expand Down

0 comments on commit 49d7b66

Please sign in to comment.