Browse Source

add functional make file with versioning and multiple platforms

Mark deVilliers 2 years ago
parent
commit
fe513c735c
8 changed files with 161 additions and 2 deletions
  1. 114 0
      Makefile
  2. 17 0
      cmd/cmd_version.go
  3. 4 0
      cmd/metadata/main.go
  4. 4 0
      cmd/node/main.go
  5. 4 1
      cmd/storage/cmd_server.go
  6. 4 0
      cmd/storage/main.go
  7. 1 1
      metadata/services/catalog.go
  8. 13 0
      version.go

+ 114 - 0
Makefile

@@ -0,0 +1,114 @@
1
+SOURCE_VERSION = $(shell git rev-parse --short=6 HEAD)
2
+BUILD_FLAGS = -v -ldflags "-X gogs.dyne.org/DECODE/decode-prototype-da.SourceVersion=$(SOURCE_VERSION)"
3
+PACKAGES := $(shell go list ./... | grep -v /vendor/ )
4
+
5
+GO_TEST = go test -covermode=atomic
6
+GO_INTEGRATION = $(GO_TEST) -bench=. -v --tags=integration
7
+GO_COVER = go tool cover
8
+GO_BENCH = go test -bench=.
9
+ARTEFACT_DIR = coverage
10
+
11
+all: linux-arm linux-i386 linux-amd64 darwin-amd64 ## build executables for the various environments
12
+
13
+.PHONY: all
14
+
15
+get-build-deps: ## install build dependencies 
16
+	go get github.com/chespinoza/goliscan
17
+
18
+.PHONY: get-build-deps
19
+
20
+check-vendor-licenses: ## check if licenses of project dependencies meet project requirements 
21
+	@goliscan check --direct-only
22
+	@goliscan check --indirect-only
23
+
24
+.PHONY: check-vendor-licenses
25
+
26
+test: ## run tests
27
+	$(GO_TEST) $(PACKAGES)
28
+
29
+.PHONY: test
30
+
31
+test_integration: ## run integration tests (SLOW)
32
+	mkdir -p $(ARTEFACT_DIR)
33
+	echo 'mode: atomic' > $(ARTEFACT_DIR)/cover-integration.out
34
+	touch $(ARTEFACT_DIR)/cover.tmp
35
+	$(foreach package, $(PACKAGES), $(GO_INTEGRATION) -coverprofile=$(ARTEFACT_DIR)/cover.tmp $(package) && tail -n +2 $(ARTEFACT_DIR)/cover.tmp >> $(ARTEFACT_DIR)/cover-integration.out || exit;)
36
+.PHONY: test_integration
37
+
38
+clean: ## clean up
39
+	rm -rf tmp/
40
+	rm -rf $(ARTEFACT_DIR)
41
+
42
+.PHONY: clean
43
+
44
+bench: ## run benchmark tests
45
+	$(GO_BENCH) $(PACKAGES)
46
+
47
+.PHONY: bench
48
+
49
+coverage: test_integration ## generate and display coverage report
50
+	$(GO_COVER) -func=$(ARTEFACT_DIR)/cover-integration.out
51
+
52
+.PHONY: test_integration
53
+
54
+docker_up: ## run dependencies as docker containers
55
+	docker-compose up -d
56
+	docker ps
57
+
58
+.PHONY: docker_up
59
+
60
+darwin-amd64: tmp/build/darwin-amd64/metadata tmp/build/darwin-amd64/storage tmp/build/darwin-amd64/node  ## build for mac amd64
61
+
62
+linux-i386: tmp/build/linux-i386/metadata tmp/build/linux-i386/storage tmp/build/linux-i386/node ## build for linux i386
63
+
64
+linux-amd64: tmp/build/linux-amd64/metadata tmp/build/linux-amd64/storage tmp/build/linux-amd64/node ## build for linux amd64
65
+
66
+linux-arm: tmp/build/linux-arm/metadata tmp/build/linux-arm/sort tmp/build/linux-arm/node ## build for linux arm (raspberry-pi)
67
+
68
+.PHONY: darwin-amd64 linux-i386 linux-amd64 linux-arm
69
+
70
+tmp/build/linux-i386/metadata:
71
+	GOOS=linux GOARCH=386 go build $(BUILD_FLAGS) -o $(@) ./cmd/metadata
72
+
73
+tmp/build/linux-i386/storage:
74
+	GOOS=linux GOARCH=386 go build $(BUILD_FLAGS) -o $(@) ./cmd/storage
75
+
76
+tmp/build/linux-i386/node:
77
+	GOOS=linux GOARCH=386 go build $(BUILD_FLAGS) -o $(@) ./cmd/node
78
+
79
+
80
+## linux-amd64
81
+tmp/build/linux-amd64/metadata:
82
+	GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/metadata
83
+
84
+tmp/build/linux-amd64/storage:
85
+	GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/storage
86
+
87
+tmp/build/linux-amd64/node:
88
+	GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/node
89
+
90
+## linux-arm
91
+tmp/build/linux-arm/metadata:
92
+	GOOS=linux GOARCH=arm go build $(BUILD_FLAGS) -o $(@) ./cmd/metadata
93
+
94
+tmp/build/linux-arm/storage:
95
+	GOOS=linux GOARCH=arm go build $(BUILD_FLAGS) -o $(@) ./cmd/storage
96
+
97
+tmp/build/linux-arm/node:
98
+	GOOS=linux GOARCH=arm go build $(BUILD_FLAGS) -o $(@) ./cmd/node
99
+
100
+## darwin-amd64
101
+tmp/build/darwin-amd64/metadata:
102
+	GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/metadata
103
+
104
+tmp/build/darwin-amd64/storage:
105
+	GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/storage
106
+
107
+tmp/build/darwin-amd64/node:
108
+	GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/node
109
+
110
+# 'help' parses the Makefile and displays the help text
111
+help:
112
+	@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
113
+
114
+.PHONY: help

