forked from NetApp/trident
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile_Windows
89 lines (77 loc) · 2.96 KB
/
Makefile_Windows
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
# Copyright 2022 NetApp, Inc. All Rights Reserved.
GOARCH ?= amd64
GOGC ?= ""
GOPROXY ?= https://proxy.golang.org
GO_IMAGE ?= golang:1.18
TRIDENT_VOLUME = trident_build
TRIDENT_VOLUME_PATH ?=c:/go/src/github.com/netapp/trident
TRIDENT_CONFIG_PKG = github.com/netapp/trident/config
BUILD_CONTAINER_NAME ?= trident-build
WINDOWS_IMG_VERSION ?=1809
## build flags variables
GITHASH ?= $(shell git describe --match=NeVeRmAtCh --always --abbrev=40 --dirty || echo unknown)
BUILD_TYPE ?= custom
BUILD_TYPE_REV ?= 0
BUILD_TIME = $(date)
GO_CMD ?= go
# common variables
PORT ?= 8000
ROOT :=$(shell cd)
BIN_DIR = ${ROOT}\bin
BIN ?= trident_orchestrator.exe
TARBALL_BIN ?= trident
CLI_BIN ?= tridentctl.exe
CLI_PKG ?= github.com/netapp/trident/cli
K8S ?= ""
BUILD = build
VERSION ?= $(file < ${ROOT}/hack/VERSION)
DR_WINDOWS = docker run \
--name=${BUILD_CONTAINER_NAME} \
-e CGO_ENABLED=0 \
-e GOOS=windows \
-e GOARCH=${GOARCH} \
-e GOGC=${GOGC} \
-e GOPROXY=${GOPROXY} \
-e XDG_CACHE_HOME=/go/cache \
${VOLUME_ARG} \
-v "${ROOT}":"${TRIDENT_VOLUME_PATH}" \
-w ${TRIDENT_VOLUME_PATH} \
${GO_IMAGE}
GO_WINDOWS = ${DR_WINDOWS} ${GO_CMD}
.PHONY: default trident_build_windows push
## version variables
TRIDENT_VERSION ?= ${VERSION}
TRIDENT_IMAGE ?= trident
ifeq ($(BUILD_TYPE),custom)
TRIDENT_VERSION := ${TRIDENT_VERSION}-custom
else ifneq ($(BUILD_TYPE),stable)
TRIDENT_VERSION := ${TRIDENT_VERSION}-${BUILD_TYPE}.${BUILD_TYPE_REV}
endif
## tag variables
TRIDENT_TAG := ${TRIDENT_IMAGE}:${TRIDENT_VERSION}
ifdef REGISTRY_ADDR
TRIDENT_TAG := ${REGISTRY_ADDR}/${TRIDENT_TAG}
endif
DIST_REGISTRY ?= netapp
TRIDENT_DIST_TAG := ${DIST_REGISTRY}/${TRIDENT_IMAGE}:${TRIDENT_VERSION}
# Go compiler flags need to be properly encapsulated with double quotes to handle spaces in values
BUILD_FLAGS = "-s -w -X \"${TRIDENT_CONFIG_PKG}.BuildHash=${GITHASH}\" -X \"${TRIDENT_CONFIG_PKG}.BuildType=${BUILD_TYPE}\" -X \"${TRIDENT_CONFIG_PKG}.BuildTypeRev=${BUILD_TYPE_REV}\" -X \"${TRIDENT_CONFIG_PKG}.BuildTime=${BUILD_TIME}\" -X \"${TRIDENT_CONFIG_PKG}.BuildImage=${TRIDENT_DIST_TAG}\""
## Trident build targets
trident_build_windows:
@if not exist ${BIN_DIR} md ${BIN_DIR}
@if exist bin\${BIN} del bin\${BIN}
@if exist bin\${CLI_BIN} del bin\${CLI_BIN}
@if exist ${ROOT}\${BIN} del ${ROOT}\${BIN}
@if exist ${ROOT}\${CLI_BIN} del ${ROOT}\${CLI_BIN}
@${GO_WINDOWS} ${BUILD} -ldflags ${BUILD_FLAGS} -o bin\${BIN}
ifdef CREATE_BASE_IMAGE
@docker commit ${BUILD_CONTAINER_NAME} ${CREATE_BASE_IMAGE}
endif
@docker rm ${BUILD_CONTAINER_NAME}
@${GO_WINDOWS} ${BUILD} -ldflags ${BUILD_FLAGS} -o bin\${CLI_BIN} ${CLI_PKG}
@docker rm ${BUILD_CONTAINER_NAME}
@copy ${BIN_DIR}\${BIN} ${ROOT}\${BIN}
@copy ${BIN_DIR}\${CLI_BIN} ${ROOT}\${CLI_BIN}
docker build --file Dockerfile.Windows --build-arg ARCH=${GOARCH} --build-arg WINDOWS_VERSION=${WINDOWS_IMG_VERSION} --build-arg PORT=${PORT} --build-arg BIN=${BIN} --build-arg CLI_BIN=${CLI_BIN} --build-arg K8S=${K8S} -t ${TRIDENT_DIST_TAG} --rm .
push:
docker push ${TRIDENT_DIST_TAG}