TARGET ?= 3scale-amp-2.7-rhel-7-candidate

GIT_BRANCH = $(shell git symbolic-ref --short HEAD)

COMPONENT = zync
TAG ?= $(shell cut -f 2 -d ' ' source-repos)
BRANCH ?= $(TAG)
SOURCE ?= $(BRANCH).tar.gz
VERSION ?= 2.7

$(COMPONENT)-$(SOURCE):
	rhpkg sources

build: $(COMPONENT)-$(SOURCE)
	docker build -t $(COMPONENT):$(BRANCH) . --build-arg BUILD_TYPE=local

test:
	rhpkg container-build --scratch --target=$(TARGET)

clean:
	rm -rf $(COMPONENT)-3scale-* cache.tar.gz

brew:
ifneq (,$(findstring private-,$(GIT_BRANCH)))
	$(error can't build from private branch $(GIT_BRANCH))
else
	rhpkg container-build --target=$(TARGET)
endif

include docker-compose.mk

.PHONY: smoke
smoke: export ZYNC_IMAGE := $(SMOKE_IMAGE)
smoke: $(DOCKER_COMPOSE) ## Run some Smoke tests
	$(DOCKER_COMPOSE) down --volumes
	$(DOCKER_COMPOSE) up --detach postgresql
	$(DOCKER_COMPOSE) run --rm --no-deps -e RAILS_LOG_LEVEL=error zync bundle exec rake db:wait db:drop db:setup
	$(DOCKER_COMPOSE) up --detach zync
	sleep 10
	$(DOCKER_COMPOSE) exec -T zync bash -c 'curl -s -o /dev/null -w "%{http_code}" localhost:8080/status/ready' | grep 200
	$(DOCKER_COMPOSE) down --volumes
