-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
60 lines (52 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
49
50
51
52
53
54
55
56
57
58
59
60
# © Copyright 2024 Hewlett Packard Enterprise Development LP
IMAGE ?= cosi-driver
ifndef REPO_NAME
REPO_NAME ?= hpestorage/$(IMAGE)
endif
IMAGE_NAME ?= $(REPO_NAME)
ifdef REGISTRY_NAME
IMAGE_NAME = $(REGISTRY_NAME)/$(REPO_NAME)
endif
IMAGE_TAGS ?= latest
ARCH ?= amd64
HTTP_PROXY ?=
HTTPS_PROXY ?=
RUN_TESTS ?= true
GOENV = PATH=$$PATH:$(GOPATH)/bin
.PHONY: help
help:
@echo "Targets:"
@echo " clean - Remove build artifacts."
@echo " build - Compiles the source code."
@echo " test - Run unit tests."
@echo " container - Build cosi driver image and create a local docker image. Errors are ignored."
@echo " push - Build and push cosi driver image to registry."
@echo " all - Cleans build artifacts, build and run unit tests and push the container image to the registry."
.PHONY: build
build:
@mkdir -p bin
@CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -ldflags '-extldflags "-static"' -o ./bin/$(IMAGE) ./*.go
.PHONY: container
container:
docker buildx build --platform=linux/amd64,linux/arm64 --progress=plain \
$(if $(HTTP_PROXY),--build-arg http_proxy=$(HTTP_PROXY)) \
$(if $(HTTPS_PROXY),--build-arg https_proxy=$(HTTPS_PROXY)) \
--build-arg RUN_TESTS=$(RUN_TESTS) \
--provenance=false $(addprefix -t $(IMAGE_NAME):,$(IMAGE_TAGS)) .
.PHONY: push
push:
docker buildx build --platform=linux/amd64,linux/arm64 --progress=plain \
$(if $(HTTP_PROXY),--build-arg http_proxy=$(HTTP_PROXY)) \
$(if $(HTTPS_PROXY),--build-arg https_proxy=$(HTTPS_PROXY)) \
--build-arg RUN_TESTS=$(RUN_TESTS) \
--provenance=false --push $(addprefix -t $(IMAGE_NAME):,$(IMAGE_TAGS)) .
.PHONY: test
test:
@echo "Running unit tests"
go test -v -gcflags=all=-l ./...
.PHONY: clean
clean:
@rm -rf bin
.PHONY: all
all:
$(MAKE) push RUN_TESTS=$(RUN_TESTS)