support for podman/docker manifest workflow
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Emil Lerch 2020-11-29 13:57:52 -08:00
parent 6449f8100e
commit 978533a3d0
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -30,9 +30,7 @@ BINDIRMODE ?= 777
### These variables should not need tweaking. ### These variables should not need tweaking.
### ###
# So /bin/sh/ sources file at $ENV DKR := $(shell if command -v docker > /dev/null 2>&1; then echo "docker"; else echo "podman"; fi)
SHELL := sh
.SHELLFLAGS := -ic
SRC_DIRS := cmd pkg # directories which hold app source (not vendored) SRC_DIRS := cmd pkg # directories which hold app source (not vendored)
@ -136,7 +134,7 @@ go-build: $(BUILD_DIRS)
@echo "building for $(OS)/$(ARCH)" @echo "building for $(OS)/$(ARCH)"
@mkdir -p "$$(pwd)/.go/bin/$(OS)_$(ARCH)" @mkdir -p "$$(pwd)/.go/bin/$(OS)_$(ARCH)"
@chmod $(BINDIRMODE) "$$(pwd)/.go/bin/$(OS)_$(ARCH)" @chmod $(BINDIRMODE) "$$(pwd)/.go/bin/$(OS)_$(ARCH)"
@docker run \ @$(DKR) run \
--rm \ --rm \
-u $$(id -u):$$(id -g) \ -u $$(id -u):$$(id -g) \
-v $$(pwd):/src \ -v $$(pwd):/src \
@ -159,7 +157,7 @@ go-build: $(BUILD_DIRS)
shell: # @HELP launches a shell in the containerized build environment shell: # @HELP launches a shell in the containerized build environment
shell: $(BUILD_DIRS) shell: $(BUILD_DIRS)
@echo "launching a shell in the containerized build environment" @echo "launching a shell in the containerized build environment"
@docker run \ @$(DKR) run \
-ti \ -ti \
--rm \ --rm \
-u $$(id -u):$$(id -g) \ -u $$(id -u):$$(id -g) \
@ -198,30 +196,50 @@ $(CONTAINER_DOTFILES):
-e 's|{ARG_OS}|$(OS)|g' \ -e 's|{ARG_OS}|$(OS)|g' \
-e 's|{ARG_FROM}|$(BASEIMAGE)|g' \ -e 's|{ARG_FROM}|$(BASEIMAGE)|g' \
Dockerfile.in > .dockerfile-$(BIN)-$(OS)_$(ARCH) Dockerfile.in > .dockerfile-$(BIN)-$(OS)_$(ARCH)
@docker build -t $(REGISTRY)/$(BIN):$(TAG) -f .dockerfile-$(BIN)-$(OS)_$(ARCH) . @$(DKR) build -t $(REGISTRY)/$(BIN):$(TAG) -f .dockerfile-$(BIN)-$(OS)_$(ARCH) .
@docker images -q $(REGISTRY)/$(BIN):$(TAG) > $@ @$(DKR) images -q $(REGISTRY)/$(BIN):$(TAG) > $@
@echo @echo
push: # @HELP pushes the container for one platform ($OS/$ARCH) to the defined registry push: # @HELP pushes the container for one platform ($OS/$ARCH) to the defined registry
push: $(CONTAINER_DOTFILES) push: $(CONTAINER_DOTFILES)
@for bin in $(BINS); do \ @for bin in $(BINS); do \
docker push $(REGISTRY)/$$bin:$(TAG); \ $(DKR) push $(REGISTRY)/$$bin:$(TAG); \
done done
# TODO: Upstream was using manifest-tool and gcloud commands. Needs update # TODO: podman and docker are pretty different wrt manifests and workflow here
# docker is experimental CLI and requires pushed images (which then should probably
# be untagged on the server), podman can push everything at once when the manifest
# is cleaned
manifest-list: # @HELP builds a manifest list of containers for all platforms manifest-list: # @HELP builds a manifest list of containers for all platforms
manifest-list: all-container manifest-list: all-container
@export DOCKER_CLI_EXPERIMENTAL=enabled && \ @export DOCKER_CLI_EXPERIMENTAL=enabled && \
for bin in $(BINS); do \ if $(DKR) --version | grep -q podman; then \
docker manifest create $(REGISTRY)/$$bin:$(VERSION); \ for bin in $(BINS); do \
for platform in $(ALL_PLATFORMS); do \ $(DKR) manifest create $(REGISTRY)/$$bin:$(VERSION); \
docker manifest add --arch $$(echo $$platform | cut -d/ -f2) \ for platform in $(ALL_PLATFORMS); do \
$(REGISTRY)/$$bin:$(VERSION) \ $(DKR) manifest add --arch $$(echo $$platform | cut -d/ -f2) \
$(REGISTRY)/$$bin:$(VERSION)__$$(echo $$platform | sed 's#/#_#g'); \ $(REGISTRY)/$$bin:$(VERSION) \
done; \ $(REGISTRY)/$$bin:$(VERSION)__$$(echo $$platform | sed 's#/#_#g'); \
docker manifest push --all $(REGISTRY)/$$bin:$(VERSION) \ done; \
docker://$(REGISTRY)/$$bin:$(VERSION); \ $(DKR) manifest push --all $(REGISTRY)/$$bin:$(VERSION) \
done docker://$(REGISTRY)/$$bin:$(VERSION); \
done; \
else \
for bin in $(BINS); do \
cmd="$(DKR) manifest create $(REGISTRY)/$$bin:$(VERSION)"; \
for platform in $(ALL_PLATFORMS); do \
cmd="$$cmd $(REGISTRY)/$$bin:$(VERSION)__$$(echo $$platform | sed 's#/#_#g')"; \
$(DKR) push $(REGISTRY)/$$bin:$(VERSION)__$$(echo $$platform | sed 's#/#_#g'); \
done; \
eval "$$cmd"; \
for platform in $(ALL_PLATFORMS); do \
$(DKR) manifest annotate --arch $$(echo $$platform | cut -d/ -f2) \
$(REGISTRY)/$$bin:$(VERSION) \
$(REGISTRY)/$$bin:$(VERSION)__$$(echo $$platform | sed 's#/#_#g'); \
done; \
$(DKR) manifest push $(REGISTRY)/$$bin:$(VERSION); \
done; \
fi
version: # @HELP outputs the version string version: # @HELP outputs the version string
version: version:
@ -229,7 +247,7 @@ version:
test: # @HELP runs tests, as defined in ./build/test.sh test: # @HELP runs tests, as defined in ./build/test.sh
test: $(BUILD_DIRS) test: $(BUILD_DIRS)
@docker run \ @$(DKR) run \
-i \ -i \
--rm \ --rm \
-u $$(id -u):$$(id -g) \ -u $$(id -u):$$(id -g) \
@ -255,14 +273,25 @@ clean: # @HELP removes built binaries and temporary files
clean: container-clean bin-clean clean: container-clean bin-clean
container-clean: container-clean:
@rm -rf .container-* .dockerfile-*; \ @rm -rf .container-* .dockerfile-*; \
for bin in $(BINS); do \ for bin in $(BINS); do \
docker image exists "$(REGISTRY)/$$bin:$(VERSION)" && \ if $(DKR) --version |grep -q podman; then \
docker image rm "$(REGISTRY)/$$bin:$(VERSION)"; \ $(DKR) image exists "$(REGISTRY)/$$bin:$(VERSION)" && \
for platform in $(ALL_PLATFORMS); do \ $(DKR) image rm "$(REGISTRY)/$$bin:$(VERSION)"; \
docker image exists "$(REGISTRY)/$$bin:$(VERSION)__$$(echo $$platform | sed 's#/#_#g')" && \ else \
docker image rm "$(REGISTRY)/$$bin:$(VERSION)__$$(echo $$platform | sed 's#/#_#g')"; \ $(DKR) image rm "$(REGISTRY)/$$bin:$(VERSION)"; \
done \ fi; \
for platform in $(ALL_PLATFORMS); do \
if $(DKR) --version |grep -q podman; then \
$(DKR) image exists \
"$(REGISTRY)/$$bin:$(VERSION)__$$(echo $$platform | sed 's#/#_#g')" && \
$(DKR) image rm \
"$(REGISTRY)/$$bin:$(VERSION)__$$(echo $$platform | sed 's#/#_#g')"; \
else \
$(DKR) image rm \
"$(REGISTRY)/$$bin:$(VERSION)__$$(echo $$platform | sed 's#/#_#g')"; \
fi; \
done; \
done; true done; true
bin-clean: bin-clean: