From 43ca5f5ef188db9dd88406ba3875310131d32c0a Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Wed, 19 Aug 2020 21:20:40 -0400 Subject: [PATCH] Add new Dockerfile label org.opencontainers.image.revision --- Makefile | 10 ++++++---- build/build-plugin.sh | 4 ++-- build/build.sh | 8 ++++---- cloudbuild.yaml | 1 - rootfs/Dockerfile | 2 ++ 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 492fa34e6..ceccf63c8 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ E2E_NODES ?= 8 E2E_CHECK_LEAKS ?= REPO_INFO ?= $(shell git config --get remote.origin.url) -GIT_COMMIT ?= git-$(shell git rev-parse --short HEAD) +COMMIT_SHA ?= git-$(shell git rev-parse --short HEAD) PKG = k8s.io/ingress-nginx @@ -65,6 +65,7 @@ image: clean-image ## Build image for a particular arch. --build-arg BASE_IMAGE="$(BASE_IMAGE)" \ --build-arg VERSION="$(TAG)" \ --build-arg TARGETARCH="$(ARCH)" \ + --build-arg COMMIT_SHA="$(COMMIT_SHA)" \ -t $(REGISTRY)/controller:$(TAG) rootfs .PHONY: clean-image @@ -77,7 +78,7 @@ build: ## Build ingress controller, debug tool and pre-stop hook. @build/run-in-docker.sh \ PKG=$(PKG) \ ARCH=$(ARCH) \ - GIT_COMMIT=$(GIT_COMMIT) \ + COMMIT_SHA=$(COMMIT_SHA) \ REPO_INFO=$(REPO_INFO) \ TAG=$(TAG) \ GOBUILD_FLAGS=$(GOBUILD_FLAGS) \ @@ -88,7 +89,7 @@ build-plugin: ## Build ingress-nginx krew plugin. @build/run-in-docker.sh \ PKG=$(PKG) \ ARCH=$(ARCH) \ - GIT_COMMIT=$(GIT_COMMIT) \ + COMMIT_SHA=$(COMMIT_SHA) \ REPO_INFO=$(REPO_INFO) \ TAG=$(TAG) \ GOBUILD_FLAGS=$(GOBUILD_FLAGS) \ @@ -108,7 +109,7 @@ test: ## Run go unit tests. @build/run-in-docker.sh \ PKG=$(PKG) \ ARCH=$(ARCH) \ - GIT_COMMIT=$(GIT_COMMIT) \ + COMMIT_SHA=$(COMMIT_SHA) \ REPO_INFO=$(REPO_INFO) \ TAG=$(TAG) \ GOBUILD_FLAGS=$(GOBUILD_FLAGS) \ @@ -213,4 +214,5 @@ release: ensure-buildx clean --platform $(subst $(SPACE),$(COMMA),$(PLATFORMS)) \ --build-arg BASE_IMAGE="$(BASE_IMAGE)" \ --build-arg VERSION="$(TAG)" \ + --build-arg COMMIT_SHA="$(COMMIT_SHA)" \ -t $(REGISTRY)/controller:$(TAG) rootfs diff --git a/build/build-plugin.sh b/build/build-plugin.sh index d404e5e26..f311377ea 100755 --- a/build/build-plugin.sh +++ b/build/build-plugin.sh @@ -26,7 +26,7 @@ declare -a mandatory mandatory=( PKG ARCH - GIT_COMMIT + COMMIT_SHA REPO_INFO TAG ) @@ -56,7 +56,7 @@ function build_for_arch(){ "${GOBUILD_FLAGS}" \ -ldflags "-s -w \ -X ${PKG}/version.RELEASE=${TAG} \ - -X ${PKG}/version.COMMIT=${GIT_COMMIT} \ + -X ${PKG}/version.COMMIT=${COMMIT_SHA} \ -X ${PKG}/version.REPO=${REPO_INFO}" \ -o "${release}/kubectl-ingress_nginx${extension}" "${PKG}/cmd/plugin" diff --git a/build/build.sh b/build/build.sh index 3c235d598..33b56b31f 100755 --- a/build/build.sh +++ b/build/build.sh @@ -26,7 +26,7 @@ declare -a mandatory mandatory=( PKG ARCH - GIT_COMMIT + COMMIT_SHA REPO_INFO TAG ) @@ -49,20 +49,20 @@ export GOARCH=${ARCH} go build \ -ldflags "-s -w \ -X ${PKG}/version.RELEASE=${TAG} \ - -X ${PKG}/version.COMMIT=${GIT_COMMIT} \ + -X ${PKG}/version.COMMIT=${COMMIT_SHA} \ -X ${PKG}/version.REPO=${REPO_INFO}" \ -o "rootfs/bin/${ARCH}/nginx-ingress-controller" "${PKG}/cmd/nginx" go build \ -ldflags "-s -w \ -X ${PKG}/version.RELEASE=${TAG} \ - -X ${PKG}/version.COMMIT=${GIT_COMMIT} \ + -X ${PKG}/version.COMMIT=${COMMIT_SHA} \ -X ${PKG}/version.REPO=${REPO_INFO}" \ -o "rootfs/bin/${ARCH}/dbg" "${PKG}/cmd/dbg" go build \ -ldflags "-s -w \ -X ${PKG}/version.RELEASE=${TAG} \ - -X ${PKG}/version.COMMIT=${GIT_COMMIT} \ + -X ${PKG}/version.COMMIT=${COMMIT_SHA} \ -X ${PKG}/version.REPO=${REPO_INFO}" \ -o "rootfs/bin/${ARCH}/wait-shutdown" "${PKG}/cmd/waitshutdown" diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 89b2135d4..fbb549b57 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -8,7 +8,6 @@ steps: entrypoint: bash env: - DOCKER_CLI_EXPERIMENTAL=enabled - - GIT_COMMIT=$_GIT_TAG - REGISTRY=gcr.io/k8s-staging-ingress-nginx - REPO_INFO=https://github.com/kubernetes/ingress-nginx - HOME=/root diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile index 4141ff4e9..2d523d618 100644 --- a/rootfs/Dockerfile +++ b/rootfs/Dockerfile @@ -18,6 +18,7 @@ FROM ${BASE_IMAGE} ARG TARGETARCH ARG VERSION +ARG COMMIT_SHA LABEL org.opencontainers.image.title="NGINX Ingress Controller for Kubernetes" LABEL org.opencontainers.image.documentation="https://kubernetes.github.io/ingress-nginx/" @@ -25,6 +26,7 @@ LABEL org.opencontainers.image.source="https://github.com/kubernetes/ingress-ngi LABEL org.opencontainers.image.vendor="The Kubernetes Authors" LABEL org.opencontainers.image.licenses="Apache-2.0" LABEL org.opencontainers.image.version="${VERSION}" +LABEL org.opencontainers.image.revision="${COMMIT_SHA}" WORKDIR /etc/nginx