Skip to content

Commit

Permalink
Merge pull request #189 from deitch/release-3.2-manifest
Browse files Browse the repository at this point in the history
Release 3.2 manifest
  • Loading branch information
tomdee authored Sep 14, 2018
2 parents dea9808 + 8d33192 commit 181228f
Showing 1 changed file with 85 additions and 61 deletions.
146 changes: 85 additions & 61 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ ifeq ($(ARCH),x86_64)
override ARCH=amd64
endif

# we want to be able to run the same recipe on multiple targets keyed on the image name
# to do that, we would use the entire image name, e.g. calico/node:abcdefg, as the stem, or '%', in the target
# however, make does **not** allow the usage of invalid filename characters - like / and : - in a stem, and thus errors out
# to get around that, we "escape" those characters by converting all : to --- and all / to ___ , so that we can use them
# in the target, we then unescape them back
escapefs = $(subst :,---,$(subst /,___,$(1)))
unescapefs = $(subst ---,:,$(subst ___,/,$(1)))

# these macros create a list of valid architectures for pushing manifests
space :=
space +=
comma := ,
prefix_linux = $(addprefix linux/,$(strip $1))
join_platforms = $(subst $(space),$(comma),$(call prefix_linux,$(strip $1)))


# Targets used when cross building.
.PHONY: register
# Enable binfmt adding support for miscellaneous binary formats.
Expand All @@ -55,9 +71,27 @@ VALIDARCHES = $(filter-out $(EXCLUDEARCH),$(ARCHES))


###############################################################################
CONTAINER_NAME=calico/typha
BUILD_IMAGE=calico/typha
PACKAGE_NAME?=github.com/projectcalico/typha

PUSH_IMAGES?=$(BUILD_IMAGE) quay.io/calico/typha
RELEASE_IMAGES?=gcr.io/projectcalico-org/typha eu.gcr.io/projectcalico-org/typha asia.gcr.io/projectcalico-org/typha us.gcr.io/projectcalico-org/typha

# If this is a release, also tag and push additional images.
ifeq ($(RELEASE),true)
PUSH_IMAGES+=$(RELEASE_IMAGES)
endif

# remove from the list to push to manifest any registries that do not support multi-arch
EXCLUDE_MANIFEST_REGISTRIES ?= quay.io/
PUSH_MANIFEST_IMAGES=$(PUSH_IMAGES:$(EXCLUDE_MANIFEST_REGISTRIES)%=)
PUSH_NONMANIFEST_IMAGES=$(filter-out $(PUSH_MANIFEST_IMAGES),$(PUSH_IMAGES))

# location of docker credentials to push manifests
DOCKER_CONFIG ?= $(HOME)/.docker/config.json



GO_BUILD_VER?=v0.17
# For building, we use the go-build image for the *host* architecture, even if the target is different
# the one for the host should contain all the necessary cross-compilation tools
Expand Down Expand Up @@ -202,8 +236,8 @@ bin/typha-client-$(ARCH): $(SRC_FILES) vendor/.up-to-date
# Building the image
###############################################################################
# Build the calico/typha docker image, which contains only typha.
.PHONY: calico/typha calico/typha-$(ARCH)
image: $(CONTAINER_NAME)
.PHONY: $(BUILD_IMAGE) $(BUILD_IMAGE)-$(ARCH)
image: $(BUILD_IMAGE)

# Build the image for the target architecture
.PHONY: image-all
Expand All @@ -212,14 +246,14 @@ sub-image-%:
$(MAKE) image ARCH=$*

# Build the calico/typha docker image, which contains only Typha.
.PHONY: image $(CONTAINER_NAME)
$(CONTAINER_NAME): bin/calico-typha-$(ARCH) register
.PHONY: image $(BUILD_IMAGE)
$(BUILD_IMAGE): bin/calico-typha-$(ARCH) register
rm -rf docker-image/bin
mkdir -p docker-image/bin
cp bin/calico-typha-$(ARCH) docker-image/bin/
docker build --pull -t $(CONTAINER_NAME):latest-$(ARCH) --build-arg QEMU_IMAGE=$(CALICO_BUILD) --file ./docker-image/Dockerfile.$(ARCH) docker-image
docker build --pull -t $(BUILD_IMAGE):latest-$(ARCH) --build-arg QEMU_IMAGE=$(CALICO_BUILD) --file ./docker-image/Dockerfile.$(ARCH) docker-image
ifeq ($(ARCH),amd64)
docker tag $(CONTAINER_NAME):latest-$(ARCH) $(CONTAINER_NAME):latest
docker tag $(BUILD_IMAGE):latest-$(ARCH) $(BUILD_IMAGE):latest
endif

