Skip to content

Instantly share code, notes, and snippets.

@miekg
Created January 13, 2018 12:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miekg/7a9b34a29ff907fb0621d75a5013871b to your computer and use it in GitHub Desktop.
Save miekg/7a9b34a29ff907fb0621d75a5013871b to your computer and use it in GitHub Desktop.
# Makefile for building our Docker containers
#
# You can override ARCH and REGISTRY, the default to "amd64 arm arm64 ppc64le s390x" and "miek"
# If you need to get an asset before building use the asset rule. The asset needs to be copied
# to $(arch):
#
# asset:
# cp $(COREDNS)/coredns $(arch)/coredns
ifeq (, $(shell which manifest-tool))
$(error No manifest-tool in $$PATH, install with: "go get github.com/estesp/manifest-tool")
endif
# Limit architectures we push, full list is: amd64 arm arm64 ppc64le s390x
REGISTRY:=miek
ifeq ($(ARCH),)
$(error Please specify architectures use. Full list is "amd64 arm arm64 ppc64le s390x")
endif
DIR:=$(shell basename $$PWD)
IMAGE=$(REGISTRY)/$(DIR)
EMPTY:=
SPACE:=$(EMPTY) $(EMPTY)
COMMA:=$(EMPTY),$(EMPTY)
PLATFORMS:=$(subst $(SPACE),$(COMMA),$(foreach arch,$(ARCH),linux/$(arch)))
.PHONY: build
build:
for a in $(ARCH); do \
mkdir -p $$a ;\
cp * $$a 2>/dev/null ;\
make arch=$$a asset ;\
../../bin/dockerfile $$a > $$a/Dockerfile ;\
docker build -t $(IMAGE):$(VERSION) $$a && \
rm -rf $$a ;\
docker tag $(IMAGE):$(VERSION) $(IMAGE)-$$a ;\
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest ;\
done
.PHONY: push
push:
for a in $(ARCH); do \
docker push $(IMAGE)-$$a ;\
done
manifest-tool push from-args --platforms $(PLATFORMS) --template $(IMAGE)-ARCH --target $(IMAGE):$(VERSION)
manifest-tool push from-args --platforms $(PLATFORMS) --template $(IMAGE)-ARCH --target $(IMAGE):latest
.PHONY: clean
clean:
rm -rf $(ARCH)
.PHONY: asset
asset:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment