-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
100 lines (81 loc) · 3.71 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
BUILD_DATE?=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_VERSION?=$(shell git describe --tags --dirty --abbrev=0 2>/dev/null || git symbolic-ref --short HEAD)
GIT_COMMIT?=$(shell git rev-parse HEAD 2>/dev/null)
GIT_BRANCH?=$(shell git symbolic-ref --short HEAD 2>/dev/null)
# semver version
VERSION?=$(shell echo "${GIT_VERSION}" | sed -e 's/^v//')
# semver version
SEMVER_VERSION?=$(shell echo "${GIT_VERSION}" | sed -e 's/^v//')
BIN_DIR = ${PWD}/bin
IMAGE_REGISTRY?=docker.io
IMAGE_TAG=${GIT_VERSION}
ifeq (${IMAGE_TAG},main)
IMAGE_TAG = latest
endif
# Image URL to use all building/pushing image targets
IMG ?= ${IMAGE_REGISTRY}/kubegems/modelx:$(IMAGE_TAG)
DLIMG ?= ${IMAGE_REGISTRY}/kubegems/modelxdl:$(IMAGE_TAG)
GOPACKAGE=$(shell go list -m)
ldflags+=-w -s
ldflags+=-X '${GOPACKAGE}/pkg/version.gitVersion=${GIT_VERSION}'
ldflags+=-X '${GOPACKAGE}/pkg/version.gitCommit=${GIT_COMMIT}'
ldflags+=-X '${GOPACKAGE}/pkg/version.buildDate=${BUILD_DATE}'
PUSH?=false
##@ All
all: build-all image-all ## build all
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
check: linter ## Static code check.
${LINTER} run ./...
preset:
BINARIES = modelx modelxd modelxdl
define build
$(foreach n,$(subst , , ${BINARIES}),
@echo "Building $(n)-${1}-${2}"
@GOOS=${1} GOARCH=$(2) CGO_ENABLED=0 go build -gcflags=all="-N -l" -ldflags="${ldflags}" -o ${BIN_DIR}/$(n)-$(1)-$(2) ${GOPACKAGE}/cmd/$(n)
)
endef
##@ Build
OS:=$(shell go env GOOS)
ARCH:=$(shell go env GOARCH)
build: preset ## Build binaries.
$(call build,${OS},${ARCH})
@cp ${BIN_DIR}/modelx-${OS}-${ARCH} ${BIN_DIR}/modelx
build-all: preset
$(call build,linux,amd64)
$(call build,linux,arm64)
$(call build,darwin,amd64)
$(call build,darwin,arm64)
$(call build,windows,amd64)
image:
docker buildx build --platform=${OS}/${ARCH} --tag ${IMG} --push=${PUSH} -f Dockerfile ${BIN_DIR}
docker buildx build --platform=${OS}/${ARCH} --tag ${DLIMG} --push=${PUSH} -f Dockerfile.dl ${BIN_DIR}
PLATFORM?=linux/amd64,linux/arm64
image-all: ## Build container image.
docker buildx build --platform=${PLATFORM} --tag ${IMG} --push=${PUSH} -f Dockerfile ${BIN_DIR}
docker buildx build --platform=${PLATFORM} --tag ${DLIMG} --push=${PUSH} -f Dockerfile.dl ${BIN_DIR}
helm-package:
helm package charts/modelx --version=${SEMVER_VERSION} --app-version=${SEMVER_VERSION}
HELM_REPO_USERNAME?=kubegems
HELM_REPO_PASSWORD?=
CHARTMUSEUM_ADDR?=https://${HELM_REPO_USERNAME}:${HELM_REPO_PASSWORD}@charts.kubegems.io/kubegems
helm-push:
curl --data-binary "@modelx-${SEMVER_VERSION}.tgz" ${CHARTMUSEUM_ADDR}/api/charts
clean:
- rm -rf ${BIN_DIR}