<commit_before>all:	initrd.img initrd-test.img mobylinux-efi.iso mobylinux-bios.iso

ETCFILES=$(shell find etc)

TAG=$(shell git rev-parse HEAD)
STATUS=$(shell git status -s)
ifeq ($(STATUS),)
DIRTY=
else
DIRTY=-dirty
endif

# Tag: 22b043cb43f6bc3bc4e1f1ecf9d64932f9325642
BIOS_IMAGE=mobylinux/mkimage-iso-bios@sha256:7e28f7745fd62284142dce59a137c3331f7673efe8b3f19ee5c65e4cc27ff18c

# Tag: c6c904f82ec47594f7b1a26a76013cd7a53356d8
PAD4_IMAGE=mobylinux/pad4@sha256:0963843b484faa021dc99f67bdfd01c9c1721621fffcf343a68151ae074b2206

# Tag: 1e3cdc45eae37806b692432e010271b3172b7f0a
TAR2INITRD_IMAGE=mobylinux/tar2initrd@sha256:4045cba0df947e449a54d3822f789dc3faad4aa8f04a0d51674ed777f044e159

# Tag: 77bc577875fb3a80ac2d14b70d1daa885bbf199c
GCE_IMAGE=mobylinux/mkimage-gce@sha256:f9abf2eae20984b7dd3c1afb700b2c9c41e39e6e7c688c78348a51d0780d74cc

moby.img: Dockerfile mkinitrd.sh init $(ETCFILES)
	$(MAKE) -C kernel
	$(MAKE) -j -C packages
	printf $(TAG)$(DIRTY) > etc/moby-commit
	BUILD=$$( tar cf - \
	  Dockerfile etc usr init mkinitrd.sh \
	  -C kernel usr etc sbin lib -C .. \
	  -C packages/proxy usr sbin etc -C ../.. \
	  -C packages/transfused sbin etc -C ../.. \
	  -C packages/tap-vsockd sbin etc -C ../.. \
	  -C packages/docker usr etc -C ../.. \
	  -C packages/diagnostics usr etc -C ../.. \
	  -C packages/automount etc -C ../.. \
	  -C packages/hostsettings etc -C ../.. \
	  -C packages/chronyd etc -C ../.. \
	  -C packages/userns etc -C ../.. \
	  -C packages/nc-vsock usr -C ../.. \
	  -C packages/vsudd sbin etc -C ../.. \
	  -C packages/mobyconfig usr -C ../.. \
	  -C packages/mobyplatform usr -C ../.. \
	  -C packages/oom etc -C ../.. \
	  -C packages/9pmount-vsock sbin -C ../.. \
	  -C packages/test etc -C ../.. \
	  -C packages/iptables usr -C ../.. \
	  -C packages/containerd etc -C ../.. \
	  -C packages/aws etc -C ../.. \
	  -C packages/azure etc -C ../.. \
	  -C packages/gcp etc -C ../.. \
	  | \
	  docker build -q - ) && [ -n "$$BUILD" ] && echo "Built $$BUILD" && \
	echo $$BUILD > mobylinux.tag && \
	docker run --rm --read-only --net=none --log-driver=none --tmpfs /tmp --tmpfs /initrd $$BUILD | \
		docker run --rm --read-only --net=none --log-driver=none --tmpfs /tmp -i $(PAD4_IMAGE) > $@

container.img:
	$(MAKE) -j -C containers
	tar cf - containers/*/rootfs containers/*/config.json | \
		docker run --rm --read-only --net=none --log-driver=none --tmpfs /tmp -i $(TAR2INITRD_IMAGE) > $@

test.img:
	$(MAKE) -j -C test
	tar cf - test/rootfs test/config.json | \
		docker run --rm --read-only --net=none --log-driver=none --tmpfs /tmp -i $(TAR2INITRD_IMAGE) > $@

initrd.img: moby.img container.img
	cat $^ > $@

initrd-test.img: initrd.img test.img
	cat $^ > $@

