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

stand-stage:
	ya tool dctl get stage tools_review_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_review_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

pip-freeze:
	docker-compose -f docker-compose-freeze-deps.yml build freeze
	docker-compose -f docker-compose-freeze-deps.yml run freeze

migrations:
	docker-compose run backend review makemigrations --settings=review.settings_test
