-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
48 lines (39 loc) · 1.8 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
# Copyright 2019 The pf9ctl authors.
#
# Usage:
# make # builds the artifact
# make ensure # runs dep ensure which downloads the dependencies
# make clean # removes the artifact and the vendored packages
# make clean-all # same as make clean + removes the bin dir which houses dep
# make container-build # build artifact on a Linux based container using golang 1.14.1
SHELL := /usr/bin/env bash
BUILD_NUMBER ?= 10
GITHASH := $(shell git rev-parse --short HEAD)
PF9_VERSION ?= 1.0.0
VERSION := $(PF9_VERSION)-$(BUILD_NUMBER)
DETECTED_OS := $(shell uname -s)
BIN_DIR := $(shell pwd)/bin
BIN := pf9ctl
REPO := pf9ctl
PACKAGE_GOPATH := /go/src/github.com/platform9/$(REPO)
LDFLAGS := $(shell source ./version.sh ; KUBE_ROOT=. ; KUBE_GIT_VERSION=${VERSION_OVERRIDE} ; kube::version::ldflags)
GIT_STORAGE_MOUNT := $(shell source ./git_utils.sh; container_git_storage_mount)
CONT_USER := $(shell id -u)
CONT_GRP := $(shell id -g)
XDG_CACHE_HOME := /tmp
GOFLAGS ?= ""
.PHONY: clean clean-all container-build default format test
default: $(BIN)
container-build:
docker run --rm --env XDG_CACHE_HOME=$(XDG_CACHE_HOME) --env SEGMENT_KEY_PRD_PMKFT=$(SEGMENT_KEY_PRD_PMKFT) --env VERSION_OVERRIDE=${VERSION_OVERRIDE} --env GOPATH=/tmp --env GOFLAGS=$(GOFLAGS) --user $(CONT_USER):$(CONT_GRP) --volume $(PWD):$(PACKAGE_GOPATH) $(GIT_STORAGE_MOUNT) --workdir $(PACKAGE_GOPATH) golang:1.23 make ldflags="-s -w -extldflags '-static'"
$(BIN): test
go build -o $(BIN_DIR)/$(BIN) -ldflags "$(LDFLAGS) -X github.com/platform9/pf9ctl/pkg/client.SegmentWriteKey=$(SEGMENT_KEY_PRD_PMKFT) -s -w"
format:
gofmt -w -s *.go
gofmt -w -s */*.go
clean:
rm -rf $(BIN_DIR)
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-s -w -extldflags '-static'" -o $(BIN_DIR)/$(BIN) main.go
test:
go test -v ./...