forked from micromdm/micromdm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
152 lines (112 loc) · 3.88 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
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
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
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