From 630150309520fd34891ee5c8cf371dab0a91db74 Mon Sep 17 00:00:00 2001 From: Julien Viard de Galbert Date: Thu, 15 Apr 2021 21:12:10 +0200 Subject: [PATCH 1/2] Makefile: handle a private registry --- Dockerfile | 2 +- Makefile | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2ef1178..2b2402f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ARG FROM=alpine -FROM alpine AS cni +FROM $FROM AS cni ARG GOARCH=amd64 ARG CNI_PLUGINS_VERSION=v0.9.1 RUN apk add --no-cache curl && \ diff --git a/Makefile b/Makefile index 40a5720..8a9e443 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,10 @@ PROJECT := kilo PKG := github.com/squat/$(PROJECT) REGISTRY ?= index.docker.io IMAGE ?= squat/$(PROJECT) +ifneq ($(REGISTRY),index.docker.io) + REGISTRY_PREFIX := $(REGISTRY)/ +endif +FULLY_QUALIFIED_IMAGE := $(REGISTRY_PREFIX)$(IMAGE) TAG := $(shell git describe --abbrev=0 --tags HEAD 2>/dev/null) COMMIT := $(shell git rev-parse HEAD) @@ -243,7 +247,7 @@ container: .container-$(ARCH)-$(VERSION) container-name @docker images -q $(IMAGE):$(ARCH)-$(VERSION) > $@ container-latest: .container-$(ARCH)-$(VERSION) - @docker tag $(IMAGE):$(ARCH)-$(VERSION) $(IMAGE):$(ARCH)-latest + @docker tag $(IMAGE):$(ARCH)-$(VERSION) $(REGISTRY_PREFIX)$(IMAGE):$(ARCH)-latest @echo "container: $(IMAGE):$(ARCH)-latest" container-name: @@ -251,14 +255,15 @@ container-name: manifest: .manifest-$(VERSION) manifest-name .manifest-$(VERSION): Dockerfile $(addprefix push-, $(ALL_ARCH)) - @docker manifest create --amend $(IMAGE):$(VERSION) $(addsuffix -$(VERSION), $(addprefix squat/$(PROJECT):, $(ALL_ARCH))) + @docker manifest create --amend $(FULLY_QUALIFIED_IMAGE):$(VERSION) $(addsuffix -$(VERSION), $(addprefix $(FULLY_QUALIFIED_IMAGE):, $(ALL_ARCH))) @$(MAKE) --no-print-directory manifest-annotate-$(VERSION) - @docker manifest push $(IMAGE):$(VERSION) > $@ + @docker manifest push $(FULLY_QUALIFIED_IMAGE):$(VERSION) > $@ manifest-latest: Dockerfile $(addprefix push-latest-, $(ALL_ARCH)) - @docker manifest create --amend $(IMAGE):latest $(addsuffix -latest, $(addprefix squat/$(PROJECT):, $(ALL_ARCH))) + @docker manifest rm $(FULLY_QUALIFIED_IMAGE):latest || echo no old manifest + @docker manifest create --amend $(FULLY_QUALIFIED_IMAGE):latest $(addsuffix -latest, $(addprefix $(FULLY_QUALIFIED_IMAGE):, $(ALL_ARCH))) @$(MAKE) --no-print-directory manifest-annotate-latest - @docker manifest push $(IMAGE):latest + @docker manifest push $(FULLY_QUALIFIED_IMAGE):latest @echo "manifest: $(IMAGE):latest" manifest-annotate: manifest-annotate-$(VERSION) @@ -269,7 +274,7 @@ manifest-annotate-%: annotate=; \ j=0; for da in $(DOCKER_ARCH); do \ if [ "$$j" -eq "$$i" ] && [ -n "$$da" ]; then \ - annotate="docker manifest annotate $(IMAGE):$* $(IMAGE):$$a-$* --os linux --arch"; \ + annotate="docker manifest annotate $(FULLY_QUALIFIED_IMAGE):$* $(FULLY_QUALIFIED_IMAGE):$$a-$* --os linux --arch"; \ k=0; for ea in $$da; do \ [ "$$k" = 0 ] && annotate="$$annotate $$ea"; \ [ "$$k" != 0 ] && annotate="$$annotate --variant $$ea"; \ @@ -283,10 +288,13 @@ manifest-annotate-%: done manifest-name: - @echo "manifest: $(IMAGE_ROOT):$(VERSION)" + @echo "manifest: $(IMAGE):$(VERSION)" push: .push-$(ARCH)-$(VERSION) push-name .push-$(ARCH)-$(VERSION): .container-$(ARCH)-$(VERSION) +ifneq ($(REGISTRY_PREFIX),) + @docker tag $(IMAGE):$(ARCH)-$(VERSION) $(REGISTRY)/$(IMAGE):$(ARCH)-$(VERSION) +endif @docker push $(REGISTRY)/$(IMAGE):$(ARCH)-$(VERSION) @docker images -q $(IMAGE):$(ARCH)-$(VERSION) > $@ From e51a8c92cf68c87682706045b8a7117141349c71 Mon Sep 17 00:00:00 2001 From: Julien Viard de Galbert Date: Tue, 11 May 2021 16:17:25 +0200 Subject: [PATCH 2/2] Drop intermediate REGISTRY_PREFIX variable and use FULLY_QUALIFIED_IMAGE more consistently TODO: test this on docker hub --- Makefile | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 8a9e443..92c9c0c 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,7 @@ PROJECT := kilo PKG := github.com/squat/$(PROJECT) REGISTRY ?= index.docker.io IMAGE ?= squat/$(PROJECT) -ifneq ($(REGISTRY),index.docker.io) - REGISTRY_PREFIX := $(REGISTRY)/ -endif -FULLY_QUALIFIED_IMAGE := $(REGISTRY_PREFIX)$(IMAGE) +FULLY_QUALIFIED_IMAGE := $(REGISTRY)/$(IMAGE) TAG := $(shell git describe --abbrev=0 --tags HEAD 2>/dev/null) COMMIT := $(shell git rev-parse HEAD) @@ -247,7 +244,7 @@ container: .container-$(ARCH)-$(VERSION) container-name @docker images -q $(IMAGE):$(ARCH)-$(VERSION) > $@ container-latest: .container-$(ARCH)-$(VERSION) - @docker tag $(IMAGE):$(ARCH)-$(VERSION) $(REGISTRY_PREFIX)$(IMAGE):$(ARCH)-latest + @docker tag $(IMAGE):$(ARCH)-$(VERSION) $(FULLY_QUALIFIED_IMAGE):$(ARCH)-latest @echo "container: $(IMAGE):$(ARCH)-latest" container-name: @@ -292,14 +289,14 @@ manifest-name: push: .push-$(ARCH)-$(VERSION) push-name .push-$(ARCH)-$(VERSION): .container-$(ARCH)-$(VERSION) -ifneq ($(REGISTRY_PREFIX),) - @docker tag $(IMAGE):$(ARCH)-$(VERSION) $(REGISTRY)/$(IMAGE):$(ARCH)-$(VERSION) +ifneq ($(REGISTRY),index.docker.io) + @docker tag $(IMAGE):$(ARCH)-$(VERSION) $(FULLY_QUALIFIED_IMAGE):$(ARCH)-$(VERSION) endif - @docker push $(REGISTRY)/$(IMAGE):$(ARCH)-$(VERSION) + @docker push $(FULLY_QUALIFIED_IMAGE):$(ARCH)-$(VERSION) @docker images -q $(IMAGE):$(ARCH)-$(VERSION) > $@ push-latest: container-latest - @docker push $(REGISTRY)/$(IMAGE):$(ARCH)-latest + @docker push $(FULLY_QUALIFIED_IMAGE):$(ARCH)-latest @echo "pushed: $(IMAGE):$(ARCH)-latest" push-name: