Skip to content

Commit

Permalink
qcow2-fuse experiments in Docker
Browse files Browse the repository at this point in the history
Still suffering from vasi/qcow2-fuse#4
  • Loading branch information
twz123 committed Mar 15, 2022
1 parent c4e2bb6 commit 385c972
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/id_rsa.pub
/image/alpine-make-vm-image

.docker-image.*
*.tmp

# Created by https://www.toptal.com/developers/gitignore/api/terraform
Expand Down
14 changes: 14 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG ALPINE_VERSION
FROM docker.io/library/alpine:$ALPINE_VERSION
# https://github.com/vasi/qcow2-fuse/issues/4
RUN set -ex \
&& apk add libgcc fuse qemu-img \
&& apk add --virtual .build-deps \
curl \
rust \
cargo \
fuse-dev \
pkgconf \
&& cargo install --root /usr/local qcow2-fuse \
&& apk del .build-deps \
&& rm -rf /tmp/* /var/cache/apk/* /root/.cargo
32 changes: 30 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ QEMU_IMG = qemu-img
JQ = jq
SSH = ssh

alpine.branch = v3.15
alpine.version = 3.15
alpine.qcow2.size = 8G
alpine.qcow2.opts = -o nocow=on
alpine-make-vm-image.url = https://raw.githubusercontent.com/alpinelinux/alpine-make-vm-image/v0.8.0/alpine-make-vm-image
Expand All @@ -27,14 +27,40 @@ destroy:
$(TF) destroy -auto-approve
-rm terraform.tfstate terraform.tfstate.backup

.docker-image.%: Dockerfile.%
docker build --iidfile '[email protected]' --build-arg ALPINE_VERSION='$(alpine.version)' - <'$^'
mv -- '[email protected]' '$@'

.PHONY: docker-test
docker-test: .docker-image.build
docker-test: QEMU_IMG = docker run --rm \
--volume '$(CURDIR):/build' --workdir /build \
--user $(shell id -u):$(shell id -g) \
--entrypoint qemu-img \
'$(shell cat .docker-image.build)'
docker-test: SUDO = docker run --rm \
--volume '$(CURDIR):/build' --workdir /build \
'$(shell cat .docker-image.build)'
docker-test: alpine.qcow2

# $(eval image_format = $(patsubst .%,%,$(suffix $@)))
# @echo Building $@ ...
# $(MAKE) alpine.qcow2 QEMU_IMG='docker run --rm $(shell cat .docker-image.build) --user $(shell id -u):$(shell id -g)'

# @[ ! -f '$@' ] || rm -f -- '$@'
# docker run --rm docker.io/library/alpine:'$(alpine.branch)' \
# --user '$(shell id -u):$(shell id -g)' \
# sh -c
# -rm terraform.tfstate terraform.tfstate.backup

alpine.qcow2: image/alpine-make-vm-image image/packages image/build.sh
$(eval image_format = $(patsubst .%,%,$(suffix $@)))
@echo Building $@ ...
@[ ! -f '$@' ] || rm -f -- '$@'
@{ \
$(QEMU_IMG) create -f '$(image_format)' $($@.opts) '[email protected]' '$([email protected])' \
&& $(SUDO) image/alpine-make-vm-image \
--branch '$(alpine.branch)' \
--branch 'v$(alpine.version)' \
--image-format '$(image_format)' \
--packages '$(shell cat image/packages)' \
--script-chroot \
Expand Down Expand Up @@ -70,6 +96,8 @@ clean:
-rm -f image/alpine-make-vm-image alpine.qcow2 alpine.qcow2.tmp
-rm -rf .terraform
-rm id_rsa id_rsa.pub
-docker rmi "$(shell cat .docker-image.*)"
-rm .docker-image.*

.terraform.lock.hcl: main.tf
$(TF) init

0 comments on commit 385c972

Please sign in to comment.