Skip to content

Commit

Permalink
add a Makefile for the operator
Browse files Browse the repository at this point in the history
Signed-off-by: Moath Qasim <[email protected]>
  • Loading branch information
moadqassem committed Apr 4, 2023
1 parent 1309a4e commit 018f32f
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
SHELL = /bin/bash -eu -o pipefail

export GOPATH?=$(shell go env GOPATH)
export CGO_ENABLED=0
export GOPROXY?=https://proxy.golang.org
export GO111MODULE=on
export GOFLAGS?=-mod=readonly -trimpath
export GIT_TAG ?= $(shell git tag --points-at HEAD)

GO_VERSION = 1.20.1

CMD = $(notdir $(wildcard ./cmd/*))
BUILD_DEST ?= _build

REGISTRY ?= docker.io
REGISTRY_NAMESPACE ?= moadqassem

IMAGE_TAG = \
$(shell echo $$(git rev-parse HEAD && if [[ -n $$(git status --porcelain) ]]; then echo '-dirty'; fi)|tr -d ' ')
IMAGE_NAME ?= $(REGISTRY)/$(REGISTRY_NAMESPACE)/kubetink:$(IMAGE_TAG)

BASE64_ENC = \
$(shell if base64 -w0 <(echo "") &> /dev/null; then echo "base64 -w0"; else echo "base64 -b0"; fi)

.PHONY: lint
lint:
@golangci-lint --version
golangci-lint run -v ./pkg/...

.PHONY: vendor
vendor: buildenv
go mod vendor

.PHONY: buildenv
buildenv:
@go version

.PHONY: all
all: build

.PHONY: build
build: $(CMD)

.PHONY: $(CMD)
$(CMD): %: $(BUILD_DEST)/%

$(BUILD_DEST)/%: cmd/%
go build -v -o $@ ./cmd/$*

.PHONY: clean
clean:
rm -rf $(BUILD_DEST)
@echo "Cleaned $(BUILD_DEST)"

.PHONY: docker-image
docker-image:
docker build --build-arg GO_VERSION=$(GO_VERSION) -t $(IMAGE_NAME) .

.PHONY: docker-image-publish
docker-image-publish: docker-image
docker push $(IMAGE_NAME)
if [[ -n "$(GIT_TAG)" ]]; then \
$(eval IMAGE_TAG = $(GIT_TAG)) \
docker build -t $(IMAGE_NAME) . && \
docker push $(IMAGE_NAME) && \
$(eval IMAGE_TAG = latest) \
docker build -t $(IMAGE_NAME) . ;\
docker push $(IMAGE_NAME) ;\
fi

.PHONY: shfmt
shfmt:
shfmt -w -sr -i 2 hack

0 comments on commit 018f32f

Please sign in to comment.