Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce idempotent Makefile to run basic.sh in docker #330

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
BaseSystem.img
BaseSystem.dmg
BaseSystem.chunklist
MyDisk.qcow2
80 changes: 80 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
SELF := $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST)))))

# Make sure fully-featured BASH shell is used by this Makefile
SHELL := $(shell which bash)

IMAGE := macos-simple-kvm

DISK_NAME ?= MyDisk
DISK_SIZE ?= 64G

# Embed helper Dockerfile here for simplicity
define DOCKERFILE
FROM ubuntu:rolling

ENV LC_ALL=C.UTF-8 LANG=C.UTF-8

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -q update -y \
&& apt-get -q install -y \
qemu-system \
qemu-utils \
python3 \
python3-pip \
&& apt-get -q autoremove -y \
&& apt-get -q clean -y \
&& rm -rf /var/lib/apt/lists/*

WORKDIR $(SELF)/

ENTRYPOINT []
CMD /bin/bash
endef

# Define helper docker-run macro to simplify rest of the Makefile
define RUN
docker run --rm \
--network="host" \
--privileged="true" \
--device="/dev/dri/" \
-e DISPLAY="$$DISPLAY" \
-v $(SELF)/:$(SELF)/ \
-i $(IMAGE)
endef

# Append audio and hard disk device configuration
define BASIC_SH
$(file < $(SELF)/basic.sh)
-audiodev driver=pa,id=sound1,server=localhost \
-drive id=SystemDisk,if=none,file=MyDisk.qcow2 \
-device ide-hd,bus=sata.4,drive=SystemDisk
endef

export

.PHONY: all

all: basic

.PHONY: build

build:
docker build -t $(IMAGE) - <<< "$$DOCKERFILE"

.PHONY: jumpstart

jumpstart-%: build
[[ -f $(SELF)/BaseSystem.img ]] || $(call RUN) ./jumpstart.sh --$*

jumpstart: jumpstart-catalina

.PHONY: basic

basic: build $(SELF)/BaseSystem.img $(SELF)/MyDisk.qcow2
$(call RUN) bash -s <<< "$$BASIC_SH"

$(SELF)/BaseSystem.img:
@echo "Please run one of the 'jumpstart' variants first!" && exit 1

$(SELF)/$(DISK_NAME).qcow2:
$(call RUN) qemu-img create -f qcow2 $@ $(DISK_SIZE)