<commit_before>.PHONY: test hyperkit-test qemu qemu-iso qemu-gce media ebpf ci ci-pr get get-regextract

all:
	$(MAKE) -C alpine

aufs:
	$(MAKE) AUFS=true all

alpine/initrd.img:
	$(MAKE) -C alpine initrd.img

alpine/initrd-test.img:
	$(MAKE) -C alpine initrd-test.img

alpine/kernel/x86_64/vmlinuz64:
	$(MAKE) -C alpine/kernel x86_64/vmlinuz64

alpine/mobylinux-bios.iso:
	$(MAKE) -C alpine mobylinux-bios.iso

alpine/gce.img.tar.gz:
	$(MAKE) -C alpine gce.img.tar.gz

QEMU_IMAGE=mobylinux/qemu:0fb8c648e8ed9ef6b1ec449587aeab6c53872744@sha256:606f30d815102e73bc01c07915dc0d5f153b0252c63f5f0ed1e39621ec656eb5

# interactive versions need to use volume mounts
qemu: alpine/initrd.img alpine/kernel/x86_64/vmlinuz64
	docker run -it --rm -v $(CURDIR)/alpine/initrd.img:/tmp/initrd.img -v $(CURDIR)/alpine/kernel/x86_64/vmlinuz64:/tmp/vmlinuz64 $(QEMU_IMAGE)

qemu-iso: alpine/mobylinux-bios.iso
	docker run -it --rm -v $(CURDIR)/alpine/mobylinux-bios.iso:/tmp/mobylinux-bios.iso $(QEMU_IMAGE)

qemu-gce: alpine/gce.img.tar.gz
	docker run -it --rm -v $(CURDIR)/alpine/gce.img.tar.gz:/tmp/gce.img.tar.gz $(QEMU_IMAGE)

bin:
	mkdir -p $@

bin/com.docker.hyperkit: | bin
	curl -fsSL https://circleci.com/api/v1/project/docker/hyperkit/latest/artifacts/0//Users/distiller/hyperkit/build/com.docker.hyperkit > $@
	chmod a+x $@

bin/com.docker.slirp: | bin
	curl -fsSL https://circleci.com/api/v1/project/docker/vpnkit/latest/artifacts/0//Users/distiller/vpnkit/com.docker.slirp.tgz \
		| tar xz --strip=2 -C $(dir $@) Contents/MacOS/com.docker.slirp
	touch $@

bin/regextract: | bin
	curl -fsSL https://circleci.com/api/v1/project/justincormack/regextract/latest/artifacts/0/\$$CIRCLE_ARTIFACTS/darwin/amd64/regextract > $@
	chmod a+x $@

hyperkit: hyperkit.sh bin/com.docker.hyperkit bin/com.docker.slirp alpine/initrd.img alpine/kernel/x86_64/vmlinuz64
	./hyperkit.sh

define check_test_log
	@cat $1 |grep -q 'Moby test suite PASSED'
endef

hyperkit-test: hyperkit.sh bin/com.docker.hyperkit bin/com.docker.slirp alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64
	rm -f disk.img
	INITRD=alpine/initrd-test.img script -q /dev/null ./hyperkit.sh | tee test.log
	$(call check_test_log, test.log)

test: alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64
	tar cf - $^ | docker run --rm -i $(QEMU_IMAGE) 2>&1 | tee test.log
	$(call check_test_log, test.log)

TAG=$(shell git rev-parse HEAD)
STATUS=$(shell git status -s)
MOBYLINUX_TAG=alpine/mobylinux.tag
ifdef AUFS
AUFS_PREFIX=aufs-
endif
ifdef LTS4.4
AUFS_PREFIX=lts4.4-
endif
MEDIA_IMAGE=mobylinux/media:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG)
INITRD_IMAGE=mobylinux/mobylinux:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG)
KERNEL_IMAGE=mobylinux/kernel:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG)
media: Dockerfile.media alpine/initrd.img alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64 alpine/mobylinux-efi.iso
ifeq ($(STATUS),)
	tar cf - $^ alpine/mobylinux.efi alpine/kernel/x86_64/vmlinux alpine/kernel/x86_64/kernel-headers.tar alpine/kernel/x86_64/kernel-dev.tar | docker build -f Dockerfile.media -t $(MEDIA_IMAGE) -
	docker push $(MEDIA_IMAGE)
	[ -f $(MOBYLINUX_TAG) ]
	docker tag $(shell cat $(MOBYLINUX_TAG)) $(INITRD_IMAGE)
	docker push $(INITRD_IMAGE)
	tar cf - Dockerfile.kernel alpine/kernel/x86_64/vmlinuz64 | docker build -f Dockerfile.kernel -t $(KERNEL_IMAGE) -
	docker push $(KERNEL_IMAGE)
else
	$(error "git not clean")
endif

EBPF_TAG=alpine/base/ebpf/ebpf.tag
EBPF_IMAGE=mobylinux/ebpf:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG)
ebpf: alpine/initrd.img alpine/kernel/x86_64/vmlinuz64
ifeq ($(STATUS),)
	[ -f $(EBPF_TAG) ]
	docker tag $(shell cat $(EBPF_TAG)) $(EBPF_IMAGE)
	docker push $(EBPF_IMAGE)
else
	$(error "git not clean")
endif

MEDIA_FILES=alpine/kernel/x86_64/vmlinuz64 alpine/kernel/x86_64/vmlinux alpine/initrd.img alpine/mobylinux-efi.iso alpine/mobylinux.efi 
MEDIA_FILES_OPT=alpine/kernel/x86_64/kernel-headers.tar alpine/kernel/x86_64/kernel-dev.tar alpine/initrd-test.img

get:
ifeq ($(STATUS),)
	IMAGE=$$( docker create mobylinux/media:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG) /dev/null ) && \
	mkdir -p alpine/kernel/x86_64 && \
	for FILE in $(MEDIA_FILES); do  docker cp $$IMAGE:$$(basename $$FILE) $$FILE || exit; done; \
	for FILE in $(MEDIA_FILES_OPT); do docker cp $$IMAGE:$$(basename $$FILE) $$FILE; done; \
	docker rm $$IMAGE
else
	$(error "git not clean")
endif

# Get artifacts using regextract for cases where docker is not available
get-regextract: bin/regextract
ifeq ($(STATUS),)
	TMP_EXTRACT=$$(mktemp -d) && \
	for FILE in $(MEDIA_FILES) $(MEDIA_FILES_OPT); do mkdir -p $$(dirname $$FILE); done; \
	bin/regextract mobylinux/media:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG) | tar xf - -C $$TMP_EXTRACT && \
	for FILE in $(MEDIA_FILES); do cp $$TMP_EXTRACT/$$(basename $$FILE) $$FILE || exit; done; \
	for FILE in $(MEDIA_FILES_OPT); do cp $$TMP_EXTRACT/$$(basename $$FILE) $$FILE; done; \
	rm -Rf $$TMP_EXTRACT
else
	$(error "git not clean")
endif

ci:
	$(MAKE) clean
	$(MAKE) all
	$(MAKE) test
	$(MAKE) media

ci-pr:
	$(MAKE) clean
	$(MAKE) all
	$(MAKE) test

.PHONY: clean

clean:
	$(MAKE) -C alpine clean
	$(MAKE) -C containers clean
	$(MAKE) -C test clean
	rm -rf bin disk.img test.log
<commit_msg>Use hyperkit and slirp from Docker for Mac install if available<commit_after>.PHONY: test hyperkit-test qemu qemu-iso qemu-gce media ebpf ci ci-pr get get-regextract

all:
	$(MAKE) -C alpine

aufs:
	$(MAKE) AUFS=true all

alpine/initrd.img:
	$(MAKE) -C alpine initrd.img

alpine/initrd-test.img:
	$(MAKE) -C alpine initrd-test.img

