This repository has been archived by the owner on May 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
114 lines (92 loc) · 3.26 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
#
# Makefile for zededa-provision
#
# Copyright (c) 2018 Zededa, Inc.
# SPDX-License-Identifier: Apache-2.0
# Goals
# 1. Build go provision binaries for arm64 and amd64
# 2. Build on Linux as well on Mac
ARCH ?= amd64
#ARCH ?= arm64
USER := $(shell id -u -n)
GROUP := $(shell id -g -n)
UID := $(shell id -u)
GID := $(shell id -g)
GIT_TAG := $(shell git tag | tail -1)
BUILD_DATE := $(shell date -u +"%Y-%m-%d-%H:%M")
GIT_VERSION := $(shell git describe --match v --abbrev=8 --always --dirty)
BRANCH_NAME := $(shell git rev-parse --abbrev-ref HEAD)
VERSION := $(GIT_TAG)
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOMODULE=github.com/zededa/go-provision
BUILD_VERSION=$(shell scripts/getversion.sh)
OBJDIR := $(PWD)/bin/$(ARCH)
BINDIR := $(OBJDIR)
DOCKER_ARGS=$${GOARCH:+--build-arg GOARCH=}$(GOARCH)
DOCKER_TAG=zededa/ztools:local$${GOARCH:+-}$(GOARCH)
APPS = zedbox
APPS1 = logmanager ledmanager downloader verifier client zedrouter domainmgr identitymgr zedmanager zedagent hardwaremodel ipcmonitor nim diag baseosmgr wstunnelclient conntrack
SHELL_CMD=bash
define BUILD_CONTAINER
FROM golang:1.9.1-alpine
RUN apk add --no-cache openssh-client git gcc linux-headers libc-dev util-linux libpcap-dev bash vim make
RUN deluser $(USER) ; delgroup $(GROUP) || :
RUN sed -ie /:$(UID):/d /etc/passwd /etc/shadow ; sed -ie /:$(GID):/d /etc/group || :
RUN addgroup -g $(GID) $(GROUP) && adduser -h /home/$(USER) -G $(GROUP) -D -H -u $(UID) $(USER)
ENV HOME /home/$(USER)
endef
SHELL_CMD=bash
define BUILD_CONTAINER
FROM golang:1.9.1-alpine
RUN apk add --no-cache openssh-client git gcc linux-headers libc-dev util-linux libpcap-dev bash vim make
RUN deluser $(USER) ; delgroup $(GROUP) || :
RUN sed -ie /:$(UID):/d /etc/passwd /etc/shadow ; sed -ie /:$(GID):/d /etc/group || :
RUN addgroup -g $(GID) $(GROUP) && adduser -h /home/$(USER) -G $(GROUP) -D -H -u $(UID) $(USER)
ENV HOME /home/$(USER)
endef
.PHONY: all clean vendor
all: obj build
obj:
@rm -rf $(BINDIR)
@mkdir -p $(BINDIR)
build:
@echo Building version $(BUILD_VERSION)
@mkdir -p var/tmp/zededa
@echo $(BUILD_VERSION) >$(BINDIR)/versioninfo
@for app in $(APPS); do \
echo $$app; \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=$(ARCH) $(GOBUILD) \
-ldflags -X=main.Version=$(BUILD_VERSION) \
-o $(BINDIR)/$$app github.com/zededa/go-provision/$$app || exit 1; \
done
@for app in $(APPS1); do \
echo $$app; \
rm -f $(BINDIR)/$$app; \
ln -s $(APPS) $(BINDIR)/$$app; \
done
build-docker:
docker build $(DOCKER_ARGS) -t $(DOCKER_TAG) .
build-docker-git:
git archive HEAD | docker build $(DOCKER_ARGS) -t $(DOCKER_TAG) -
export BUILD_CONTAINER
eve-build-$(USER):
@echo "$$BUILD_CONTAINER" | docker build -t $@ - >/dev/null
shell: eve-build-$(USER)
@mkdir -p .go/src/$(GOMODULE)
@docker run -it --rm -u $(USER) -w /home/$(USER) \
-v $(CURDIR)/.go:/go -v $(CURDIR):/go/src/$(GOMODULE) -v $${HOME}:/home/$(USER) \
$< $(SHELL_CMD)
test: SHELL_CMD=go test github.com/zededa/go-provision/...
test: shell
@echo Done testing
Gopkg.lock: SHELL_CMD=bash --norc --noprofile -c "go get github.com/golang/dep/cmd/dep ; cd /go/src/$(GOMODULE) ; dep ensure -update $(GODEP_NAME)"
Gopkg.lock: Gopkg.toml shell
@echo Done updating vendor
vendor: Gopkg.lock
touch Gopkg.toml
clean:
@rm -rf bin