.PHONY: check test pull-build-image docker-push local-up local-down local-wipe

BUILD_IMAGE=docker-registry.internal.justin.tv/insights/piper-build:latest
AIRFLOW_IMAGE=docker-registry.internal.justin.tv/insights/piper-airflow:latest
SCHEDULER_IMAGE=docker-registry.internal.justin.tv/insights/piper-airflow-scheduler:latest
STARTUP_IMAGE=docker-registry.internal.justin.tv/insights/piper-airflow-startup:latest

check: lint
	PYTHONPATH=. pytest --cov-report term-missing --cov=piper piper dags

lint:
	pycodestyle dags piper --exclude=dags/*_cleanup.py
	pylint dags piper

test: pull-build-image
	docker run --rm -v ${PWD}:/code/piper ${BUILD_IMAGE} make check

pull-build-image:
	docker pull ${BUILD_IMAGE}

docker-push:
	docker build -f docker/build.Dockerfile -t ${BUILD_IMAGE} .
	docker push ${BUILD_IMAGE}
	docker build -f docker/airflow.Dockerfile -t ${AIRFLOW_IMAGE} .
	docker push ${AIRFLOW_IMAGE}
	docker build -f docker/airflow-scheduler.Dockerfile -t ${SCHEDULER_IMAGE} .
	docker push ${SCHEDULER_IMAGE}
	docker build -f docker/airflow-startup.Dockerfile -t ${STARTUP_IMAGE} .
	docker push ${STARTUP_IMAGE}

local-up:
	mkdir -p docker/drives/airflowmeta
	mkdir -p docker/drives/dailyincremental
	mkdir -p docker/drives/fakes3
	docker stack deploy -c docker/local-dev.yml localpiper
	docker/wait-for-it-mac.sh localhost:8080 60

local-down:
	docker stack rm localpiper

local-wipe:
	rm -rf docker/drives
	docker stack rm localpiper