+ 17 - 0
cmd/cmd_version.go

@@ -0,0 +1,17 @@
1
+package cmd
2
+
3
+import (
4
+	"fmt"
5
+
6
+	"github.com/spf13/cobra"
7
+	prototype "gogs.dyne.org/DECODE/decode-prototype-da"
8
+)
9
+
10
+var VersionCommand = &cobra.Command{
11
+	Use:   "version",
12
+	Short: "Display version information",
13
+	RunE: func(cmd *cobra.Command, args []string) error {
14
+		fmt.Println(prototype.VersionString())
15
+		return nil
16
+	},
17
+}

+ 4 - 0
cmd/metadata/main.go

@@ -3,6 +3,8 @@ package main
3 3
 import (
4 4
 	"os"
5 5
 
6
+	"gogs.dyne.org/DECODE/decode-prototype-da/cmd"
7
+
6 8
 	"github.com/kelseyhightower/envconfig"
7 9
 	"github.com/spf13/cobra"
8 10
 	"github.com/spf13/pflag"
@@ -55,6 +57,8 @@ func (o *config) AddFlags(fs *pflag.FlagSet) {
55 57
 
56 58
 func init() {
57 59
 	RootCmd.AddCommand(serverCommand)
60
+	RootCmd.AddCommand(cmd.VersionCommand)
61
+
58 62
 	_config.AddFlags(RootCmd.PersistentFlags())
59 63
 }
60 64
 

+ 4 - 0
cmd/node/main.go

@@ -3,6 +3,8 @@ package main
3 3
 import (
4 4
 	"os"
5 5
 
6
+	"gogs.dyne.org/DECODE/decode-prototype-da/cmd"
7
+
6 8
 	"github.com/kelseyhightower/envconfig"
7 9
 	"github.com/spf13/cobra"
8 10
 	"github.com/spf13/pflag"
@@ -55,6 +57,8 @@ func (o *config) AddFlags(fs *pflag.FlagSet) {
55 57
 
56 58
 func init() {
57 59
 	RootCmd.AddCommand(serverCommand)
60
+	RootCmd.AddCommand(cmd.VersionCommand)
61
+
58 62
 	_config.AddFlags(RootCmd.PersistentFlags())
59 63
 }
60 64
 

+ 4 - 1
cmd/storage/cmd_server.go

@@ -1,6 +1,9 @@
1 1
 package main
2 2
 
3
-import "github.com/spf13/cobra"
3
+import (
4
+	"github.com/spf13/cobra"
5
+	"gogs.dyne.org/DECODE/decode-prototype-da/storage"
6
+)
4 7
 
5 8
 var serverCommand = &cobra.Command{
6 9
 	Use:   "server",

+ 4 - 0
cmd/storage/main.go

@@ -3,6 +3,8 @@ package main
3 3
 import (
4 4
 	"os"
5 5
 
6
+	"gogs.dyne.org/DECODE/decode-prototype-da/cmd"
7
+
6 8
 	"github.com/kelseyhightower/envconfig"
7 9
 	"github.com/spf13/cobra"
8 10
 	"github.com/spf13/pflag"
@@ -55,6 +57,8 @@ func (o *config) AddFlags(fs *pflag.FlagSet) {
55 57
 
56 58
 func init() {
57 59
 	RootCmd.AddCommand(serverCommand)
60
+	RootCmd.AddCommand(cmd.VersionCommand)
61
+
58 62
 	_config.AddFlags(RootCmd.PersistentFlags())
59 63
 }
60 64
 

+ 1 - 1
metadata/services/catalog.go

@@ -9,7 +9,7 @@ func NewCatalogService() catalogResource {
9 9
 	return catalogResource{}
10 10
 }
11 11
 
12
-func (e dataResource) WebService() *restful.WebService {
12
+func (e catalogResource) WebService() *restful.WebService {
13 13
 	ws := new(restful.WebService)
14 14
 
15 15
 	ws.

+ 13 - 0
version.go

@@ -0,0 +1,13 @@
1
+package prototype
2
+
3
+import "fmt"
4
+
5
+var (
6
+	// SourceVersion is set via the makefile
7
+	SourceVersion = "DEVELOPMENT"
8
+)
9
+
10
+// VersionString returns the version of the software
11
+func VersionString() string {
12
+	return fmt.Sprintf("1.0.%s", SourceVersion)
13
+}