Skip to content

Commit

Permalink
Merge pull request #1 from jenkins-x/makefile
Browse files Browse the repository at this point in the history
fix: add Makefile
  • Loading branch information
jenkins-x-bot authored Jan 15, 2024
2 parents 5adb1f2 + 4c91413 commit 9b853a2
Show file tree
Hide file tree
Showing 4,011 changed files with 192 additions and 1,340,584 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 6 additions & 1 deletion .lighthouse/jenkins-x/pullrequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ spec:
requests:
cpu: 400m
memory: 600Mi
- name: build-make-linux
- image: golang:1.21
name: build-make-linux
resources: {}
script: |
#!/bin/bash
source .jx/variables.sh
make linux
- name: check-registry
resources: {}
- name: build-container-build
Expand Down
7 changes: 6 additions & 1 deletion .lighthouse/jenkins-x/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ spec:
requests:
cpu: 400m
memory: 600Mi
- name: build-make-build
- image: golang:1.21
name: build-make-linux
resources: {}
script: |
#!/bin/bash
source .jx/variables.sh
make linux
- name: check-registry
resources: {}
- name: build-container-build
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM scratch
EXPOSE 8080
ENTRYPOINT ["/cert-secret-syncer"]
COPY ./bin/ /
COPY ./build/linux/ /
178 changes: 178 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

