-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
93 lines (73 loc) · 3.17 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
# MIT License
#
# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# Service
NAME ?= smd
GIT_STATE := $(shell if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi)
BUILD_HOST := $(shell hostname)
BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
GO_VERSION := $(shell go version | awk '{print $3}')
BUILD_USER := $(shell whoami)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git rev-parse HEAD)
VERSION ?= $(shell git describe --tags --always --abbrev=0)
VERSION_D := $(shell git describe --tags --always --abbrev=0 --dirty --broken)
LDFLAGS := -ldflags "-X main.GitCommit=$(COMMIT) \
-X 'main.BuildTime=$(BUILD_TIME)' \
-X 'main.Version=$(VERSION)' \
-X 'main.GitBranch=$(BRANCH)' \
-X 'main.GitTag=$(VERSION)' \
-X 'main.GitState=$(GIT_STATE)' \
-X 'main.BuildHost=$(BUILD_HOST)' \
-X 'main.GoVersion=$(GO_VERSION)' \
-X 'main.BuildUser=$(BUILD_USER)'"
all: image unittest ct snyk ct_image
.PHONY : all image unittest snyk ct ct_image binaries coverage docker
image:
docker build $(NO_CACHE) --pull $(DOCKER_ARGS) --tag '$(NAME):$(VERSION)' -f Dockerfile .
unittest:
./runUnitTest.sh
snyk:
./runSnyk.sh
ct:
./runCT.sh
ct_image:
docker build --no-cache -f test/ct/Dockerfile test/ct/ --tag smd-test:$(VERSION})
binaries: smd smd-init smd-loader native
smd: cmd/smd/*.go
GOOS=linux GOARCH=amd64 go build -o smd -v -tags musl $(LDFLAGS) ./cmd/smd
smd-init: cmd/smd-init/*.go
GOOS=linux GOARCH=amd64 go build -o smd-init -v -tags musl $(LDFLAGS) ./cmd/smd-init
native:
go build -o smd-init-native -v -tags musl $(LDFLAGS) ./cmd/smd-init
go build -o smd-native -v -tags musl $(LDFLAGS) ./cmd/smd
go build -o smd-loader-native -v -tags musl $(LDFLAGS) ./cmd/smd-loader
smd-loader: cmd/smd-loader/*.go
GOOS=linux GOARCH=amd64 go build -o smd-loader -v -tags musl $(LDFLAGS) ./cmd/smd-loader
coverage:
go test -cover -v -tags musl ./cmd/* ./internal/* ./pkg/*
clean:
rm -f smd smd-init smd-loader smd-native smd-init-native
go clean -testcache
go clean -cache
go clean -modcache
docker: smd smd-init smd-loader
docker build -t ghcr.io/openchami/smd:$(VERSION_D) .