mobylinux-efi.iso: Dockerfile.efi initrd.img kernel/x86_64/vmlinuz64
	BUILD=$$( tar cf - $^ | docker build -q -f Dockerfile.efi - ) && [ -n "$$BUILD" ] && echo "Built $$BUILD" && \
	docker run --rm --net=none --log-driver=none --cap-add sys_admin $$BUILD cat /tmp/efi/mobylinux.efi > mobylinux.efi && \
	docker run --rm --net=none --log-driver=none --cap-add sys_admin $$BUILD cat /tmp/efi/mobylinux-efi.iso > $@

mobylinux-bios.iso: initrd.img kernel/x86_64/vmlinuz64
	tar cf - initrd.img -C kernel/x86_64 vmlinuz64 | \
		docker run --rm --net=none --log-driver=none -i $(BIOS_IMAGE) >$@

gce: gce.img.tar.gz

gce.img.tar.gz: common
	tar cf - initrd.img -C kernel/x86_64 vmlinuz64 | \
		docker run --rm --net=none --log-driver=none -i $(GCE_IMAGE) >$@

gce-upload:
	docker run -it --rm --volumes-from gcloud-config google/cloud-sdk gsutil cp -a public-read gce.img.tar.gz gs://docker-for-gcp-images/latest/gce.img.tar.gz

common: initrd.img
	$(MAKE) -C kernel
	$(MAKE) -j -C packages
	$(MAKE) -j -C containers

ami: common
	tar cf - \
	  cloud initrd.img kernel/x86_64/vmlinuz64 \
	  | \
	  docker build -t moby-ami:build -f cloud/Dockerfile.ami -
	# The EBS device seems not to show up without mounting in /dev, even
	# with --privileged enabled.
	docker run \
		--rm \
		--privileged \
		-v /dev:/dev \<commit_msg>Complete target to upload to GCE<commit_after>all:	initrd.img initrd-test.img mobylinux-efi.iso mobylinux-bios.iso

ETCFILES=$(shell find etc)

TAG=$(shell git rev-parse HEAD)
STATUS=$(shell git status -s)
ifeq ($(STATUS),)
DIRTY=
else
DIRTY=-dirty
endif

# By default we want to always auth to GCE to upload moby images
FORCE_GSUTIL_AUTH ?= 1

# Tag: 22b043cb43f6bc3bc4e1f1ecf9d64932f9325642
BIOS_IMAGE=mobylinux/mkimage-iso-bios@sha256:7e28f7745fd62284142dce59a137c3331f7673efe8b3f19ee5c65e4cc27ff18c

# Tag: c6c904f82ec47594f7b1a26a76013cd7a53356d8
PAD4_IMAGE=mobylinux/pad4@sha256:0963843b484faa021dc99f67bdfd01c9c1721621fffcf343a68151ae074b2206

# Tag: 1e3cdc45eae37806b692432e010271b3172b7f0a
TAR2INITRD_IMAGE=mobylinux/tar2initrd@sha256:4045cba0df947e449a54d3822f789dc3faad4aa8f04a0d51674ed777f044e159

# Tag: 77bc577875fb3a80ac2d14b70d1daa885bbf199c
GCE_IMAGE=mobylinux/mkimage-gce@sha256:f9abf2eae20984b7dd3c1afb700b2c9c41e39e6e7c688c78348a51d0780d74cc

