-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
170 lines (135 loc) · 7.49 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
IMAGE_TAG ?= $(shell git rev-parse HEAD 2> /dev/null)
ifeq ($(strip $(SILENT)),)
TO_NUL :=
else
TO_NUL := 2> /dev/null
endif
COMPANY_NAME ?= mfdlabs
PROJECT_NAME ?= $(notdir $(CURDIR))
IMAGE_NAME ?= $(COMPANY_NAME)/$(PROJECT_NAME)
ifeq ($(OS),Windows_NT)
SETC := SET
ARCH := $(PROCESSOR_ARCHITECTURE)
GOOS := windows
else
SETC := export
UNAME := $(shell uname)
ARCH := $(shell uname -m)
ifeq ($(UNAME),Linux)
GOOS := linux
else ifeq ($(UNAME),Darwin)
GOOS := darwin
endif
endif
# Convert the ARCH value to the corresponding GOARCH string
ifeq ($(ARCH),x86_64)
GOARCH := amd64
else ifeq ($(ARCH),i386)
GOARCH := 386
else ifeq ($(ARCH),armv7l)
GOARCH := arm
else ifeq ($(ARCH),aarch64)
GOARCH := arm64
else ifeq ($(ARCH),AMD64)
GOARCH := amd64
else ifeq ($(ARCH),x86)
GOARCH := 386
endif
ARCH_OUT = $(GOARCH)
ifeq ($(ARCH_OUT),386)
ARCH_OUT = x86
else ifeq ($(ARCH_OUT),amd64)
ARCH_OUT = x64
endif
ifeq ($(GOOS),windows)
OUTFILE := $(PROJECT_NAME).exe
else
OUTFILE := $(PROJECT_NAME)
endif
.DEFAULT_GOAL := all
all:
$(info make <cmd>)
$(info )
$(info commands:)
$(info )
$(info vendor - compile the vendor paths.)
$(info test - run all unit tests.)
$(info build-docker - build a docker image, IMAGE_NAME will default to $(COMPANY_NAME)/$(PROJECT_NAME) if not specified!)
$(info build-debug - build a debug build. If GOARCH or GOOS were not specified "$(GOOS)/$(GOARCH)" will be used.)
$(info build-release - build a release build that strips all symbols. If GOARCH or GOOS were not specified, "$(GOOS)/$(GOARCH)" will be used.)
$(info build-debug-<arch> - helper for building a debug build for a specific arch, <arch> can be either x86, x64, arm or arm64. If GOOS was not specified, "$(GOOS)" will be used.)
$(info build-release-<arch> - helper for building a release build for a specific arch that strips all symbols, <arch> can be either x86, x64, arm or arm64. If GOOS was not specified, "$(GOOS)" will be used.)
$(info )
test:
$(info Running Tests...)
@cd ./src && go fmt ./... && go vet ./... && go test ./...
vendor:
$(info Go Vendor being applied to $(CURDIR)/src/vendor.)
ifeq ($(strip $(SKIP_VENDOR)),)
@cd ./src && go mod tidy && go mod vendor
else
$(info Go Vendor skipped because SKIP_VENDOR specified.)
endif
build-debug-x86: vendor
$(eval GOARCH := 386)
$(info Go Debug Build For is now set to: $(GOOS)/$(GOARCH) -> $(CURDIR)/bin/debug/$(GOOS)/x86/$(OUTFILE))
@cd ./src && export GOARCH=$(GOARCH)&& export GOOS=$(GOOS)&& go build -mod=vendor -ldflags "-X main.commitSha=$(IMAGE_TAG) -X main.buildMode=debug -X main.applicationName=$(PROJECT_NAME)" -v -o ../bin/debug/$(GOOS)/x86/$(OUTFILE) ./main.go $(TO_NUL) || echo Go Build returned a non-zero status code
build-debug-x64: vendor
$(eval GOARCH := amd64)
$(info Go Debug Build For is now set to: $(GOOS)/$(GOARCH) -> $(CURDIR)/bin/debug/$(GOOS)/x64/$(OUTFILE))
@cd ./src && export GOARCH=$(GOARCH)&& export GOOS=$(GOOS)&& go build -mod=vendor -ldflags "-X main.commitSha=$(IMAGE_TAG) -X main.buildMode=debug -X main.applicationName=$(PROJECT_NAME)" -v -o ../bin/debug/$(GOOS)/x64/$(OUTFILE) ./main.go $(TO_NUL) || echo Go Build returned a non-zero status code
build-debug-arm: vendor
$(eval GOARCH := arm)
$(info Go Debug Build For is now set to: $(GOOS)/$(GOARCH) -> $(CURDIR)/bin/debug/$(GOOS)/arm/$(OUTFILE))
@cd ./src && export GOARCH=$(GOARCH)&& export GOOS=$(GOOS)&& go build -mod=vendor -ldflags "-X main.commitSha=$(IMAGE_TAG) -X main.buildMode=debug -X main.applicationName=$(PROJECT_NAME)" -v -o ../bin/debug/$(GOOS)/arm/$(OUTFILE) ./main.go $(TO_NUL) || echo Go Build returned a non-zero status code
build-debug-arm64: vendor
$(eval GOARCH := arm64)
$(info Go Debug Build For is now set to: $(GOOS)/$(GOARCH) -> $(CURDIR)/bin/debug/$(GOOS)/arm64/$(OUTFILE))
@cd ./src && export GOARCH=$(GOARCH)&& export GOOS=$(GOOS)&& go build -mod=vendor -ldflags "-X main.commitSha=$(IMAGE_TAG) -X main.buildMode=debug -X main.applicationName=$(PROJECT_NAME)" -v -o ../bin/debug/$(GOOS)/arm64/$(OUTFILE) ./main.go $(TO_NUL) || echo Go Build returned a non-zero status code
build-release-x86: vendor
$(eval GOARCH := 386)
$(info Go Release Build For is now set to: $(GOOS)/$(GOARCH) -> $(CURDIR)/bin/release/$(GOOS)/x86/$(OUTFILE))
@cd ./src && export GOARCH=$(GOARCH)&& export GOOS=$(GOOS)&& go build -mod=vendor -ldflags "-s -w -X main.commitSha=$(IMAGE_TAG) -X main.buildMode=release -X main.applicationName=$(PROJECT_NAME)" -v -o ../bin/release/$(GOOS)/x86/$(OUTFILE) ./main.go $(TO_NUL) || echo Go Build returned a non-zero status code
build-release-x64: vendor
$(eval GOARCH := amd64)
$(info Go Release Build For is now set to: $(GOOS)/$(GOARCH) -> $(CURDIR)/bin/release/$(GOOS)/x64/$(OUTFILE))
@cd ./src && export GOARCH=$(GOARCH)&& export GOOS=$(GOOS)&& go build -mod=vendor -ldflags "-s -w -X main.commitSha=$(IMAGE_TAG) -X main.buildMode=release -X main.applicationName=$(PROJECT_NAME)" -v -o ../bin/release/$(GOOS)/x64/$(OUTFILE) ./main.go $(TO_NUL) || echo Go Build returned a non-zero status code
build-release-arm: vendor
$(eval GOARCH := arm)
$(info Go Release Build For is now set to: $(GOOS)/$(GOARCH) -> $(CURDIR)/bin/release/$(GOOS)/arm/$(OUTFILE))
@cd ./src && export GOARCH=$(GOARCH)&& export GOOS=$(GOOS)&& go build -mod=vendor -ldflags "-s -w -X main.commitSha=$(IMAGE_TAG) -X main.buildMode=release -X main.applicationName=$(PROJECT_NAME)" -v -o ../bin/release/$(GOOS)/arm/$(OUTFILE) ./main.go $(TO_NUL) || echo Go Build returned a non-zero status code
build-release-arm64: vendor
$(eval GOARCH := arm64)
$(info Go Release Build For is now set to: $(GOOS)/$(GOARCH) -> $(CURDIR)/bin/release/$(GOOS)/arm64/$(OUTFILE))
@cd ./src && export GOARCH=$(GOARCH)&& export GOOS=$(GOOS)&& go build -mod=vendor -ldflags "-s -w -X main.commitSha=$(IMAGE_TAG) -X main.buildMode=release -X main.applicationName=$(PROJECT_NAME)" -v -o ../bin/release/$(GOOS)/arm64/$(OUTFILE) ./main.go $(TO_NUL) || echo Go Build returned a non-zero status code
build-debug: vendor
$(info Go Debug Build For is now set to: $(GOOS)/$(GOARCH) -> $(CURDIR)/bin/debug/$(GOOS)/$(ARCH_OUT)/$(OUTFILE))
@cd ./src && go build -mod=vendor -ldflags "-X main.commitSha=$(IMAGE_TAG) -X main.buildMode=debug -X main.applicationName=$(PROJECT_NAME)" -v -o ../bin/debug/$(GOOS)/$(ARCH_OUT)/$(OUTFILE) ./main.go $(TO_NUL) || echo Go Build returned a non-zero status code
build-release: vendor
$(info Go Release Build For is now set to: $(GOOS)/$(GOARCH) -> $(CURDIR)/bin/release/$(GOOS)/$(ARCH_OUT)/$(OUTFILE))
@cd ./src && go build -mod=vendor -ldflags "-s -w -X main.commitSha=$(IMAGE_TAG) -X main.buildMode=release -X main.applicationName=$(PROJECT_NAME)" -v -o ../bin/release/$(GOOS)/$(ARCH_OUT)/$(OUTFILE) ./main.go $(TO_NUL) || echo Go Build returned a non-zero status code
build-debug-all: build-debug-x86 build-debug-x64 build-debug-arm build-debug-arm64
build-release-all: build-release-x86 build-release-x64 build-release-arm build-release-arm64
build-docker:
ifndef IMAGE_NAME
$(info IMAGE_NAME is not defined)
else
ifndef COMPANY_NAME
$(info COMPANY_NAME is not defined)
else
ifndef PROJECT_NAME
$(info PROJECT_NAME is not defined)
else
@docker build --build-arg PROJECT_NAME=$(PROJECT_NAME) --build-arg COMPANY_NAME=$(COMPANY_NAME) -t $(IMAGE_NAME):$(IMAGE_TAG) -f Dockerfile .
@docker tag $(IMAGE_NAME):$(IMAGE_TAG) $(IMAGE_NAME):latest
ifdef CI
@docker push $(IMAGE_NAME):$(IMAGE_TAG)
@docker push $(IMAGE_NAME):latest
endif
ifndef KEEP_IMAGES
@docker rmi $(IMAGE_NAME):$(IMAGE_TAG)
@docker rmi $(IMAGE_NAME):latest
endif
endif
endif
endif