alpine/kernel/x86_64/vmlinuz64:
	$(MAKE) -C alpine/kernel x86_64/vmlinuz64

alpine/mobylinux-bios.iso:
	$(MAKE) -C alpine mobylinux-bios.iso

alpine/gce.img.tar.gz:
	$(MAKE) -C alpine gce.img.tar.gz

QEMU_IMAGE=mobylinux/qemu:0fb8c648e8ed9ef6b1ec449587aeab6c53872744@sha256:606f30d815102e73bc01c07915dc0d5f153b0252c63f5f0ed1e39621ec656eb5

# interactive versions need to use volume mounts
qemu: alpine/initrd.img alpine/kernel/x86_64/vmlinuz64
	docker run -it --rm -v $(CURDIR)/alpine/initrd.img:/tmp/initrd.img -v $(CURDIR)/alpine/kernel/x86_64/vmlinuz64:/tmp/vmlinuz64 $(QEMU_IMAGE)

qemu-iso: alpine/mobylinux-bios.iso
	docker run -it --rm -v $(CURDIR)/alpine/mobylinux-bios.iso:/tmp/mobylinux-bios.iso $(QEMU_IMAGE)

qemu-gce: alpine/gce.img.tar.gz
	docker run -it --rm -v $(CURDIR)/alpine/gce.img.tar.gz:/tmp/gce.img.tar.gz $(QEMU_IMAGE)

bin:
	mkdir -p $@

DOCKER_HYPERKIT=/Applications/Docker.app/Contents/MacOS/com.docker.hyperkit
DOCKER_SLIRP=/Applications/Docker.app/Contents/MacOS/com.docker.slirp

bin/com.docker.hyperkit: | bin
ifneq ("$(wildcard $(DOCKER_HYPERKIT))","")
	ln -s $(DOCKER_HYPERKIT) $@
else
	curl -fsSL https://circleci.com/api/v1/project/docker/hyperkit/latest/artifacts/0//Users/distiller/hyperkit/build/com.docker.hyperkit > $@
	chmod a+x $@
endif

bin/com.docker.slirp: | bin
ifneq ("$(wildcard $(DOCKER_SLIRP))","")
	ln -s $(DOCKER_SLIRP) $@
else
	curl -fsSL https://circleci.com/api/v1/project/docker/vpnkit/latest/artifacts/0//Users/distiller/vpnkit/com.docker.slirp.tgz \
		| tar xz --strip=2 -C $(dir $@) Contents/MacOS/com.docker.slirp
	touch $@
endif

bin/regextract: | bin
	curl -fsSL https://circleci.com/api/v1/project/justincormack/regextract/latest/artifacts/0/\$$CIRCLE_ARTIFACTS/darwin/amd64/regextract > $@
	chmod a+x $@

hyperkit: hyperkit.sh bin/com.docker.hyperkit bin/com.docker.slirp alpine/initrd.img alpine/kernel/x86_64/vmlinuz64
	./hyperkit.sh

define check_test_log
	@cat $1 |grep -q 'Moby test suite PASSED'
endef

hyperkit-test: hyperkit.sh bin/com.docker.hyperkit bin/com.docker.slirp alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64
	rm -f disk.img
	INITRD=alpine/initrd-test.img script -q /dev/null ./hyperkit.sh | tee test.log
	$(call check_test_log, test.log)

test: alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64
	tar cf - $^ | docker run --rm -i $(QEMU_IMAGE) 2>&1 | tee test.log
	$(call check_test_log, test.log)