SHELL := /bin/sh
NAME := jx
BINARY_NAME := cert-secret-syncer
BUILD_TARGET = build
MAIN_SRC_FILE=cmd/*
GO := GO111MODULE=on go
GO_NOMOD :=GO111MODULE=off go
REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')
ORG := jenkins-x
ORG_REPO := $(ORG)/$(NAME)
RELEASE_ORG_REPO := $(ORG_REPO)
ROOT_PACKAGE := github.com/$(ORG_REPO)

# The go version is derived from the image built by this repo: https://github.com/jenkins-x/jx-goreleaser-image
GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/')
GO_DEPENDENCIES := $(call rwildcard,pkg/,*.go) $(call rwildcard,cmd/,*.go)

GIT_TREE_STATE := $(shell test -z "`git status --porcelain`" && echo "clean" || echo "dirty")
BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown')
BUILD_DATE := $(shell date -u +%Y-%m-%dT%H:%M:%S)
CGO_ENABLED = 0

REPORTS_DIR=$(BUILD_TARGET)/reports

GOTEST := $(GO) test

# set dev version unless VERSION is explicitly set via environment
VERSION ?= $(shell echo "$$(git for-each-ref refs/tags/ --count=1 --sort=-version:refname --format='%(refname:short)' 2>/dev/null)-dev+$(REV)" | sed 's/^v//')

# Build flags for setting build-specific configuration at build time - defaults to empty
#BUILD_TIME_CONFIG_FLAGS ?= ""

# Full build flags used when building binaries. Not used for test compilation/execution.
BUILDFLAGS := -ldflags \
" -X $(ROOT_PACKAGE)/pkg/cmd/version.Version=$(VERSION)\
-X $(ROOT_PACKAGE)/pkg/cmd/version.Revision=$(REV)\
-X $(ROOT_PACKAGE)/pkg/cmd/version.Branch=$(BRANCH)\
-X $(ROOT_PACKAGE)/pkg/cmd/version.GitTreeState=$(GIT_TREE_STATE)\
-X $(ROOT_PACKAGE)/pkg/cmd/version.BuildDate=$(BUILD_DATE)\
-X $(ROOT_PACKAGE)/pkg/cmd/version.GoVersion=$(GO_VERSION)\
$(BUILD_TIME_CONFIG_FLAGS)"

# Some tests expect default values for version.*, so just use the config package values there.
TEST_BUILDFLAGS := -ldflags "$(BUILD_TIME_CONFIG_FLAGS)"

ifdef DEBUG
BUILDFLAGS := -gcflags "all=-N -l" $(BUILDFLAGS)
endif

ifdef PARALLEL_BUILDS
BUILDFLAGS += -p $(PARALLEL_BUILDS)
GOTEST += -p $(PARALLEL_BUILDS)
else
# -p 4 seems to work well for people
GOTEST += -p 4
endif

ifdef DISABLE_TEST_CACHING
GOTEST += -count=1
endif

TEST_PACKAGE ?= ./...
COVER_OUT:=$(REPORTS_DIR)/cover.txt
COVERFLAGS=-coverprofile=$(COVER_OUT) --covermode=atomic --coverpkg=./pkg/...

.PHONY: list
list: ## List all make targets
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort

.PHONY: help
.DEFAULT_GOAL := help
help:
@grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

full: check ## Build and run the tests
check: build test ## Build and run the tests

print-version: ## Print version
@echo $(VERSION)

build: $(GO_DEPENDENCIES) clean ## Build jx binary for current OS
go mod download
CGO_ENABLED=$(CGO_ENABLED) $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/$(BINARY_NAME) $(MAIN_SRC_FILE)

build-all: $(GO_DEPENDENCIES) build make-reports-dir ## Build all files - runtime, all tests etc.
CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) -run=nope -tags=integration -failfast -short ./... $(BUILDFLAGS)

tidy-deps: ## Cleans up dependencies
$(GO) mod tidy
# mod tidy only takes compile dependencies into account, let's make sure we capture tooling dependencies as well
@$(MAKE) install-generate-deps

.PHONY: make-reports-dir
make-reports-dir:
mkdir -p $(REPORTS_DIR)

test: ## Run tests with the "unit" build tag
KUBECONFIG=/cluster/connections/not/allowed JX3_HOME=/tmp/jx3 CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) --tags=unit -failfast -short ./... $(TEST_BUILDFLAGS)

test-coverage : make-reports-dir ## Run tests and coverage for all tests with the "unit" build tag
CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) --tags=unit $(COVERFLAGS) -failfast -short ./... $(TEST_BUILDFLAGS)

test-report-html: make-reports-dir test-coverage
$(GO) tool cover -html=$(COVER_OUT)

test-total-cov: make-reports-dir test-coverage
$(GO) tool cover -func=$(COVER_OUT)

install: $(GO_DEPENDENCIES) ## Install the binary
GOBIN=${GOPATH}/bin $(GO) install $(BUILDFLAGS) $(MAIN_SRC_FILE)

linux: ## Build for Linux
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/linux/$(BINARY_NAME) $(MAIN_SRC_FILE)
chmod +x build/linux/$(BINARY_NAME)

arm: ## Build for ARM
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=arm $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/arm/$(BINARY_NAME) $(MAIN_SRC_FILE)
chmod +x build/arm/$(BINARY_NAME)

win: ## Build for Windows
CGO_ENABLED=$(CGO_ENABLED) GOOS=windows GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/win/$(BINARY_NAME)-windows-amd64.exe $(MAIN_SRC_FILE)

darwin: ## Build for OSX
CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/darwin/$(BINARY_NAME) $(MAIN_SRC_FILE)
chmod +x build/darwin/$(BINARY_NAME)

.PHONY: release
release: clean linux test

release-all: release linux win darwin

.PHONY: goreleaser
goreleaser:
step-go-releaser --organisation=$(ORG) --revision=$(REV) --branch=$(BRANCH) --build-date=$(BUILD_DATE) --go-version=$(GO_VERSION) --root-package=$(ROOT_PACKAGE) --version=$(VERSION)

.PHONY: clean
clean: ## Clean the generated artifacts
rm -rf build release dist

get-fmt-deps: ## Install test dependencies
$(GO_NOMOD) get golang.org/x/tools/cmd/goimports

.PHONY: fmt
fmt: importfmt ## Format the code
$(eval FORMATTED = $(shell $(GO) fmt ./...))
@if [ "$(FORMATTED)" == "" ]; \
then \
echo "All Go files properly formatted"; \
else \
echo "Fixed formatting for: $(FORMATTED)"; \
fi

.PHONY: importfmt
importfmt: get-fmt-deps
@echo "Formatting the imports..."
goimports -w $(GO_DEPENDENCIES)

.PHONY: lint
lint: ## Lint the code
./hack/gofmt.sh
./hack/linter.sh
./hack/generate.sh

.PHONY: all
all: fmt build test lint

bin/docs:
go build $(LDFLAGS) -v -o bin/docs cmd/docs/*.go

.PHONY: docs
docs: bin/docs ## update docs
@echo "Generating docs"
@./bin/docs --target=./docs/cmd
@./bin/docs --target=./docs/man/man1 --kind=man
@rm -f ./bin/docs
36 changes: 0 additions & 36 deletions build/Dockerfile

This file was deleted.

132 changes: 0 additions & 132 deletions build/main.go

This file was deleted.

2 changes: 0 additions & 2 deletions charts/cert-secret-syncer/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ metadata:
labels:
{{- include "..labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "..selectorLabels" . | nindent 6 }}
Expand Down
Loading

0 comments on commit 9b853a2

Please sign in to comment.