BASE_STAND_NAME=base
STAND_NAME=$$USER
AWACS_TOKEN=$(shell cat ~/.dctl/token)


dev-install:
	docker-compose build
	docker-compose run --rm server ok migrate
	docker-compose run --rm server ok createsuperuser --username $(USER) --email $(USER)@yandex-team.ru --noinput

dev-run:
	docker-compose up server celery

test:
	docker-compose run --rm tests
	docker-compose run --rm tests_flow

makemessages:
	docker-compose run --rm tests sh -c "cd /src/ok && ok makemessages -l ru -e html,wiki,py"

compilemessages:
	docker-compose run --rm tests sh -c "cd /src/ok && ok compilemessages"

makemigrations:
	docker-compose run --rm tests sh -c "cd /src/ok && ok makemigrations"

stand-stage:
	ya tool dctl get stage tools_ok_stand_$(BASE_STAND_NAME) > $(STAND_NAME).yaml
	sed -i '' "s/stand_$(BASE_STAND_NAME)/stand_$(STAND_NAME)/g" $(STAND_NAME).yaml
	ya tool dctl copy stage ./$(STAND_NAME).yaml tools_ok_stand_$(STAND_NAME)
	rm ./$(STAND_NAME).yaml

stand-upstream:
	sed "s/{STAND_NAME}/$(STAND_NAME)/g" awacs_stand_backend.json > backend_$(STAND_NAME).json
	curl -v -X POST --data-binary "@backend_$(STAND_NAME).json" -H "Authorization: OAuth $(AWACS_TOKEN)" -H "Content-Type: application/json" https://awacs.yandex-team.ru/api/CreateBackend/
	sed "s/{STAND_NAME}/$(STAND_NAME)/g" awacs_stand_upstream.json > upstream_$(STAND_NAME).json
	curl -v -X POST --data-binary "@upstream_$(STAND_NAME).json" -H "Authorization: OAuth $(AWACS_TOKEN)" -H "Content-Type: application/json" https://awacs.yandex-team.ru/api/CreateUpstream/
	rm ./backend_$(STAND_NAME).json ./upstream_$(STAND_NAME).json

# Create stand if you don't have any.
# If you need to change default stand name use: `make stand STAND_NAME=your_stand_name`.
# If you need to copy stand from custom stage use: `make stand BASE_STAND_NAME=your_base_stand_name`.
# If you have stand and just want to deploy code into it use `releaser stand -s stand_name` instead.
stand:
	make stand-stage
	make stand-upstream