# ensure we have a real imagetag
Expand All @@ -229,54 +263,44 @@ ifndef IMAGETAG
endif

## push one arch
push: imagetag
docker push $(CONTAINER_NAME):$(IMAGETAG)-$(ARCH)
docker push quay.io/$(CONTAINER_NAME):$(IMAGETAG)-$(ARCH)

# Push images to gcr.io, used by GKE.
if [ "$(RELEASE)" = "true" ]; then \
docker push gcr.io/projectcalico-org/typha:$(IMAGETAG)-$(ARCH) && \
docker push eu.gcr.io/projectcalico-org/typha:$(IMAGETAG)-$(ARCH) && \
docker push asia.gcr.io/projectcalico-org/typha:$(IMAGETAG)-$(ARCH) && \
docker push us.gcr.io/projectcalico-org/typha:$(IMAGETAG)-$(ARCH); \
fi;
ifeq ($(ARCH),amd64)
docker push $(CONTAINER_NAME):$(IMAGETAG)
docker push quay.io/$(CONTAINER_NAME):$(IMAGETAG)

if [ "$(RELEASE)" = "true" ]; then \
# Push images to gcr.io, used by GKE. Only do this for releases. \
docker push gcr.io/projectcalico-org/typha:$(IMAGETAG) && \
docker push eu.gcr.io/projectcalico-org/typha:$(IMAGETAG) && \
docker push asia.gcr.io/projectcalico-org/typha:$(IMAGETAG) && \
docker push us.gcr.io/projectcalico-org/typha:$(IMAGETAG); \
fi;
endif
push: imagetag $(addprefix sub-single-push-,$(call escapefs,$(PUSH_IMAGES)))

sub-single-push-%:
docker push $(call unescapefs,$*:$(IMAGETAG)-$(ARCH))

## push all archs
push-all: imagetag $(addprefix sub-push-,$(VALIDARCHES))
sub-push-%:
$(MAKE) push ARCH=$* IMAGETAG=$(IMAGETAG)

push-manifests: imagetag $(addprefix sub-manifest-,$(call escapefs,$(PUSH_MANIFEST_IMAGES)))
sub-manifest-%:
# Docker login to hub.docker.com required before running this target as we are using $(DOCKER_CONFIG) holds the docker login credentials
# path to credentials based on manifest-tool's requirements here https://github.com/estesp/manifest-tool#sample-usage
docker run -t --entrypoint /bin/sh -v $(DOCKER_CONFIG):/root/.docker/config.json $(CALICO_BUILD) -c "/usr/bin/manifest-tool push from-args --platforms $(call join_platforms,$(VALIDARCHES)) --template $(call unescapefs,$*:$(IMAGETAG))-ARCH --target $(call unescapefs,$*:$(IMAGETAG))"

## push default amd64 arch where multi-arch manifest is not supported
push-non-manifests: imagetag $(addprefix sub-non-manifest-,$(call escapefs,$(PUSH_NONMANIFEST_IMAGES)))
sub-non-manifest-%:
ifeq ($(ARCH),amd64)
docker push $(call unescapefs,$*:$(IMAGETAG))
else
$(NOECHO) $(NOOP)
endif



## tag images of one arch
tag-images: imagetag
docker tag $(CONTAINER_NAME):latest-$(ARCH) $(CONTAINER_NAME):$(IMAGETAG)-$(ARCH)
docker tag $(CONTAINER_NAME):latest-$(ARCH) quay.io/$(CONTAINER_NAME):$(IMAGETAG)-$(ARCH)

