.PHONY: test clean

ifeq ($(BUILD_ID),)
DOCKERFILE := dev.dockerfile
else
DOCKERFILE := ci.dockerfile
endif

# if no tag variable is passed, use md5 of the dockerfile
ifeq ($(TAG),)
TAG := $(shell openssl md5 $(DOCKERFILE) | cut -f 2 -d " ")
endif

DOCKER_IMG = video-tools/mck:$(TAG)

DOCKER_SH = docker run \
	-u jenkins:jenkins \
	-v "$(shell pwd):/workdir:rw" \
	-w /workdir \
	-t "$(DOCKER_IMG)" \
	sh -c

# DEFAULT GOAL
test: .test
	make clean

# make the tester image
.artifact_tester_image:
	docker build -t "$(DOCKER_IMG)" . -f $(DOCKERFILE)
	touch $@

# lint code after building the image
.lint: .artifact_tester_image
	$(DOCKER_SH) "go vet ./..."
	$(DOCKER_SH) "golangci-lint run -v"
	touch $@

.test: .lint
	$(DOCKER_SH) "go test -v ./..."
	touch $@

clean:
	rm -vfr .artifact_tester_image
	rm -vfr .lint
	rm -vfr .test
