APP=$(shell basename $(CURDIR))
REGISTRY ?= 475275892927.dkr.ecr.us-east-1.amazonaws.com/delphi/bigtable-autoscaler
REVISION ?= $(shell git rev-parse --short=8 HEAD)
VERSION ?= $(shell cat ./VERSION)
BUILDTIME = $(shell date -u +"%Y%m%d%H%M%S")
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
AWS_PROFILE ?= gdb-delphi-dev

## -
## Commands:

##    docker/login - login to AWS docker, aws configuration need to be set first
.PHONY:docker/login
docker/login:
	$$(aws ecr get-login --profile ${AWS_PROFILE} --no-include-email --region us-east-1)

##    docker/image/build - put DDL scripts inside of a Liquibase image
.PHONY: docker/image/build
docker/image/build:
	docker build \
	    --no-cache \
		--build-arg REVISION=${REVISION} \
		--build-arg BUILDTIME=${BUILDTIME} \
		-t ${REGISTRY}:${VERSION} \
		-t ${REGISTRY}:${BRANCH} .

##    docker/image/push - push image into ECR
.PHONY: docker/image/push
docker/image/push: docker/login
	docker push ${REGISTRY}:${VERSION}

## -
## help - this message
.PHONY: help
help: Makefile
	@echo "Application: ${APP}\n"
	@echo "Run command:\n  make <target>\n"
	@grep -E -h '^## .*' $(MAKEFILE_LIST) | sed -n 's/^##//p'  | column -t -s '-' |  sed -e 's/^/ /'
