<commit_before><% self.filename = 'Makefile.docker' -%>
<% self.executable = false -%>
DOCKER ?= sudo docker
REV ?= $(shell git describe --always)
BUILD_FLAGS ?= -no-cache=true -rm=true
PROJECT ?= $(shell basename $(PWD))
REGISTRY ?= <%= registry %>
LATEST ?= $(shell $(DOCKER) images | grep -v REPOSITORY | head -n 1 | grep -E '<none>|$(REGISTRY)\/$(PROJECT)' | awk '{print $$3}')

export DOCKER
export REV
export BUILD_FLAGS
export PROJECT
export REGISTRY
export LATEST

# This is a general Makefile, designed to be present at the top level of your
# project for general docker development.  Be sure to use `docker login` on the
# vagrant vm before trying to push or pull any containers.

all:
	@echo "Available targets:"
	@echo "  * clean     - remove all local images (and tags) for $(PROJECT)"
	@echo "  * container - build a Docker container for $(PROJECT)"
	@echo "  * latest    - builds and tags the latest container for $(PROJECT) as 'latest'"
	@echo "  * pull      - pull down previous docker builds of $(REGISTRY)/$(PROJECT)"
	@echo "  * push      - push $(REGISTRY)/$(PROJECT)"
	@echo "  * tag       - tags the lastest image as 'latest'"

container: .latest_container Dockerfile

latest: build_and_tag

tag: delete_current_tag .latest_tagged

push: .latest_pushed

delete_current_tag:
	rm -f .latest_tagged

clean:
	rm -f .latest_container .latest_tagged .latest_pushed .container_output
	export IMAGES="$(shell $(DOCKER) images | grep -E '<none>|$(REGISTRY)/$(PROJECTS)')" ; \
	  test -z "$$IMAGES" || echo "$$IMAGES" | awk '{ print $$3 }' | \
	  sort | uniq | xargs $(DOCKER) rmi

.latest_container: pull
	rm -f $@
	$(DOCKER) build -t $(REGISTRY)/$(PROJECT):$(REV) $(BUILD_FLAGS) . | tee .container_output
	awk '/^Successfully built/ { print $$NF }' .container_output | tail -1 > $@

.latest_tagged:
	( test -z "$(LATEST)" && echo 'Nothing to tag!' ) || $(DOCKER) tag $(LATEST) $(REGISTRY)/$(PROJECT):latest && touch $@

build_and_tag: .latest_container tag

pull:
	$(DOCKER) pull $(REGISTRY)/$(PROJECT) || true

.latest_pushed: .latest_tagged
	$(DOCKER) push $(REGISTRY)/$(PROJECT)

.PHONY: container latest push clean build_and_tag tag delete_current_tag pull<commit_msg>Making clean command on docker makefile more effective<commit_after><% self.filename = 'Makefile.docker' -%>
<% self.executable = false -%>
DOCKER ?= sudo docker
REV ?= $(shell git describe --always)
BUILD_FLAGS ?= -no-cache=true -rm=true
PROJECT ?= $(shell basename $(PWD))
REGISTRY ?= <%= registry %>
LATEST ?= $(shell $(DOCKER) images | grep -v REPOSITORY | head -n 1 | grep -E '<none>|$(REGISTRY)\/$(PROJECT)' | awk '{print $$3}')

export DOCKER
export REV
export BUILD_FLAGS
export PROJECT
export REGISTRY
export LATEST

# This is a general Makefile, designed to be present at the top level of your
# project for general docker development.  Be sure to use `docker login` on the
# vagrant vm before trying to push or pull any containers.

all:
	@echo "Available targets:"
	@echo "  * clean     - remove all local images (and tags) for $(PROJECT)"
	@echo "  * container - build a Docker container for $(PROJECT)"
	@echo "  * latest    - builds and tags the latest container for $(PROJECT) as 'latest'"
	@echo "  * pull      - pull down previous docker builds of $(REGISTRY)/$(PROJECT)"
	@echo "  * push      - push $(REGISTRY)/$(PROJECT)"
	@echo "  * tag       - tags the lastest image as 'latest'"

container: .latest_container Dockerfile

latest: build_and_tag

tag: delete_current_tag .latest_tagged

push: .latest_pushed

delete_current_tag:
	rm -f .latest_tagged

clean:
	rm -f .latest_container .latest_tagged .latest_pushed .container_output
	export IMAGES="$(shell $(DOCKER) images | grep -E '<none>|$(REGISTRY)/$(PROJECTS)')" ; \
	  test -z "$$IMAGES" || echo "$$IMAGES" | awk '{ print $$3 }' | \
	  sort | uniq | xargs $(DOCKER) rmi

.latest_container: pull
	rm -f $@
	$(DOCKER) rm $(shell docker ps -a -q)
	$(DOCKER) build -t $(REGISTRY)/$(PROJECT):$(REV) $(BUILD_FLAGS) . | tee .container_output
	awk '/^Successfully built/ { print $$NF }' .container_output | tail -1 > $@

.latest_tagged:
	( test -z "$(LATEST)" && echo 'Nothing to tag!' ) || $(DOCKER) tag $(LATEST) $(REGISTRY)/$(PROJECT):latest && touch $@

build_and_tag: .latest_container tag

pull:
	$(DOCKER) pull $(REGISTRY)/$(PROJECT) || true

.latest_pushed: .latest_tagged
	$(DOCKER) push $(REGISTRY)/$(PROJECT)

.PHONY: container latest push clean build_and_tag tag delete_current_tag pull
{'fraction_non_alphanumeric': 0.14952851369555456, 'fraction_numerical': 0.001796138302649304, 'mean_word_length': 4.10894495412844, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '336333', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1513, 'n_words': 489}