calculate manifest hash-tag using git ls-tree

Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
Avi Deitcher
2021-05-10 12:36:07 +03:00
parent c4d8b1a250
commit 4adc04a24d
3 changed files with 51 additions and 25 deletions

View File

@@ -15,10 +15,19 @@ ifeq ($(ARCH), s390x)
DEPS += packages.s390x
endif
ORG?=linuxkit
IMAGE?=alpine
TAG?=$(shell git ls-tree --full-tree HEAD -- $(PWD) | awk '{print $$3}')
DIRTY?=$(shell git diff-index HEAD -- $(PWD))
ifneq ($(DIRTY),)
TAG := $(TAG)-dirty
endif
default: push
show-tag:
@sed -n -e '1s/# \(.*\/.*:[0-9a-f]\{40\}\)/\1/p;q' versions.$(ARCH)
@echo "$(ORG)/$(IMAGE):$(TAG)"
iid: Dockerfile Makefile $(DEPS)
docker build --no-cache --iidfile iid .
@@ -34,9 +43,11 @@ push: hash iid versions.$(ARCH)
docker pull $(ORG)/$(IMAGE):$(shell cat hash) || \
(docker tag $(shell cat iid) $(ORG)/$(IMAGE):$(shell cat hash) && \
docker push $(ORG)/$(IMAGE):$(shell cat hash))
./push-manifest.sh $(ORG) $(IMAGE)
rm -f iid
push-manifest:
./push-manifest.sh $(ORG) $(IMAGE)
build: hash iid versions.$(ARCH)
docker pull $(ORG)/$(IMAGE):$(shell cat hash) || \
docker tag $(shell cat iid) $(ORG)/$(IMAGE):$(shell cat hash)

View File

@@ -17,8 +17,13 @@ IMAGE=$2
IMG_X86_64=$(head -1 versions.x86_64 | sed 's,[#| ]*,,')
IMG_ARM64=$(head -1 versions.aarch64 | sed 's,[#| ]*,,')
IMG_s390x=$(head -1 versions.s390x | sed 's,[#| ]*,,')
# Extract the TAG from the x86_64 name and build the manifest target name
TAG=$(echo "$IMG_X86_64" | sed 's,\-.*$,,' | cut -d':' -f2)
# Extract the TAG from the tree hash - just like how "linuxkit pkg show-tag" does it - name and build the manifest target name
TAG=$(git ls-tree --full-tree HEAD -- $(pwd) | awk '{print $3}')
DIRTY=$(git diff-index HEAD -- $(pwd))
if [ -n "$DIRTY"]; then
echo "will not push out manifest when git tree is dirty" >&2
exit 1
fi
TARGET="$ORG/$IMAGE:$TAG"
YAML=$(mktemp)
@@ -77,4 +82,4 @@ fi
# Push manifest list
OUT=$(manifest-tool $MT_ARGS push from-spec --ignore-missing "$YAML")
rm "$YAML"
echo "$OUT"
echo "$OUT"