2019-02-20 22:10:38 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
|
|
|
|
SHELL := /bin/sh
|
2019-05-05 11:18:03 +00:00
|
|
|
.SHELLFLAGS := -eu -c
|
2019-02-20 22:10:38 +00:00
|
|
|
|
|
|
|
DOCKER := $(shell command -v docker 2>/dev/null)
|
|
|
|
GIT := $(shell command -v git 2>/dev/null)
|
|
|
|
|
|
|
|
DISTDIR := ./dist
|
2019-06-01 12:06:51 +00:00
|
|
|
VERSION_FILE = ./VERSION
|
|
|
|
DOCKERFILE := ./Dockerfile
|
2019-02-20 22:10:38 +00:00
|
|
|
|
2019-06-01 12:06:51 +00:00
|
|
|
IMAGE_REGISTRY := docker.io
|
2019-02-20 22:10:38 +00:00
|
|
|
IMAGE_NAMESPACE := hectormolinero
|
2019-06-01 12:06:51 +00:00
|
|
|
IMAGE_PROJECT := qemu-reactos
|
|
|
|
IMAGE_NAME := $(IMAGE_REGISTRY)/$(IMAGE_NAMESPACE)/$(IMAGE_PROJECT)
|
2019-02-20 22:10:38 +00:00
|
|
|
|
2019-06-01 12:06:51 +00:00
|
|
|
IMAGE_VERSION := v0
|
|
|
|
ifneq ($(wildcard $(VERSION_FILE)),)
|
|
|
|
IMAGE_VERSION := $(shell cat '$(VERSION_FILE)')
|
2019-02-20 22:10:38 +00:00
|
|
|
endif
|
|
|
|
|
2019-06-01 12:06:51 +00:00
|
|
|
IMAGE_TARBALL := $(DISTDIR)/$(IMAGE_PROJECT).txz
|
2019-05-05 11:18:03 +00:00
|
|
|
|
2019-02-20 22:10:38 +00:00
|
|
|
##################################################
|
|
|
|
## "all" target
|
|
|
|
##################################################
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: save-image
|
|
|
|
|
|
|
|
##################################################
|
|
|
|
## "build-*" targets
|
|
|
|
##################################################
|
|
|
|
|
|
|
|
.PHONY: build-image
|
|
|
|
build-image:
|
|
|
|
'$(DOCKER)' build \
|
2019-06-01 12:06:51 +00:00
|
|
|
--tag '$(IMAGE_NAME):$(IMAGE_VERSION)' \
|
|
|
|
--tag '$(IMAGE_NAME):latest' \
|
2019-05-05 11:18:03 +00:00
|
|
|
--file '$(DOCKERFILE)' ./
|
2019-02-20 22:10:38 +00:00
|
|
|
|
|
|
|
##################################################
|
|
|
|
## "save-*" targets
|
|
|
|
##################################################
|
|
|
|
|
|
|
|
define save_image
|
2019-06-01 12:06:51 +00:00
|
|
|
'$(DOCKER)' save '$(1)' | xz -T0 > '$(2)'
|
2019-02-20 22:10:38 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
.PHONY: save-image
|
|
|
|
save-image: $(IMAGE_TARBALL)
|
|
|
|
|
|
|
|
$(IMAGE_TARBALL): build-image
|
|
|
|
mkdir -p '$(DISTDIR)'
|
2019-06-01 12:06:51 +00:00
|
|
|
$(call save_image,$(IMAGE_NAME):$(IMAGE_VERSION),$@)
|
2019-02-20 22:10:38 +00:00
|
|
|
|
|
|
|
##################################################
|
|
|
|
## "load-*" targets
|
|
|
|
##################################################
|
|
|
|
|
|
|
|
define load_image
|
|
|
|
'$(DOCKER)' load -i '$(1)'
|
|
|
|
endef
|
|
|
|
|
|
|
|
define tag_image
|
|
|
|
'$(DOCKER)' tag '$(1)' '$(2)'
|
|
|
|
endef
|
|
|
|
|
|
|
|
.PHONY: load-image
|
|
|
|
load-image:
|
|
|
|
$(call load_image,$(IMAGE_TARBALL))
|
2019-06-01 12:06:51 +00:00
|
|
|
$(call tag_image,$(IMAGE_NAME):$(IMAGE_VERSION),$(IMAGE_NAME):latest)
|
2019-02-20 22:10:38 +00:00
|
|
|
|
|
|
|
##################################################
|
|
|
|
## "push-*" targets
|
|
|
|
##################################################
|
|
|
|
|
|
|
|
define push_image
|
|
|
|
'$(DOCKER)' push '$(1)'
|
|
|
|
endef
|
|
|
|
|
|
|
|
.PHONY: push-image
|
|
|
|
push-image:
|
2019-06-01 12:06:51 +00:00
|
|
|
$(call push_image,$(IMAGE_NAME):$(IMAGE_VERSION))
|
|
|
|
$(call push_image,$(IMAGE_NAME):latest)
|
2019-02-20 22:10:38 +00:00
|
|
|
|
|
|
|
##################################################
|
|
|
|
## "version" target
|
|
|
|
##################################################
|
|
|
|
|
|
|
|
.PHONY: version
|
|
|
|
version:
|
|
|
|
@if printf -- '%s' '$(IMAGE_VERSION)' | grep -q '^v[0-9]\{1,\}$$'; then \
|
|
|
|
NEW_IMAGE_VERSION=$$(awk -v 'v=$(IMAGE_VERSION)' 'BEGIN {printf "v%.0f", substr(v,2)+1}'); \
|
|
|
|
printf -- '%s\n' "$${NEW_IMAGE_VERSION}" > ./VERSION; \
|
|
|
|
'$(GIT)' add ./VERSION; '$(GIT)' commit -m "$${NEW_IMAGE_VERSION}"; \
|
|
|
|
'$(GIT)' tag -a "$${NEW_IMAGE_VERSION}" -m "$${NEW_IMAGE_VERSION}"; \
|
|
|
|
else \
|
|
|
|
>&2 printf -- 'Malformed version string: %s\n' '$(IMAGE_VERSION)'; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
##################################################
|
|
|
|
## "clean" target
|
|
|
|
##################################################
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
rm -f '$(IMAGE_TARBALL)'
|
2019-06-02 08:42:23 +00:00
|
|
|
if [ -d '$(DISTDIR)' ] && [ -z "$$(ls -A '$(DISTDIR)')" ]; then rmdir '$(DISTDIR)'; fi
|