CONFIG = RELEASER_PROJECT_CONFIG=".release.stand.hjson"
source ?= $(name)

stand: check-name
	@$(CONFIG) ya tool releaser env-dump -e $(source) --dump .stand.dump || $(CONFIG) ya tool releaser env-dump -e stand --dump .stand.dump
	@$(CONFIG) ya tool releaser stand --standname $(name) $(args) || true
	@rm .stand.dump

delete-stand: check-name
	@$(CONFIG) ya tool releaser env-delete -e $(name);

fast-stand:
	ya make --target-platform=linux -o build-linux
	scp build-linux/intranet/femida/src/wsgi/femida.wsgi root@"${FEMIDA_STAND}":femida-main-linux
	echo 'femida-main restarting' && ssh "root@${FEMIDA_STAND}" '[[ "$$IS_DEV_STAND" = "1" ]] && /usr/bin/pkill -9 femida-main && mv femida-main-linux femida-main && sleep 1 && while [[ `pgrep femida-main | wc -l` != 5 ]]; do sleep 1; done' && echo 'femida-main restarted'

check-name:
	@test $(name) || (echo 'Usage: make COMMAND name=STANDNAME'; exit 1)

build-local:
	cp -n datasources.py.example datasources.py; exit 0;
	docker-compose build web
	docker-compose run web femida init_local_db
	docker-compose up web

run-local:
	docker-compose up web

arc-build:
	ya make -o build
	cp build/intranet/femida/src/wsgi/femida.wsgi femida-main
	rm -rf build
