From 96e75e71d6fdd0ea5babb36eb5e486e44ffa8133 Mon Sep 17 00:00:00 2001 From: Krzysztof Ostrowski Date: Fri, 28 Jun 2024 16:18:35 +0200 Subject: [PATCH] Makefile: Introdocue Makefile from master --- .github/workflows/build.yml | 6 +++--- Dockerfile | 4 ++-- Makefile | 35 +++++++++++++++++------------------ 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a4da7227..e787f1970 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,8 +4,8 @@ on: [push, pull_request] env: QUAY_PATH: quay.io/brancz/kube-rbac-proxy - go-version: '1.22.1' - kind-version: 'v0.22.0' + go-version: '1.22.4' + kind-version: 'v0.23.0' jobs: check-license: @@ -71,7 +71,7 @@ jobs: go-version: ${{ env.go-version }} - name: Create container & run tests run: | - VERSION=local make container + VERSION=local VERSION_SEMVER=$(cat ./VERSION) make container kind load docker-image ${QUAY_PATH}:local until docker exec $(kind get nodes) crictl images | grep "${QUAY_PATH}"; do echo "no kube-rbac-proxy image" diff --git a/Dockerfile b/Dockerfile index a937b7857..522b56332 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -ARG GOARCH=amd64 -FROM gcr.io/distroless/static:nonroot-$GOARCH +ARG BASEIMAGE=gcr.io/distroless/static:nonroot-amd64 +FROM $BASEIMAGE ARG BINARY=kube-rbac-proxy-linux-amd64 COPY _output/$BINARY /usr/local/bin/kube-rbac-proxy diff --git a/Makefile b/Makefile index 2f2aa9888..1e9c0c2a0 100644 --- a/Makefile +++ b/Makefile @@ -3,12 +3,14 @@ all: check-license build generate test GO111MODULE=on export GO111MODULE +PROGRAM_NAME?=kube-rbac-proxy GITHUB_URL=github.com/brancz/kube-rbac-proxy GOOS?=$(shell uname -s | tr A-Z a-z) GOARCH?=$(shell go env GOARCH) +BASEIMAGE?=gcr.io/distroless/static:nonroot-$(GOARCH) OUT_DIR=_output -BIN?=kube-rbac-proxy VERSION?=$(shell cat VERSION)-$(shell git rev-parse --short HEAD) +VERSION_SEMVER?=$(shell echo $(VERSION) | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+') PKGS=$(shell go list ./... | grep -v /test/e2e) DOCKER_REPO?=quay.io/brancz/kube-rbac-proxy KUBECONFIG?=$(HOME)/.kube/config @@ -16,7 +18,7 @@ CONTAINER_NAME?=$(DOCKER_REPO):$(VERSION) ALL_ARCH=amd64 arm arm64 ppc64le s390x ALL_PLATFORMS=$(addprefix linux/,$(ALL_ARCH)) -ALL_BINARIES ?= $(addprefix $(OUT_DIR)/$(BIN)-, \ +ALL_BINARIES ?= $(addprefix $(OUT_DIR)/$(PROGRAM_NAME)-, \ $(addprefix linux-,$(ALL_ARCH)) \ darwin-amd64 \ windows-amd64.exe) @@ -33,20 +35,20 @@ check-license: crossbuild: $(ALL_BINARIES) -$(OUT_DIR)/$(BIN): $(OUT_DIR)/$(BIN)-$(GOOS)-$(GOARCH) - cp $(OUT_DIR)/$(BIN)-$(GOOS)-$(GOARCH) $(OUT_DIR)/$(BIN) +$(OUT_DIR)/$(PROGRAM_NAME): $(OUT_DIR)/$(PROGRAM_NAME)-$(GOOS)-$(GOARCH) + cp $(OUT_DIR)/$(PROGRAM_NAME)-$(GOOS)-$(GOARCH) $(OUT_DIR)/$(PROGRAM_NAME) -$(OUT_DIR)/$(BIN)-%: - @echo ">> building for $(GOOS)/$(GOARCH) to $(OUT_DIR)/$(BIN)-$*" +$(OUT_DIR)/$(PROGRAM_NAME)-%: + @echo ">> building for $(GOOS)/$(GOARCH) to $(OUT_DIR)/$(PROGRAM_NAME)-$*" GOARCH=$(word 2,$(subst -, ,$(*:.exe=))) \ GOOS=$(word 1,$(subst -, ,$(*:.exe=))) \ CGO_ENABLED=0 \ - go build --installsuffix cgo -o $(OUT_DIR)/$(BIN)-$* $(GITHUB_URL)/cmd/kube-rbac-proxy + go build --installsuffix cgo -ldflags="-X k8s.io/component-base/version.gitVersion=$(VERSION_SEMVER) -X k8s.io/component-base/version.gitCommit=$(shell git rev-parse HEAD) -X k8s.io/component-base/version/verflag.programName=$(PROGRAM_NAME)" -o $(OUT_DIR)/$(PROGRAM_NAME)-$* $(GITHUB_URL)/cmd/kube-rbac-proxy clean: -rm -r $(OUT_DIR) -build: clean $(OUT_DIR)/$(BIN) +build: clean $(OUT_DIR)/$(PROGRAM_NAME) update-go-deps: @for m in $$(go list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \ @@ -54,16 +56,12 @@ update-go-deps: done go mod tidy -container: $(OUT_DIR)/$(BIN)-$(GOOS)-$(GOARCH) Dockerfile - docker build --build-arg BINARY=$(BIN)-$(GOOS)-$(GOARCH) --build-arg GOARCH=$(GOARCH) -t $(CONTAINER_NAME)-$(GOARCH) . +container: $(OUT_DIR)/$(PROGRAM_NAME)-$(GOOS)-$(GOARCH) Dockerfile + docker build --build-arg BINARY=$(PROGRAM_NAME)-$(GOOS)-$(GOARCH) --build-arg BASEIMAGE=$(BASEIMAGE) -t $(CONTAINER_NAME)-$(GOARCH) . ifeq ($(GOARCH), amd64) docker tag $(DOCKER_REPO):$(VERSION)-$(GOARCH) $(CONTAINER_NAME) endif -container-test: GOOS = linux -container-test: $(OUT_DIR)/$(BIN)-$(GOOS)-$(GOARCH) Dockerfile - docker build --build-arg BINARY=$(BIN)-$(GOOS)-$(GOARCH) --build-arg GOARCH=$(GOARCH) -t $(CONTAINER_NAME) . - manifest-tool: curl -fsSL https://github.com/estesp/manifest-tool/releases/download/v1.0.2/manifest-tool-linux-amd64 > ./manifest-tool chmod +x ./manifest-tool @@ -80,6 +78,9 @@ manifest-push: manifest-tool push: crossbuild manifest-tool $(addprefix push-,$(ALL_ARCH)) manifest-push +test-container: $(OUT_DIR)/$(PROGRAM_NAME)-linux-$(GOARCH) Dockerfile + docker build --build-arg BINARY=$(PROGRAM_NAME)-linux-$(GOARCH) --build-arg BASEIMAGE=$(BASEIMAGE) -t $(CONTAINER_NAME) . + curl-container: docker build -f ./examples/example-client/Dockerfile -t quay.io/brancz/krp-curl:v0.0.2 . @@ -100,11 +101,9 @@ test-e2e: test-local-setup: VERSION = local test-local-setup: VERSION_SEMVER = $(shell cat VERSION) -test-local-setup: container-test kind-create-cluster +test-local-setup: clean test-container kind-create-cluster test-local: test-local-setup test -test-e2e-local: test-local-setup test-e2e - kind-delete-cluster: kind delete cluster @@ -126,4 +125,4 @@ $(TOOLING): $(TOOLS_BIN_DIR) @echo Installing tools from scripts/tools.go @cat scripts/tools.go | grep _ | awk -F'"' '{print $$2}' | GOBIN=$(TOOLS_BIN_DIR) xargs -tI % go install -mod=readonly -modfile=scripts/go.mod % -.PHONY: all check-license crossbuild build container push push-% manifest-push curl-container test test-unit test-e2e generate update-go-deps clean kind-delete-cluster kind-create-cluster +.PHONY: all check-license crossbuild build container push push-% manifest-push test-container curl-container test test-unit test-e2e generate update-go-deps clean kind-delete-cluster kind-create-cluster