Browse Source

move ui files to their respective containers

Mark deVilliers 2 years ago
parent
commit
e4ff16716c

+ 4 - 17
Makefile

@@ -66,7 +66,6 @@ docker-build: clean linux-amd64 ## build docker images for all of the executable
66 66
 	docker build -t prototype/metadata:latest -t prototype/metadata:$(SOURCE_VERSION) -f=./docker/Dockerfile.metadata .
67 67
 	docker build -t prototype/node:latest -t prototype/node:$(SOURCE_VERSION) -f=./docker/Dockerfile.node .
68 68
 	docker build -t prototype/storage:latest -t prototype/storage:$(SOURCE_VERSION) -f=./docker/Dockerfile.storage .
69
-	docker build -t prototype/ui:latest -t prototype/ui:$(SOURCE_VERSION) -f=./docker/Dockerfile.ui .
70 69
 
71 70
 .PHONY: docker-build
72 71
 
@@ -85,13 +84,13 @@ client-storage: ## build golang client for the storage service - requires a loca
85 84
 
86 85
 .PHONY: client-storage
87 86
 
88
-darwin-amd64: tmp/build/darwin-amd64/metadata tmp/build/darwin-amd64/storage tmp/build/darwin-amd64/node tmp/build/darwin-amd64/ui ## build for mac amd64
87
+darwin-amd64: tmp/build/darwin-amd64/metadata tmp/build/darwin-amd64/storage tmp/build/darwin-amd64/node ## build for mac amd64
89 88
 
90
-linux-i386: tmp/build/linux-i386/metadata tmp/build/linux-i386/storage tmp/build/linux-i386/node tmp/build/linux-i386/ui ## build for linux i386
89
+linux-i386: tmp/build/linux-i386/metadata tmp/build/linux-i386/storage tmp/build/linux-i386/node ## build for linux i386
91 90
 
92
-linux-amd64: tmp/build/linux-amd64/metadata tmp/build/linux-amd64/storage tmp/build/linux-amd64/node tmp/build/linux-amd64/ui ## build for linux amd64
91
+linux-amd64: tmp/build/linux-amd64/metadata tmp/build/linux-amd64/storage tmp/build/linux-amd64/node ## build for linux amd64
93 92
 
94
-linux-arm: tmp/build/linux-arm/metadata tmp/build/linux-arm/sort tmp/build/linux-arm/node tmp/build/linux-arm/ui ## build for linux arm (raspberry-pi)
93
+linux-arm: tmp/build/linux-arm/metadata tmp/build/linux-arm/sort tmp/build/linux-arm/node ## build for linux arm (raspberry-pi)
95 94
 
96 95
 .PHONY: darwin-amd64 linux-i386 linux-amd64 linux-arm
97 96
 
@@ -104,9 +103,6 @@ tmp/build/linux-i386/storage:
104 103
 tmp/build/linux-i386/node:
105 104
 	GOOS=linux GOARCH=386 go build $(BUILD_FLAGS) -o $(@) ./cmd/node
106 105
 
107
-tmp/build/linux-i386/ui:
108
-	GOOS=linux GOARCH=386 go build $(BUILD_FLAGS) -o $(@) ./cmd/ui
109
-
110 106
 ## linux-amd64
111 107
 tmp/build/linux-amd64/metadata:
112 108
 	GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/metadata
@@ -117,9 +113,6 @@ tmp/build/linux-amd64/storage:
117 113
 tmp/build/linux-amd64/node:
118 114
 	GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/node
119 115
 
120
-tmp/build/linux-amd64/ui:
121
-	GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/ui
122
-
123 116
 ## linux-arm
124 117
 tmp/build/linux-arm/metadata:
125 118
 	GOOS=linux GOARCH=arm go build $(BUILD_FLAGS) -o $(@) ./cmd/metadata
@@ -130,9 +123,6 @@ tmp/build/linux-arm/storage:
130 123
 tmp/build/linux-arm/node:
131 124
 	GOOS=linux GOARCH=arm go build $(BUILD_FLAGS) -o $(@) ./cmd/node
