forked from micromdm/micromdm
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
199 lines (143 loc) · 4.91 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
all: build
.PHONY: build
ifeq ($(GOPATH),)
PATH := $(HOME)/go/bin:$(PATH)
else
PATH := $(GOPATH)/bin:$(PATH)
endif
export GO111MODULE=on
#Specify a minimum version for macos otherwise notarization will fail
CGO_LDFLAGS=-mmacosx-version-min=10.12
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)
GOVERSION = $(shell go version | awk '{print $$3}')
NOW = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
SHELL = /bin/sh
ifndef ($(DOCKER_IMAGE_NAME))
DOCKER_IMAGE_NAME = micromdm/micromdm
endif
DOCKER_IMAGE_TAG = $(shell echo ${VERSION} | sed 's/^v//')
ifneq ($(OS), Windows_NT)
CURRENT_PLATFORM = linux
ifeq ($(shell uname), Darwin)
SHELL := /bin/sh
CURRENT_PLATFORM = darwin
endif
else
CURRENT_PLATFORM = windows
endif
ifeq ($(PG_HOST),)
PG_HOST := localhost
endif
ifeq ($(MYSQL_HOST),)
MYSQL_HOST := 127.0.0.1
endif
BUILD_VERSION = "\
-X github.com/micromdm/go4/version.appName=${APP_NAME} \
-X github.com/micromdm/go4/version.version=${VERSION} \
-X github.com/micromdm/go4/version.branch=${BRANCH} \
-X github.com/micromdm/go4/version.buildUser=${USER} \
-X github.com/micromdm/go4/version.buildDate=${NOW} \
-X github.com/micromdm/go4/version.revision=${REVISION} \
-X github.com/micromdm/go4/version.goVersion=${GOVERSION} \
-X github.com/micromdm/micromdm/dep.version=${VERSION}"
gomodcheck:
@go help mod > /dev/null || (@echo micromdm requires Go version 1.11 or higher && exit 1)
deps: gomodcheck
@go mod download
test:
go test -cover ./...
# don't run race tests by default. see https://github.com/etcd-io/bbolt/issues/187
test-race:
go test -cover -race ./...
build: micromdm mdmctl
clean:
rm -rf build/
rm -f *.zip
.pre-build:
mkdir -p build/darwin
mkdir -p build/linux
install-local: \
install-mdmctl \
install-micromdm
.pre-mdmctl:
$(eval APP_NAME = mdmctl)
mdmctl: .pre-build .pre-mdmctl
go build -o build/$(CURRENT_PLATFORM)/mdmctl -ldflags ${BUILD_VERSION} ./cmd/mdmctl
xp-mdmctl: .pre-build .pre-mdmctl
GOOS=darwin go build -o build/darwin/mdmctl -ldflags ${BUILD_VERSION} ./cmd/mdmctl
GOOS=linux CGO_ENABLED=0 go build -o build/linux/mdmctl -ldflags ${BUILD_VERSION} ./cmd/mdmctl
install-mdmctl: .pre-mdmctl
go install -ldflags ${BUILD_VERSION} ./cmd/mdmctl
APP_NAME = micromdm
.pre-micromdm:
$(eval APP_NAME = micromdm)
micromdm: .pre-build .pre-micromdm
go build -o build/$(CURRENT_PLATFORM)/micromdm -ldflags ${BUILD_VERSION} ./cmd/micromdm
install-micromdm: .pre-micromdm
go install -ldflags ${BUILD_VERSION} ./cmd/micromdm
xp-micromdm: .pre-build .pre-micromdm
GOOS=darwin go build -o build/darwin/micromdm -ldflags ${BUILD_VERSION} ./cmd/micromdm
GOOS=linux CGO_ENABLED=0 go build -o build/linux/micromdm -ldflags ${BUILD_VERSION} ./cmd/micromdm
release-zip: xp-micromdm xp-mdmctl
zip -r micromdm_${VERSION}.zip build/
docker-build:
GOOS=linux CGO_ENABLED=0 go build -o build/linux/micromdm -ldflags ${BUILD_VERSION} ./cmd/micromdm
docker build -t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} .
docker-tag: docker-build
docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKER_IMAGE_NAME}:latest
ngrok:
@./tools/ngrok/screen
docker-compose:
docker-compose -f docker-compose-dev.yaml up -d
# PostgreSQL
db-psql-test:
$(call psql_db,micromdm_test)
db-psql:
$(call psql_db,micromdm)
define psql_db
PGPASSWORD=micromdm psql --host=${PG_HOST} --port=5432 --username=micromdm --dbname=$(1)
endef
db-reset-test:
$(call psql_exec,'DROP DATABASE IF EXISTS micromdm_test;')
$(call psql_exec,'CREATE DATABASE micromdm_test;')
define psql_exec
PGPASSWORD=micromdm psql --host=${PG_HOST} --port=5432 --username=micromdm -c $(1)
endef
db-migrate-test:
$(call goose_up,micromdm_test)
db-migrate:
$(call goose_up,micromdm)
define goose_up
cd ./pg/migrations && goose postgres "host=${PG_HOST} port=5432 user=micromdm dbname=$(1) password=micromdm sslmode=disable" up
endef
# MySQL
# Make sure user can access db:
# mysql -u root -p
# mysql> CREATE USER 'micromdm'@'localhost' IDENTIFIED BY 'micromdm';
# mysql> GRANT ALL PRIVILEGES ON *.* TO 'micromdm'@'localhost' IDENTIFIED BY 'micromdm';
db-mysql-test:
$(call mysql_db,micromdm_test)
db-mysql:
$(call mysql_db,micromdm)
define mysql_db
MYSQLPASSWORD=micromdm mysql --host=${MYSQL_HOST} --port=3306 --user=micromdm --password=micromdm $(1)
endef
db-mysql-reset-test:
$(call mysql_exec,'SHOW DATABASES;')
$(call mysql_exec,'DROP DATABASE IF EXISTS micromdm_test;')
$(call mysql_exec,'CREATE DATABASE micromdm_test;')
$(call mysql_exec,'SET sql_mode = "";')
define mysql_exec
mysql --host=${MYSQL_HOST} --port=3306 --user=micromdm --password=micromdm --execute=$(1)
endef
db-mysql-migrate-test:
$(call mysql-goose_up,micromdm_test)
db-mysql-migrate:
$(call mysql-goose_up,micromdm)
define mysql-goose_up
cd ./mysql/migrations && goose mysql "micromdm:micromdm@/$(1)?parseTime=true" up
endef