This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
forked from kolide/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
212 lines (166 loc) · 6.08 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
.PHONY: build
PATH := $(GOPATH)/bin:$(shell npm bin):$(PATH)
VERSION = $(shell git describe --tags --always --dirty)
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
REVISION = $(shell git rev-parse HEAD)
REVSHORT = $(shell git rev-parse --short HEAD)
USER = $(shell whoami)
DOCKER_IMAGE_NAME = kolide/fleet
ifneq ($(OS), Windows_NT)
# If on macOS, set the shell to bash explicitly
ifeq ($(shell uname), Darwin)
SHELL := /bin/bash
endif
# The output binary name is different on Windows, so we're explicit here
OUTPUT = fleet
# To populate version metadata, we use unix tools to get certain data
GOVERSION = $(shell go version | awk '{print $$3}')
NOW = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
else
# The output binary name is different on Windows, so we're explicit here
OUTPUT = fleet.exe
# To populate version metadata, we use windows tools to get the certain data
GOVERSION_CMD = "(go version).Split()[2]"
GOVERSION = $(shell powershell $(GOVERSION_CMD))
NOW = $(shell powershell Get-Date -format s)
endif
ifndef CIRCLE_PR_NUMBER
DOCKER_IMAGE_TAG = ${REVSHORT}
else
DOCKER_IMAGE_TAG = dev-${CIRCLE_PR_NUMBER}-${REVSHORT}
endif
ifdef CIRCLE_TAG
DOCKER_IMAGE_TAG = ${CIRCLE_TAG}
endif
ifndef MYSQL_PORT_3306_TCP_ADDR
MYSQL_PORT_3306_TCP_ADDR = 127.0.0.1
endif
KIT_VERSION = "\
-X github.com/kolide/fleet/vendor/github.com/kolide/kit/version.appName=${APP_NAME} \
-X github.com/kolide/fleet/vendor/github.com/kolide/kit/version.version=${VERSION} \
-X github.com/kolide/fleet/vendor/github.com/kolide/kit/version.branch=${BRANCH} \
-X github.com/kolide/fleet/vendor/github.com/kolide/kit/version.revision=${REVISION} \
-X github.com/kolide/fleet/vendor/github.com/kolide/kit/version.buildDate=${NOW} \
-X github.com/kolide/fleet/vendor/github.com/kolide/kit/version.buildUser=${USER} \
-X github.com/kolide/fleet/vendor/github.com/kolide/kit/version.goVersion=${GOVERSION}"
all: build
define HELP_TEXT
Makefile commands
make deps - Install dependent programs and libraries
make generate - Generate and bundle required code
make generate-dev - Generate and bundle required code in a watch loop
make distclean - Delete all build artifacts
make build - Build the code
make package - Build rpm and deb packages for linux
make test - Run the full test suite
make test-go - Run the Go tests
make test-js - Run the JavaScript tests
make lint - Run all linters
make lint-go - Run the Go linters
make lint-js - Run the JavaScript linters
make lint-scss - Run the SCSS linters
make lint-ts - Run the TypeScript linters
endef
help:
$(info $(HELP_TEXT))
.prefix:
ifeq ($(OS), Windows_NT)
if not exist build mkdir build
else
mkdir -p build/linux
mkdir -p build/darwin
endif
.pre-build:
$(eval GOGC = off)
$(eval CGO_ENABLED = 0)
.pre-fleet:
$(eval APP_NAME = fleet)
.pre-fleetctl:
$(eval APP_NAME = fleetctl)
build: fleet
fleet: .prefix .pre-build .pre-fleet
go build -i -o build/${OUTPUT} -ldflags ${KIT_VERSION} ./cmd/fleet
fleetctl: .prefix .pre-build .pre-fleetctl
go build -i -o build/fleetctl -ldflags ${KIT_VERSION} ./cmd/fleetctl
lint-js:
eslint frontend --ext .js,.jsx
lint-ts:
tslint frontend/**/*.tsx frontend/**/*.ts
lint-scss:
sass-lint --verbose
lint-go:
go vet ./...
lint: lint-go lint-js lint-scss lint-ts
test-go:
go test ./...
analyze-go:
go test -race -cover ./...
test-js: export NODE_PATH = ./frontend
test-js:
_mocha --compilers js:babel-core/register,tsx:typescript-require \
--recursive "frontend/**/*.tests.js*" \
--require ignore-styles \
--require "frontend/.test.setup.js" \
--require "frontend/test/loaderMock.js"
test: lint test-go test-js
generate: .prefix
NODE_ENV=production webpack --progress --colors
go-bindata -pkg=service \
-o=server/service/bindata.go \
frontend/templates/ assets/...
go-bindata -pkg=kolide -o=server/kolide/bindata.go server/mail/templates
# we first generate the webpack bundle so that bindata knows to watch the
# output bundle file. then, generate debug bindata source file. finally, we
# run webpack in watch mode to continuously re-generate the bundle
generate-dev: .prefix
webpack --progress --colors
go-bindata -debug -pkg=service \
-o=server/service/bindata.go \
frontend/templates/ assets/...
go-bindata -pkg=kolide -o=server/kolide/bindata.go server/mail/templates
webpack --progress --colors --watch
deps:
yarn
go get -u \
github.com/kolide/go-bindata/... \
github.com/golang/dep/cmd/dep \
github.com/groob/mockimpl
dep ensure -vendor-only
distclean:
ifeq ($(OS), Windows_NT)
if exist build rmdir /s/q build
if exist vendor rmdir /s/q vendor
if exist assets\bundle.js del assets\bundle.js
else
rm -rf build vendor
rm -f assets/bundle.js
endif
docker-build-release: .pre-fleet
GOOS=linux go build -i -o build/linux/${OUTPUT} -ldflags ${KIT_VERSION} ./cmd/fleet
docker build -t "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" .
docker tag "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" kolide/fleet:latest
docker-push-release: docker-build-release
docker push "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}"
docker push kolide/fleet:latest
docker-build-circle:
@echo ">> building docker image"
GOOS=linux go build -i -o build/linux/${OUTPUT} -ldflags ${KIT_VERSION} ./cmd/fleet
docker build -t "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" .
docker push "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}"
demo-dump:
mysqldump --extended-insert=FALSE --skip-dump-date \
-u kolide -p \
-h ${MYSQL_PORT_3306_TCP_ADDR} kolide \
> ./tools/app/demo.sql
demo-restore:
mysql --binary-mode -u kolide -p \
-h ${MYSQL_PORT_3306_TCP_ADDR} kolide \
< ./tools/app/demo.sql
binary-bundle: generate
rm -rf build/binary-bundle
mkdir -p build/binary-bundle/linux
mkdir -p build/binary-bundle/darwin
GOOS=linux go build -i -o build/binary-bundle/linux/${OUTPUT}_linux_amd64 -ldflags ${KIT_VERSION} ./cmd/fleet
GOOS=darwin go build -i -o build/binary-bundle/darwin/${OUTPUT}_darwin_amd64 -ldflags ${KIT_VERSION} ./cmd/fleet
cd build/binary-bundle && zip -r "fleet_${VERSION}.zip" darwin/ linux/
cp build/binary-bundle/fleet_${VERSION}.zip build/binary-bundle/fleet_lastest.zip