<commit_before># DockerHelper.mk is a simple replacement for docker-compose for
# working with a single service.
#
# Usage Examples:
# - https://gist.github.com/SmartFinn/7bb86b078726f0763ce0#file-usage-md
# - https://github.com/SmartFinn/Dockerfiles
#
# @author: <NAME> (https://github.com/SmartFinn)
# @license: Unlicense (http://unlicense.org)
# @link: https://gist.github.com/SmartFinn/7bb86b078726f0763ce0

OWNER  ?= $(USER)
REPO   ?= $(notdir $(CURDIR))
TAG    ?= latest
IMAGE  ?= $(OWNER)/$(REPO):$(TAG)
NAME   ?= $(REPO)
DOCKER ?= docker
BUILD_OPTIONS ?= --force-rm
RUN_COMMAND   ?=
RUN_OPTIONS   ?= --interactive --rm --tty

default: build

diff logs port stats top:
	@$(DOCKER) container $@ $(NAME)

build:
	$(DOCKER) build $(BUILD_OPTIONS) --tag $(IMAGE) $(CURDIR)

destroy: stop rm

images: ls

history ls pull:
	@$(DOCKER) image $@ $(IMAGE)

kill pause restart start stop unpause:
	@$(DOCKER) $@ $(NAME) | \
		xargs -I {} echo " ---> $@ container '{}'"

prune:
	@$(DOCKER) system prune -f

ps:
	@$(DOCKER) container ps -a --filter=name=$(NAME)

purge: stop rm rmi prune

push:
	$(DOCKER) login
	$(DOCKER) image push $(IMAGE)

rebuild: rmi build

rm:
	@$(DOCKER) container rm --force --volumes $(NAME) | \
		xargs -I {} echo " ---> remove container '{}'"

rmi:
	@$(DOCKER) image rm $(IMAGE) | \
		xargs -I {} echo " ---> {}"

run:
	$(DOCKER) run $(RUN_OPTIONS) --name $(NAME) $(IMAGE) $(RUN_COMMAND)

shell:
	@$(DOCKER) container exec --interactive --tty $(NAME) \
		sh -c "/bin/bash || /bin/sh"

up: run

.PHONY: default build destroy diff images history kill logs ls pause \
	port prune ps pull purge push rebuild restart rm rmi run shell \
	start stats stop top unpause up<commit_msg>Update DockerHelper.mk: add custom networks support<commit_after># DockerHelper.mk is a simple replacement for docker-compose for
# working with a single service.
#
# Usage Examples:
# - https://gist.github.com/SmartFinn/7bb86b078726f0763ce0#file-usage-md
# - https://github.com/SmartFinn/Dockerfiles
#
# @author: <NAME> (https://github.com/SmartFinn)
# @license: Unlicense (http://unlicense.org)
# @link: https://gist.github.com/SmartFinn/7bb86b078726f0763ce0

OWNER  ?= $(USER)
REPO   ?= $(notdir $(CURDIR))
TAG    ?= latest
IMAGE  ?= $(OWNER)/$(REPO):$(TAG)
NAME   ?= $(REPO)
DOCKER ?= docker
BUILD_OPTIONS ?= --force-rm
NET_NAME      ?= $(shell echo $(RUN_OPTIONS) | sed -rn "s/.*--net(|work)[= '\"]([^ '\"']+).*/\2/p")
NET_OPTIONS   ?= --driver=bridge
RUN_COMMAND   ?=
RUN_OPTIONS   ?= --interactive --rm --tty

default: build

diff logs port stats top:
	@$(DOCKER) container $@ $(NAME)

build:
	$(DOCKER) build $(BUILD_OPTIONS) --tag $(IMAGE) $(CURDIR)

destroy: stop rm

down: stop rm rmi prune

images: ls

history ls pull:
	@$(DOCKER) image $@ $(IMAGE)

kill pause restart start stop unpause:
	@$(DOCKER) $@ $(NAME) | \
		xargs -I {} echo " ---> $@ container '{}'"

network:
	@if $(DOCKER) network ls -qf name='^$(NET_NAME)$$' | xargs -r false; then \
		NET_NAME="$(NET_NAME)"; \
		if test -n "$${NET_NAME%container:*}"; then \
			$(DOCKER) network create $(NET_OPTIONS) $(NET_NAME); \
		fi; \
	fi

networks:
	@$(DOCKER) network ls --filter=name=$(NET_NAME)

prune:
	@$(DOCKER) system prune -f

ps:
	@$(DOCKER) container ps -a --filter=name=$(NAME)

push:
	$(DOCKER) login
	$(DOCKER) image push $(IMAGE)

rebuild: rmi build

rm:
	@$(DOCKER) container rm --force --volumes $(NAME) | \
		xargs -I {} echo " ---> remove container '{}'"

rmi:
	@$(DOCKER) image rm $(IMAGE) | \
		xargs -I {} echo " ---> {}"

run: network
	$(DOCKER) run $(RUN_OPTIONS) --name $(NAME) $(IMAGE) $(RUN_COMMAND)

shell:
	@$(DOCKER) container exec --interactive --tty $(NAME) \
		sh -c "/bin/bash || /bin/sh"

up: run

.PHONY: default build destroy down diff images history kill logs ls \
	network networks pause port prune ps pull push rebuild restart \
	rm rmi run shell start stats stop top unpause up
{'fraction_non_alphanumeric': 0.1842985842985843, 'fraction_numerical': 0.014671814671814672, 'mean_word_length': 3.698911729141475, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 8, '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': '5674606', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1484, 'n_words': 410}