set -e

echo "readonly" | docker login docker.med-logic.ru --username readonly --password-stdin

docker pull docker.med-logic.ru/medicine-nginx:latest
docker pull docker.med-logic.ru/medicine-app:latest

unzip ../backups/medicine.sql.zip -d ../volumes/files/

docker exec -i medicine-stack-postgres psql -U postgres -d medicine -f /files/medicine.sql

cd /root/medicine-config/medicine
if [ ! -f .env ]
then
  cp env.sample .env
fi

docker-compose run --rm app python manage.py migrate --noinput
docker-compose run --rm app python manage.py collectstatic --noinput