TAG=$(shell git rev-parse HEAD)
STATUS=$(shell git status -s)
MOBYLINUX_TAG=alpine/mobylinux.tag
ifdef AUFS
AUFS_PREFIX=aufs-
endif
ifdef LTS4.4
AUFS_PREFIX=lts4.4-
endif
MEDIA_IMAGE=mobylinux/media:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG)
INITRD_IMAGE=mobylinux/mobylinux:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG)
KERNEL_IMAGE=mobylinux/kernel:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG)
media: Dockerfile.media alpine/initrd.img alpine/initrd-test.img alpine/kernel/x86_64/vmlinuz64 alpine/mobylinux-efi.iso
ifeq ($(STATUS),)
	tar cf - $^ alpine/mobylinux.efi alpine/kernel/x86_64/vmlinux alpine/kernel/x86_64/kernel-headers.tar alpine/kernel/x86_64/kernel-dev.tar | docker build -f Dockerfile.media -t $(MEDIA_IMAGE) -
	docker push $(MEDIA_IMAGE)
	[ -f $(MOBYLINUX_TAG) ]
	docker tag $(shell cat $(MOBYLINUX_TAG)) $(INITRD_IMAGE)
	docker push $(INITRD_IMAGE)
	tar cf - Dockerfile.kernel alpine/kernel/x86_64/vmlinuz64 | docker build -f Dockerfile.kernel -t $(KERNEL_IMAGE) -
	docker push $(KERNEL_IMAGE)
else
	$(error "git not clean")
endif

EBPF_TAG=alpine/base/ebpf/ebpf.tag
EBPF_IMAGE=mobylinux/ebpf:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG)
ebpf: alpine/initrd.img alpine/kernel/x86_64/vmlinuz64
ifeq ($(STATUS),)
	[ -f $(EBPF_TAG) ]
	docker tag $(shell cat $(EBPF_TAG)) $(EBPF_IMAGE)
	docker push $(EBPF_IMAGE)
else
	$(error "git not clean")
endif

MEDIA_FILES=alpine/kernel/x86_64/vmlinuz64 alpine/kernel/x86_64/vmlinux alpine/initrd.img alpine/mobylinux-efi.iso alpine/mobylinux.efi 
MEDIA_FILES_OPT=alpine/kernel/x86_64/kernel-headers.tar alpine/kernel/x86_64/kernel-dev.tar alpine/initrd-test.img

get:
ifeq ($(STATUS),)
	IMAGE=$$( docker create mobylinux/media:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG) /dev/null ) && \
	mkdir -p alpine/kernel/x86_64 && \
	for FILE in $(MEDIA_FILES); do  docker cp $$IMAGE:$$(basename $$FILE) $$FILE || exit; done; \
	for FILE in $(MEDIA_FILES_OPT); do docker cp $$IMAGE:$$(basename $$FILE) $$FILE; done; \
	docker rm $$IMAGE
else
	$(error "git not clean")
endif

# Get artifacts using regextract for cases where docker is not available
get-regextract: bin/regextract
ifeq ($(STATUS),)
	TMP_EXTRACT=$$(mktemp -d) && \
	for FILE in $(MEDIA_FILES) $(MEDIA_FILES_OPT); do mkdir -p $$(dirname $$FILE); done; \
	bin/regextract mobylinux/media:$(MEDIA_PREFIX)$(AUFS_PREFIX)$(TAG) | tar xf - -C $$TMP_EXTRACT && \
	for FILE in $(MEDIA_FILES); do cp $$TMP_EXTRACT/$$(basename $$FILE) $$FILE || exit; done; \
	for FILE in $(MEDIA_FILES_OPT); do cp $$TMP_EXTRACT/$$(basename $$FILE) $$FILE; done; \
	rm -Rf $$TMP_EXTRACT
else
	$(error "git not clean")
endif

ci:
	$(MAKE) clean
	$(MAKE) all
	$(MAKE) test
	$(MAKE) media

ci-pr:
	$(MAKE) clean
	$(MAKE) all
	$(MAKE) test

.PHONY: clean

clean:
	$(MAKE) -C alpine clean
	$(MAKE) -C containers clean
	$(MAKE) -C test clean
	rm -rf bin disk.img test.log

{'fraction_non_alphanumeric': 0.1539755208819957, 'fraction_numerical': 0.034009156311314584, 'mean_word_length': 4.767241379310345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 6, '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': '5666878', 'n_tokens_mistral': 4920, 'n_tokens_neox': 4474, 'n_words': 854}