# Tag images for gcr.io, used by GKE.
docker tag $(CONTAINER_NAME):latest-$(ARCH) gcr.io/projectcalico-org/typha:$(IMAGETAG)-$(ARCH)
docker tag $(CONTAINER_NAME):latest-$(ARCH) eu.gcr.io/projectcalico-org/typha:$(IMAGETAG)-$(ARCH)
docker tag $(CONTAINER_NAME):latest-$(ARCH) asia.gcr.io/projectcalico-org/typha:$(IMAGETAG)-$(ARCH)
docker tag $(CONTAINER_NAME):latest-$(ARCH) us.gcr.io/projectcalico-org/typha:$(IMAGETAG)-$(ARCH)
tag-images: imagetag $(addprefix sub-single-tag-images-arch-,$(call escapefs,$(PUSH_IMAGES))) $(addprefix sub-single-tag-images-non-manifest-,$(call escapefs,$(PUSH_NONMANIFEST_IMAGES)))
sub-single-tag-images-arch-%:
docker tag $(BUILD_IMAGE):latest-$(ARCH) $(call unescapefs,$*:$(IMAGETAG)-$(ARCH))

# because some still do not support multi-arch manifest
sub-single-tag-images-non-manifest-%:
ifeq ($(ARCH),amd64)
docker tag $(CONTAINER_NAME):latest-$(ARCH) $(CONTAINER_NAME):$(IMAGETAG)
docker tag $(CONTAINER_NAME):latest-$(ARCH) quay.io/$(CONTAINER_NAME):$(IMAGETAG)

# Tag images for gcr.io, used by GKE.
docker tag $(CONTAINER_NAME):latest-$(ARCH) gcr.io/projectcalico-org/typha:$(IMAGETAG)
docker tag $(CONTAINER_NAME):latest-$(ARCH) eu.gcr.io/projectcalico-org/typha:$(IMAGETAG)
docker tag $(CONTAINER_NAME):latest-$(ARCH) asia.gcr.io/projectcalico-org/typha:$(IMAGETAG)
docker tag $(CONTAINER_NAME):latest-$(ARCH) us.gcr.io/projectcalico-org/typha:$(IMAGETAG)
docker tag $(BUILD_IMAGE):latest-$(ARCH) $(call unescapefs,$*:$(IMAGETAG))
else
$(NOECHO) $(NOOP)
endif

## tag images of all archs
Expand Down Expand Up @@ -349,7 +373,7 @@ endif

## checks that we can get the version
version: image
docker run --rm $(CONTAINER_NAME):latest-$(ARCH) calico-typha --version
docker run --rm $(BUILD_IMAGE):latest-$(ARCH) calico-typha --version

## Builds the code and runs all tests.
ci: image-all version static-checks ut upload-to-coveralls
Expand All @@ -366,13 +390,13 @@ endif
ifndef BRANCH_NAME
$(error BRANCH_NAME is undefined - run using make <target> BRANCH_NAME=var or set an environment variable)
endif
$(MAKE) tag-images-all push-all IMAGETAG=$(BRANCH_NAME) EXCLUDEARCH="$(EXCLUDEARCH)"
$(MAKE) tag-images-all push-all IMAGETAG=$(shell git describe --tags --dirty --always --long) EXCLUDEARCH="$(EXCLUDEARCH)"
$(MAKE) tag-images-all push-all push-manifests push-non-manifests IMAGETAG=$(BRANCH_NAME) EXCLUDEARCH="$(EXCLUDEARCH)"
$(MAKE) tag-images-all push-all push-manifests push-non-manifests IMAGETAG=$(shell git describe --tags --dirty --always --long) EXCLUDEARCH="$(EXCLUDEARCH)"

k8sfv-test: image
cd .. && git clone https://github.com/projectcalico/felix.git && cd felix; \
[ ! -e ../typha/semaphore-felix-branch ] || git checkout $(cat ../typha/semaphore-felix-branch); \
JUST_A_MINUTE=true USE_TYPHA=true FV_TYPHAIMAGE=calico/typha:latest TYPHA_VERSION=latest $(MAKE) k8sfv-test
JUST_A_MINUTE=true USE_TYPHA=true FV_TYPHAIMAGE=$(BUILD_IMAGE):latest TYPHA_VERSION=latest $(MAKE) k8sfv-test