132 125
 
133
-tmp/build/linux-arm/ui:
134
-	GOOS=linux GOARCH=arm go build $(BUILD_FLAGS) -o $(@) ./cmd/ui
135
-
136 126
 ## darwin-amd64
137 127
 tmp/build/darwin-amd64/metadata:
138 128
 	GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/metadata
@@ -143,9 +133,6 @@ tmp/build/darwin-amd64/storage:
143 133
 tmp/build/darwin-amd64/node:
144 134
 	GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/node
145 135
 
146
-tmp/build/darwin-amd64/ui:
147
-	GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $(@) ./cmd/ui
148
-
149 136
 
150 137
 # 'help' parses the Makefile and displays the help text
151 138
 help:

+ 1 - 0
cmd/metadata/cmd_server.go

@@ -14,6 +14,7 @@ var serverCommand = &cobra.Command{
14 14
 			Binding:        _config.Binding,
15 15
 			SwaggerUIPath:  _config.SwaggerUIPath,
16 16
 			WebServicesURL: _config.WebServicesURL,
17
+			AssetsPath:     _config.AssetsPath,
17 18
 		})
18 19
 
19 20
 	},

+ 2 - 0
cmd/metadata/main.go

@@ -20,6 +20,7 @@ type config struct {
20 20
 	Binding        string `envconfig:"BINDING" default:":8081"`
21 21
 	SwaggerUIPath  string `envconfig:"SWAGGER_UI_PATH" default:"../../swagger-ui/"`
22 22
 	WebServicesURL string `envconfig:"WEBSERVICES_URL" default:"http://localhost:8081"`
23
+	AssetsPath     string `envconfig:"ASSETS_PATH" default:"../../ui/"`
23 24
 }
24 25
 
25 26
 func newConfig() *config {
@@ -32,6 +33,7 @@ func (o *config) AddFlags(fs *pflag.FlagSet) {
32 33
 	fs.StringVarP(&o.Binding, "binding", "b", o.Binding, "binding address in form of {ip}:port")
33 34
 	fs.StringVarP(&o.SwaggerUIPath, "swagger-ui", "s", o.SwaggerUIPath, "path to folder to server Swagger UI")
34 35
 	fs.StringVarP(&o.WebServicesURL, "url", "u", o.WebServicesURL, "external address of the API service")
36
+	fs.StringVarP(&o.AssetsPath, "assets", "a", o.AssetsPath, "path to folder of static files to serve")
35 37
 }
36 38
 
37 39
 func init() {

+ 1 - 0
cmd/node/cmd_server.go

@@ -16,6 +16,7 @@ var serverCommand = &cobra.Command{
16 16
 			WebServicesURL:         _config.WebServicesURL,
17 17
 			MetadataServiceAddress: _config.MetadataServiceAddress,
18 18
 			StorageServiceAddress:  _config.StorageServiceAddress,
19
+			AssetsPath:             _config.AssetsPath,
19 20
 		})
20 21
 
21 22
 	},

+ 2 - 0
cmd/node/main.go

@@ -22,6 +22,7 @@ type config struct {
22 22
 	WebServicesURL         string `envconfig:"WEBSERVICES_URL" default:"http://localhost:8080"`
23 23
 	MetadataServiceAddress string `envconfig:"METADATA_SERVICE_ADDRESS" default:"http://localhost:8081"`
24 24
 	StorageServiceAddress  string `envconfig:"STORAGE_SERVICE_ADDRESS" default:"http://localhost:8083"`
25
+	AssetsPath             string `envconfig:"ASSETS_PATH" default:"../../ui/"`
25 26
 }
26 27
 
27 28
 func newConfig() *config {
@@ -36,6 +37,7 @@ func (o *config) AddFlags(fs *pflag.FlagSet) {
36 37
 	fs.StringVarP(&o.WebServicesURL, "url", "u", o.WebServicesURL, "public address of the API service")
37 38
 	fs.StringVarP(&o.MetadataServiceAddress, "metadata", "m", o.MetadataServiceAddress, "public address of the Metadata service")
38 39
 	fs.StringVarP(&o.StorageServiceAddress, "storage", "s", o.StorageServiceAddress, "public address of the Storage service")
40
+	fs.StringVarP(&o.AssetsPath, "assets", "a", o.AssetsPath, "path to folder of static files to serve")
39 41
 }
40 42
 
41 43
 func init() {

+ 0 - 20
cmd/ui/cmd_server.go

@@ -1,20 +0,0 @@
1
-package main
2
-
3
-import (
4
-	"log"
5
-	"net/http"
6
-
7
-	"github.com/spf13/cobra"
8
-)
9
-
10
-var serverCommand = &cobra.Command{
11
-	Use:   "server",
12
-	Short: "Start ui server.",
13
-	RunE: func(cmd *cobra.Command, args []string) error {
14
-
15
-		http.Handle("/", http.FileServer(http.Dir(_config.AssetsPath)))
16
-
17
-		log.Printf("Serving %s on HTTP port: %s\n", _config.AssetsPath, _config.Binding)
18
-		return http.ListenAndServe(_config.Binding, nil)
19
-	},
20
-}

+ 0 - 46
cmd/ui/main.go

@@ -1,46 +0,0 @@
1
-package main
2
-
3
-import (
4
-	"os"
5
-
6
-	"gogs.dyne.org/DECODE/decode-prototype-da/cmd"
7
-
8
-	"github.com/kelseyhightower/envconfig"
9
-	"github.com/spf13/cobra"
10
-	"github.com/spf13/pflag"
11
-)
12
-
13
-var RootCmd = &cobra.Command{
14
-	Use: "ui",
15
-}
16
-
17
-var _config = newConfig()
18
-
19
-type config struct {
20
-	Binding    string `envconfig:"BINDING" default:":8085"`
21
-	AssetsPath string `envconfig:"ASSETS_PATH" default:"../../ui/"`
22
-}
23
-
24
-func newConfig() *config {
25
-	c := &config{}
26
-	envconfig.Process("", c)
27
-	return c
28
-}
29
-
30
-func (o *config) AddFlags(fs *pflag.FlagSet) {
31
-	fs.StringVarP(&o.Binding, "binding", "b", o.Binding, "binding address in form of {ip}:port")
32
-	fs.StringVarP(&o.AssetsPath, "assets", "a", o.AssetsPath, "path to folder of static files to serve")
33
-}
34
-
35
-func init() {
36
-	RootCmd.AddCommand(serverCommand)
37
-	RootCmd.AddCommand(cmd.VersionCommand)
38
-
39
-	_config.AddFlags(RootCmd.PersistentFlags())
40
-}
41
-
42
-func main() {
43
-	if err := RootCmd.Execute(); err != nil {
44
-		os.Exit(-1)
45
-	}
46
-}

+ 0 - 16
docker-compose.yml

@@ -27,22 +27,6 @@ services:
27 27
         # address of the node
28 28
         # TODO : resolve this to be the external address
29 29
         #- WEBSERVICES_URL=http://node_one:8080
30
-  ## node_one_ui is the user interface for the decode node
31
-  node_one_ui:
32
-    image : prototype/ui
33
-    ports:
34
-        - "8085:8085"
35
-    links :
36
-        - "metadata:metadata"
37
-        - "node_one:node"
38
-    depends_on:
39
-        - "metadata"
40
-        - "node_one"
41
-    environment:
42
-        # address of the metadata service
43
-        - METADATA_SERVICE_ADDRESS=http://metadata:8081
44
-        # address of the node service
45
-        - NODE_SERVICE_ADDRESS=http://node:8080
46 30
   ## node_one_device_hub is an instance of device hub for IOT integration
47 31
   ##node_one_device_hub:
48 32
   ##  image: thingful/device-hub

+ 6 - 0
docker/Dockerfile.metadata

@@ -5,6 +5,12 @@ EXPOSE 8081
5 5
 COPY tmp/build/linux-amd64/metadata /prototype/
6 6
 COPY ./swagger-ui/ /prototype/swagger-ui/
7 7
 
8
+COPY ui/search.html /prototype/assets/index.html
9
+COPY ui/search.js /prototype/assets/
10
+COPY ui/static /prototype/assets/static/
11
+
8 12
 ENV SWAGGER_UI_PATH=/prototype/swagger-ui/
13
+ENV ASSETS_PATH=/prototype/assets/
14
+
9 15
 
10 16
 ENTRYPOINT [ "/prototype/metadata", "server"]

+ 6 - 0
docker/Dockerfile.node

@@ -5,6 +5,12 @@ EXPOSE 8080
5 5
 COPY tmp/build/linux-amd64/node /prototype/
6 6
 COPY ./swagger-ui/ /prototype/swagger-ui/
7 7
 
8
+COPY ui/node.html /prototype/assets/index.html
9
+COPY ui/node.js /prototype/assets/
10
+COPY ui/static /prototype/assets/static/
11
+
8 12
 ENV SWAGGER_UI_PATH=/prototype/swagger-ui/
13
+ENV ASSETS_PATH=/prototype/assets/
14
+
9 15
 
10 16
 ENTRYPOINT [ "/prototype/node", "server"]

+ 0 - 16
docker/Dockerfile.ui

@@ -1,16 +0,0 @@
1
-FROM bitnami/minideb:stretch
2
-
3
-EXPOSE 8085
4
-
5
-COPY tmp/build/linux-amd64/ui /prototype/
6
-
7
-# add static web assets
8
-COPY ui/search.html /prototype/assets/
9
-COPY ui/search.js /prototype/assets/
10
-COPY ui/node.html /prototype/assets/
11
-COPY ui/node.js /prototype/assets/
12
-COPY ui/static /prototype/assets/static/
13
-
14
-ENV ASSETS_PATH=/prototype/assets/
15
-
16
-ENTRYPOINT [ "/prototype/ui", "server"]

+ 4 - 0
metadata/server.go

@@ -14,6 +14,7 @@ type Options struct {
14 14
 	Binding        string
15 15
 	SwaggerUIPath  string
16 16
 	WebServicesURL string
17
+	AssetsPath     string
17 18
 }
18 19
 
19 20
 func Serve(options Options) error {
@@ -43,6 +44,9 @@ func Serve(options Options) error {
43 44
 	// Open http://localhost:8080/apidocs/?url=http://localhost:8080/apidocs.json
44 45
 	http.Handle("/apidocs/", http.StripPrefix("/apidocs/", http.FileServer(http.Dir(options.SwaggerUIPath))))
45 46
 
47
+	// Serve the ui
48
+	http.Handle("/", http.FileServer(http.Dir(options.AssetsPath)))
49
+
46 50
 	log.Printf("start listening on %s", options.Binding)
47 51
 	return http.ListenAndServe(options.Binding, nil)
48 52
 }

+ 5 - 0
node/server.go

@@ -23,6 +23,7 @@ type Options struct {
23 23
 	WebServicesURL         string
24 24
 	MetadataServiceAddress string
25 25
 	StorageServiceAddress  string
26
+	AssetsPath             string
26 27
 }
27 28
 
28 29
 func Serve(options Options) error {
@@ -77,6 +78,10 @@ func Serve(options Options) error {
77 78
 	// You need to download the Swagger HTML5 assets and change the FilePath location in the config below.
78 79
 	// Open http://localhost:8080/apidocs/?url=http://localhost:8080/apidocs.json
79 80
 	http.Handle("/apidocs/", http.StripPrefix("/apidocs/", http.FileServer(http.Dir(options.SwaggerUIPath))))
81
+
82
+	// Serve the ui
83
+	http.Handle("/", http.FileServer(http.Dir(options.AssetsPath)))
84
+
80 85
 	log.Printf("start listening on %s", options.Binding)
81 86
 
82 87
 	return http.ListenAndServe(options.Binding, nil)