-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMakefile
167 lines (145 loc) · 6.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
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
# Edgecore DeviceManager
# Copyright 2020-2021 Edgecore Networks, Inc.
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Configure shell
SHELL = bash -eu -o pipefail
# Variables
VERSION ?= $(shell cat ./VERSION)
WORKSPACE ?= $(shell pwd)
LOCAL_DIR=/usr/local
GO_DIR=${LOCAL_DIR}/go
PROTOC_VERSION=3.7.0
PROTOC_SHA256SUM=a1b8ed22d6dc53c5b8680a6f1760a305b33ef471bece482e92728f00ba2a2969
DM_CONFIG_FILE_PATH=${WORKSPACE}/src/config/config.yml
CONFIG_FILE_PATH=${WORKSPACE}/lib-utilities/config/odimra_config.json
GO_BIN_PATH=/usr/local/go/bin
help:
@echo "Usage: make [<target>]"
@echo "where available targets are:"
@echo
@echo "- Quick installation commands."
@echo "all : Install necessary packages, commands and run Device Manager"
@echo
@echo "- Additional commands."
@echo "buildDeviceManager : Builds Device Manager"
@echo "protos : Build for manager.pb.go file"
@echo "lintStyle : Verify code is properly gofmt-ed"
@echo "lintSanity : Verify that 'go vet' doesn't report any issues"
@echo "lintMod : Verify the integrity of the 'mod' files"
@echo "lint : Shorthand for lintStyle & lintSanity"
@echo "dockerCleanup : Kills and removes redis, etcd, device manager containers along with network."
@echo
.PHONY: install
all: init protos buildDeviceManager buildServices buildDockerImages runDockerImages createRedisSchema
createRedisSchema:
docker exec -t redis6380 /bin/bash -c "/etc/deviceManager/redis/createSchema.sh"
dockerCleanup:
docker rm -f redis6379 redis6380 device-manager etcd
docker network rm dm-net
runDockerImages:
docker network create dm-net
docker run -dp 6379:6379 --name redis6379 --net dm-net redis6379
docker run -dp 6380:6380 --name redis6380 --net dm-net redis6380
docker run -h etcd -dp 2379:2379 -p 2380:2380 --name etcd --net dm-net etcd
docker run -dp 45000:45000 --name device-manager --net dm-net device-manager
buildDockerImages:
sudo docker build --no-cache -t device-manager -f docker/Dockerfile.DeviceManager .
sudo docker build --no-cache -t redis6379 -f docker/Dockerfile.Redis.6379 .
sudo docker build --no-cache -t redis6380 -f docker/Dockerfile.Redis.6380 .
sudo docker build --no-cache -t etcd -f docker/Dockerfile.Etcd .
init:
sudo apt -y update
sudo apt -y upgrade
sudo apt -y install git curl unzip
go-install:
wget https://go.dev/dl/go1.17.10.linux-amd64.tar.gz
tar xzvf go1.17.10.linux-amd64.tar.gz
rm -f go1.17.10.linux-amd64.tar.gz
sudo mv go /usr/local
export GOROOT=${GO_DIR}
export GOPATH=$(HOME)/app
export PATH=$(HOME)/app/bin:${GO_DIR}/bin:$$PATH
mkdir -p ~/app/bin
@echo "export GOROOT=${GO_DIR}" >> $(HOME)/.bashrc
@echo "export GOPATH=$(HOME)/app" >> $(HOME)/.bashrc
@echo "export PATH=$(HOME)/app/bin:${GO_DIR}/bin:$$PATH" >> $(HOME)/.bashrc
@echo "!!Please source ~./bashrc file to take effect environment variable!!"
prereq:
curl -L -o /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip \
https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip
mkdir -p /tmp/protoc3
echo "${PROTOC_SHA256SUM} /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip" | sha256sum -c - \
&& unzip /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /tmp/protoc3 \
&& sudo mv /tmp/protoc3/bin/* /usr/local/bin/ \
&& sudo mv /tmp/protoc3/include/* /usr/local/include/
rm -rf /tmp/protoc3
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go get -v google.golang.org/[email protected]
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go install github.com/golang/protobuf/[email protected]
protos:
@cd svc-device-manager; \
GOROOT=${GO_DIR} GOPATH=$(HOME)/app PATH=$(PATH):$(HOME)/app/bin protoc --proto_path=proto \
--go_out=plugins=grpc:. \
proto/manager.proto
buildDeviceManager:
@echo "Building Device Manager binary..."
@cd svc-device-manager; \
${GO_BIN_PATH}/go build -o ../apps/svc-device-manager .
buildServices:
build/buildProtoFiles.sh
build/buildServices.sh
PATH:=$(GOPATH)/bin:$(PATH)
lintStyle:
ifeq (,$(shell which gofmt))
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go get -u github.com/golang/go/src/cmd/gofmt
endif
@echo "Running style check..."
@gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './src/vendor/*'))" ;\
if [ ! -z "$$gofmt_out" ]; then \
echo "$$gofmt_out" ;\
echo "Style check failed on one or more files ^, run 'go fmt' to fix." ;\
exit 1 ;\
fi
@echo "Style check OK"
lintSanity: protos
@echo "Running sanity check..."
@cd src; \
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go vet -mod=vendor ./...
@echo "Sanity check OK"
lintMod:
@echo "Running dependency check..."
@cd src; \
GOROOT=${GO_DIR} GOPATH=$(HOME)/app ${GO_BIN_PATH}/go mod verify
@echo "Dependency check OK"
lint: lintStyle lintSanity lintMod
# Rules to automatically install golangci-lint
GOLANGCI_LINT_TOOL?=$(shell which golangci-lint)
ifeq (,$(GOLANGCI_LINT_TOOL))
GOLANGCI_LINT_TOOL=$(GOPATH)/bin/golangci-lint
golangci_lint_tool_install:
# Same version as installed by Jenkins ci-management
# Note that install using `go get` is not recommended as per https://github.com/golangci/golangci-lint
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.17.0
else
golangci_lint_tool_install:
endif
sca: golangci_lint_tool_install
rm -rf ./sca-report
@mkdir -p ./sca-report
$(GOLANGCI_LINT_TOOL) run --out-format junit-xml ./... 2>&1 | tee ./sca-report/sca-report.xml