###############################################################################
Expand Down Expand Up @@ -408,15 +432,15 @@ release-build: release-prereqs clean
ifneq ($(VERSION), $(GIT_VERSION))
$(error Attempt to build $(VERSION) from $(GIT_VERSION))
endif
$(MAKE) image
$(MAKE) tag-images IMAGETAG=$(VERSION)
$(MAKE) tag-images IMAGETAG=latest
$(MAKE) image-all
$(MAKE) tag-images-all IMAGETAG=$(VERSION)
$(MAKE) tag-images-all IMAGETAG=latest

## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
# Check the reported version is correct for each release artifact.
docker run --rm $(CONTAINER_NAME):$(VERSION)-$(ARCH) calico-typha --version | grep $(VERSION) || ( echo "Reported version:" `docker run --rm $(CONTAINER_NAME):$(VERSION)-$(ARCH) calico-typha --version` "\nExpected version: $(VERSION)" && exit 1 )
docker run --rm quay.io/$(CONTAINER_NAME):$(VERSION)-$(ARCH) calico-typha --version | grep $(VERSION) || ( echo "Reported version:" `docker run --rm quay.io/$(CONTAINER_NAME):$(VERSION)-$(ARCH) calico-typha --version | grep -x $(VERSION)` "\nExpected version: $(VERSION)" && exit 1 )
docker run --rm $(BUILD_IMAGE):$(VERSION)-$(ARCH) calico-typha --version | grep $(VERSION) || ( echo "Reported version:" `docker run --rm $(BUILD_IMAGE):$(VERSION)-$(ARCH) calico-typha --version` "\nExpected version: $(VERSION)" && exit 1 )
docker run --rm quay.io/$(BUILD_IMAGE):$(VERSION)-$(ARCH) calico-typha --version | grep $(VERSION) || ( echo "Reported version:" `docker run --rm quay.io/$(BUILD_IMAGE):$(VERSION)-$(ARCH) calico-typha --version | grep -x $(VERSION)` "\nExpected version: $(VERSION)" && exit 1 )

# TODO: Some sort of quick validation of the produced binaries.

Expand All @@ -433,7 +457,7 @@ release-publish: release-prereqs
git push origin $(VERSION)

# Push images.
$(MAKE) push RELEASE=true IMAGETAG=$(VERSION) ARCH=$(ARCH)
$(MAKE) push-all RELEASE=true IMAGETAG=$(VERSION)

@echo "Finalize the GitHub release based on the pushed tag."
@echo "Attach the $(DIST)/calico-typha-amd64 binary."
Expand All @@ -450,10 +474,10 @@ release-publish: release-prereqs
## Pushes `latest` release images. WARNING: Only run this for latest stable releases.
release-publish-latest: release-prereqs
# Check latest versions match.
if ! docker run $(CONTAINER_NAME):latest-$(ARCH) calico-typha --version | grep '$(VERSION)'; then echo "Reported version:" `docker run $(CONTAINER_NAME):latest-$(ARCH) calico-typha --version` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi
if ! docker run quay.io/$(CONTAINER_NAME):latest-$(ARCH) calico-typha --version | grep '$(VERSION)'; then echo "Reported version:" `docker run quay.io/$(CONTAINER_NAME):latest-$(ARCH) calico-typha --version` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi
if ! docker run $(BUILD_IMAGE):latest-$(ARCH) calico-typha --version | grep '$(VERSION)'; then echo "Reported version:" `docker run $(BUILD_IMAGE):latest-$(ARCH) calico-typha --version` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi
if ! docker run quay.io/$(BUILD_IMAGE):latest-$(ARCH) calico-typha --version | grep '$(VERSION)'; then echo "Reported version:" `docker run quay.io/$(BUILD_IMAGE):latest-$(ARCH) calico-typha --version` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi

$(MAKE) push RELEASE=true IMAGETAG=latest ARCH=$(ARCH)
$(MAKE) push-all RELEASE=true IMAGETAG=latest

# release-prereqs checks that the environment is configured properly to create a release.
release-prereqs:
Expand Down Expand Up @@ -527,7 +551,7 @@ help:
@echo "Builds:"
@echo
@echo " make all Build all the binary packages."
@echo " make image Build $(CONTAINER_NAME) docker image."
@echo " make image Build $(BUILD_IMAGE) docker image."
@echo
@echo "Tests:"
@echo
Expand Down

0 comments on commit 181228f

Please sign in to comment.