APP            =  a0deploy
AWS_PROFILE    ?= gdb-infra-dev
AWS_REGION     ?= us-east-1
AWS_ACCOUNT_ID ?= 483193324480
ECR            =  ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
REPOSITORY     =  ${ECR}/${APP}
VERSION        =  5.2.1

##   %/login - login to AWS ECR registry using docker or podman, aws configuration need to be set first
.PHONY:%/login
%/login:
	@aws ecr get-login \
		--profile ${AWS_PROFILE} \
		--no-include-email \
		--region ${AWS_REGION} | awk '{print $$6}' | \
		$* login -u AWS --password-stdin https://${ECR}

##   %/login - login to AWS ECR registry using docker or podman, for aws cli version 2, aws configuration need to be set first
.PHONY:%/login_v2
%/login_v2:
	@aws ecr get-login-password \
		--profile ${AWS_PROFILE} \
		--region ${AWS_REGION} | \
		$* login --username AWS --password-stdin ${ECR}

##   %/image/push - build an image using docker or podman
.PHONY: %/image/build
%/image/build:
	@$* build \
		--cache-from ${REPOSITORY}:latest \
		--build-arg VERSION=${VERSION} \
		-t ${REPOSITORY}:${VERSION} \
		-t ${REPOSITORY}:latest .

##   %/image/push - push an image to a registry, you can use docker or podman
.PHONY: %/image/push
%/image/push:
	@$* push ${REPOSITORY}:${VERSION}
	@$* push ${REPOSITORY}:latest

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