SOURCES=$(wildcard src/*.nim)
TARGET_ENV ?= local
ECR_ACCOUNT_URL ?= 063932952339.dkr.ecr.us-west-2.amazonaws.com
VERSION ?=`git describe`
PORT ?= 8080

default: serve-docker

build: $(SOURCES)
	nimble build

serve: build
	TOCLERBE_PORT=$(PORT) \
		TOCLERBE_API_KEYS=qwertyasdfgh \
		./toclerbe urls.txt

# Build the container image.
build-image: $(SOURCES)
	docker image build -t $(ECR_ACCOUNT_URL)/toclerbe:$(VERSION) .

# Push the container image to the private AWS ECR
push-image: build-image
	docker push $(ECR_ACCOUNT_URL)/toclerbe:$(VERSION)

serve-docker: build-image start-postgres
	docker run \
		-e TOCLERBE_PORT=80 \
		-e TOCLERBE_API_KEYS=qwertyasdfgh
		-e "ISSUER=$(ISSUER)" \
		-p 127.0.0.1:$(PORT):80/tcp \
		$(ECR_ACCOUNT_URL)/toclerbe:$(VERSION)

ecr-auth:
	aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin $(ECR_ACCOUNT_URL)