<commit_before>KI := conv
DATA ?= /data
SSH_HOST ?= 127.0.0.1
REPO ?= imma
TAG ?= latest
PREFIX := fehfeh$(shell hostname | perl -pe 's{[\.-]}{}g')

all:
	echo $(shell date +%s) >> .meh
	$(MAKE) base
	docker tag $(REPO):ubuntu $(REPO):start
	docker tag $(REPO):ubuntu $(REPO):start2
	env COMPOSE_PROJECT_NAME=$(PREFIX) docker-compose up -d --force-recreate
	while true; do if nc -z $(SSH_HOST) 2222; then break; fi; sleep 1; done
	while true; do if ssh -A -p 2222 -o IdentityFile=$(shell pwd)/.kitchen/docker_id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$(SSH_HOST) true; then break; fi; sleep 1; done
	$(MAKE) continue
	$(MAKE) finish
	docker tag $(REPO):latest $(REPO):start

base: .kitchen/docker_id_rsa
	(cd && make prune || true)
	mkdir -p .ssh
	rsync -ia ~/.ssh/authorized_keys .ssh/
	ln -nfs Dockerfile.base Dockerfile
	docker build -t $(REPO):ubuntu .

update:
	(cd && make prune || true)
	mkdir -p .ssh
	rsync -ia ~/.ssh/authorized_keys .ssh/
	ln -nfs Dockerfile.update Dockerfile
	echo $(shell date +%s) >> .meh
	docker build -t $(REPO):start2 .
	env COMPOSE_PROJECT_NAME=$(PREFIX) docker-compose up -d --force-recreate
	while true; do if nc -z $(SSH_HOST) 2222; then break; fi; sleep 1; done
	while true; do if ssh -A -p 2222 -o IdentityFile=$(shell pwd)/.kitchen/docker_id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$(SSH_HOST) true; then break; fi; sleep 1; done
	$(MAKE) continue
	$(MAKE) finish

continue:
	ssh -A -p 2222 -o IdentityFile=$(shell pwd)/.kitchen/docker_id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$(SSH_HOST) /tmp/cache/script/bootstrap
	echo FINISHED: ssh -A -p 2222 -o IdentityFile=$(shell pwd)/.kitchen/docker_id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$(SSH_HOST) /tmp/cache/script/bootstrap

finish:
	docker commit $(PREFIX)_$(REPO)_latest_1 $(REPO):latest
	env COMPOSE_PROJECT_NAME=$(PREFIX) docker-compose down || env COMPOSE_PROJECT_NAME=$(PREFIX) docker-compose down
	(cd && make prune >/dev/null 2>&1 || true)

dind:
	$(MAKE) SSH_HOST=172.17.0.1

.kitchen/docker_id_rsa:
	mkdir -p .kitchen
	ssh-keygen -f .kitchen/docker_id_rsa -P ''

docker-listen:
	docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 2375:2375 bobrik/socat TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock

push:
	ecs push "$(REPO):$(TAG)"

pull:
	ecs pull "$(REPO):$(TAG)"
	docker tag "$(shell aws ecr describe-repositories --repository-name $(REPO) | jq -r '.repositories[].repositoryUri'):$(TAG)" "$(REPO):$(TAG)"

docker:
	ki $(KI) docker-ubuntu

virtualbox:
	ki $(KI) virtualbox-ubuntu

virtualbox-docker:
	ki exec virtualbox-ubuntu -c 'ssh -A -o StrictHostKeyChecking=no ubuntu@localhost ki $(KI) docker-ubuntu'<commit_msg>keep prune here<commit_after>KI := conv
DATA ?= /data
SSH_HOST ?= 127.0.0.1
REPO ?= imma
TAG ?= latest
PREFIX := fehfeh$(shell hostname | perl -pe 's{[\.-]}{}g')

all:
	echo $(shell date +%s) >> .meh
	$(MAKE) base
	docker tag $(REPO):ubuntu $(REPO):start
	docker tag $(REPO):ubuntu $(REPO):start2
	env COMPOSE_PROJECT_NAME=$(PREFIX) docker-compose up -d --force-recreate
	while true; do if nc -z $(SSH_HOST) 2222; then break; fi; sleep 1; done
	while true; do if ssh -A -p 2222 -o IdentityFile=$(shell pwd)/.kitchen/docker_id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$(SSH_HOST) true; then break; fi; sleep 1; done
	$(MAKE) continue
	$(MAKE) finish
	docker tag $(REPO):latest $(REPO):start

base: .kitchen/docker_id_rsa
	$(MAKE) prune || true
	mkdir -p .ssh
	rsync -ia ~/.ssh/authorized_keys .ssh/
	ln -nfs Dockerfile.base Dockerfile
	docker build -t $(REPO):ubuntu .

update:
	$(MAKE) prune || true
	mkdir -p .ssh
	rsync -ia ~/.ssh/authorized_keys .ssh/
	ln -nfs Dockerfile.update Dockerfile
	echo $(shell date +%s) >> .meh
	docker build -t $(REPO):start2 .
	env COMPOSE_PROJECT_NAME=$(PREFIX) docker-compose up -d --force-recreate
	while true; do if nc -z $(SSH_HOST) 2222; then break; fi; sleep 1; done
	while true; do if ssh -A -p 2222 -o IdentityFile=$(shell pwd)/.kitchen/docker_id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$(SSH_HOST) true; then break; fi; sleep 1; done
	$(MAKE) continue
	$(MAKE) finish

continue:
	ssh -A -p 2222 -o IdentityFile=$(shell pwd)/.kitchen/docker_id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$(SSH_HOST) /tmp/cache/script/bootstrap
	echo FINISHED: ssh -A -p 2222 -o IdentityFile=$(shell pwd)/.kitchen/docker_id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$(SSH_HOST) /tmp/cache/script/bootstrap

finish:
	docker commit $(PREFIX)_$(REPO)_latest_1 $(REPO):latest
	env COMPOSE_PROJECT_NAME=$(PREFIX) docker-compose down || env COMPOSE_PROJECT_NAME=$(PREFIX) docker-compose down
	$(MAKE) prune || true

dind:
	$(MAKE) SSH_HOST=172.17.0.1

.kitchen/docker_id_rsa:
	mkdir -p .kitchen
	ssh-keygen -f .kitchen/docker_id_rsa -P ''

docker-listen:
	docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 2375:2375 bobrik/socat TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock

push:
	ecs push "$(REPO):$(TAG)"

pull:
	ecs pull "$(REPO):$(TAG)"
	docker tag "$(shell aws ecr describe-repositories --repository-name $(REPO) | jq -r '.repositories[].repositoryUri'):$(TAG)" "$(REPO):$(TAG)"

docker:
	ki $(KI) docker-ubuntu

virtualbox:
	ki $(KI) virtualbox-ubuntu

virtualbox-docker:
	ki exec virtualbox-ubuntu -c 'ssh -A -o StrictHostKeyChecking=no ubuntu@localhost ki $(KI) docker-ubuntu'

prune:
	docker system prune -f
	docker system prune -f --volumes
	docker system df
{'fraction_non_alphanumeric': 0.15418974450598535, 'fraction_numerical': 0.020368054314811507, 'mean_word_length': 4.456140350877193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '7419021', 'n_tokens_mistral': 2404, 'n_tokens_neox': 2122, 'n_words': 583}