moby.img: Dockerfile mkinitrd.sh init $(ETCFILES)
	$(MAKE) -C kernel
	$(MAKE) -j -C packages
	printf $(TAG)$(DIRTY) > etc/moby-commit
	BUILD=$$( tar cf - \
	  Dockerfile etc usr init mkinitrd.sh \
	  -C kernel usr etc sbin lib -C .. \
	  -C packages/proxy usr sbin etc -C ../.. \
	  -C packages/transfused sbin etc -C ../.. \
	  -C packages/tap-vsockd sbin etc -C ../.. \
	  -C packages/docker usr etc -C ../.. \
	  -C packages/diagnostics usr etc -C ../.. \
	  -C packages/automount etc -C ../.. \
	  -C packages/hostsettings etc -C ../.. \
	  -C packages/chronyd etc -C ../.. \
	  -C packages/userns etc -C ../.. \
	  -C packages/nc-vsock usr -C ../.. \
	  -C packages/vsudd sbin etc -C ../.. \
	  -C packages/mobyconfig usr -C ../.. \
	  -C packages/mobyplatform usr -C ../.. \
	  -C packages/oom etc -C ../.. \
	  -C packages/9pmount-vsock sbin -C ../.. \
	  -C packages/test etc -C ../.. \
	  -C packages/iptables usr -C ../.. \
	  -C packages/containerd etc -C ../.. \
	  -C packages/aws etc -C ../.. \
	  -C packages/azure etc -C ../.. \
	  -C packages/gcp etc -C ../.. \
	  | \
	  docker build -q - ) && [ -n "$$BUILD" ] && echo "Built $$BUILD" && \
	echo $$BUILD > mobylinux.tag && \
	docker run --rm --read-only --net=none --log-driver=none --tmpfs /tmp --tmpfs /initrd $$BUILD | \
		docker run --rm --read-only --net=none --log-driver=none --tmpfs /tmp -i $(PAD4_IMAGE) > $@

container.img:
	$(MAKE) -j -C containers
	tar cf - containers/*/rootfs containers/*/config.json | \
		docker run --rm --read-only --net=none --log-driver=none --tmpfs /tmp -i $(TAR2INITRD_IMAGE) > $@

test.img:
	$(MAKE) -j -C test
	tar cf - test/rootfs test/config.json | \
		docker run --rm --read-only --net=none --log-driver=none --tmpfs /tmp -i $(TAR2INITRD_IMAGE) > $@

initrd.img: moby.img container.img
	cat $^ > $@

initrd-test.img: initrd.img test.img
	cat $^ > $@

mobylinux-efi.iso: Dockerfile.efi initrd.img kernel/x86_64/vmlinuz64
	BUILD=$$( tar cf - $^ | docker build -q -f Dockerfile.efi - ) && [ -n "$$BUILD" ] && echo "Built $$BUILD" && \
	docker run --rm --net=none --log-driver=none --cap-add sys_admin $$BUILD cat /tmp/efi/mobylinux.efi > mobylinux.efi && \
	docker run --rm --net=none --log-driver=none --cap-add sys_admin $$BUILD cat /tmp/efi/mobylinux-efi.iso > $@

mobylinux-bios.iso: initrd.img kernel/x86_64/vmlinuz64
	tar cf - initrd.img -C kernel/x86_64 vmlinuz64 | \
		docker run --rm --net=none --log-driver=none -i $(BIOS_IMAGE) >$@

gce: gce.img.tar.gz

gce.img.tar.gz: common
	tar cf - initrd.img -C kernel/x86_64 vmlinuz64 | \
		docker run --rm --net=none --log-driver=none -i $(GCE_IMAGE) >$@

gce-upload:
ifeq ($(FORCE_GSUTIL_AUTH),1)
	-docker rm gsutil-moby-config 2>/dev/null
	docker run -it --name gsutil-moby-config google/cloud-sdk gcloud auth login --brief --project=docker-for-gcp
endif
	docker run --rm -ti \
		--volumes-from gsutil-moby-config \
		-v $(CURDIR)/gce.img.tar.gz:/gce.img.tar.gz \
		google/cloud-sdk \
		gsutil cp -a public-read /gce.img.tar.gz gs://docker-for-gcp-templates/latest/gce.img.tar.gz

common: initrd.img
	$(MAKE) -C kernel
	$(MAKE) -j -C packages
	$(MAKE) -j -C containers

ami: common
	tar cf - \
	  cloud initrd.img kernel/x86_64/vmlinuz64 \
	  | \
	  docker build -t moby-ami:build -f cloud/Dockerfile.ami -
	# The EBS device seems not to show up without mounting in /dev, even
	# with --privileged enabled.
	docker run \
		--rm \
		--privileged \
		-v /dev:/dev \
{'fraction_non_alphanumeric': 0.16646848989298454, 'fraction_numerical': 0.07431629013079667, 'mean_word_length': 2.7200353825740824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '5782297', 'n_tokens_mistral': 4020, 'n_tokens_neox': 3503, 'n_words': 772}