Skip to content

Commit

Permalink
Dev yobol (#2)
Browse files Browse the repository at this point in the history
* HTTP interfaces for operations

* update dependency

Co-authored-by: xufangyou <[email protected]>
  • Loading branch information
Yobol and xufangyou authored Mar 31, 2022
1 parent d7e31d3 commit 742a3d5
Show file tree
Hide file tree
Showing 41 changed files with 22,029 additions and 98 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Dockerfile*
.dockerignore
docker-compose*
.env

.git
.gitignore

go.sum

.vscode
.idea/

README.md
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ go.sum
.idea

# TLS Certificates
etc/security
etc/security
etc/resources
etc/config.yaml

VERSION
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:1.16-alpine3.15 AS builder

ARG ALPINE_PKG_BASE="make git"
ARG ALPINE_PKG_EXTRA=""

RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories
RUN apk add --update --no-cache ${ALPINE_PKG_BASE} ${ALPINE_PKG_EXTRA}

WORKDIR /edge

COPY . .

RUN make update || echo "skipping"
RUN make build

FROM alpine:3.15

WORKDIR /edge

COPY --from=builder /edge/edge-device-manager ./edge-device-manager
COPY --from=builder /edge/bin ./bin
COPY --from=builder /edge/etc ./etc
COPY --from=builder /edge/public ./public

RUN ./bin/boot.sh

EXPOSE 10996

CMD ["./edge-device-manager", "-cp", "etc", "-cn", "config"]

24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
APP=edge-device-manager
PKG=github.com/thingio/${APP}

VERSION=$(shell cat ./VERSION 2>/dev/null || echo 0.0.0)
GIT_SHA=$(shell git rev-parse HEAD)
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)

GOMODULE=GO111MODULE=on GOPROXY=https://goproxy.cn,https://goproxy.io/,https://mirrors.aliyun.com/goproxy,direct
GO=CGO_ENABLED=0 $(GOMODULE) go
CGO=CGO_ENABLED=1 $(GOMODULE) go
GOFLAGS=-ldflags "-X $(PKG)/version.Version=$(VERSION)"

.PHONY: update build
update:
$(GO) mod download all
build:
$(GO) build $(GOFLAGS) -o $(APP) ./main.go

.PHONY: dockerfile
dockerfile:
docker build -f Dockerfile . \
-t $(APP):$(GIT_SHA) \
-t $(APP):$(GIT_BRANCH) \
-t $(APP):$(VERSION)
2 changes: 2 additions & 0 deletions bin/boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# generate config.yaml from config.yaml.template
cp -f ./etc/config.yaml.template ./etc/config.yaml
16 changes: 10 additions & 6 deletions etc/config.yaml → etc/config.yaml.template
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
common:
driver_health_check_interval_second: 5
device_health_check_interval_second: 5
manager:
http:
port: 10996

msgbus:
type: "MQTT"
mqtt:
host: 127.0.0.1
port: 8883
port: 1883
username: admin
password: 123456
connect_timout_millisecond: 30000
token_timeout_millisecond: 1000
qos: 2
clean_session: false
method_call_timeout_millisecond: 1000
with_tls: true
with_tls: false
ca_path: etc/security/ca.crt
cert_path: etc/security/client.crt
key_path: etc/security/client.key
key_path: etc/security/client.key

log:
level: info
console: true
1 change: 0 additions & 1 deletion etc/resources/devices/randnum_test01.json

This file was deleted.

1 change: 0 additions & 1 deletion etc/resources/devices/randnum_test02.json

This file was deleted.

1 change: 0 additions & 1 deletion etc/resources/devices/randnum_test03.json

This file was deleted.

70 changes: 0 additions & 70 deletions etc/resources/products/randnum_test01.json

This file was deleted.

6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module github.com/thingio/edge-device-manager

require (
github.com/emicklei/go-restful-openapi/v2 v2.8.0
github.com/emicklei/go-restful/v3 v3.7.3
github.com/go-openapi/spec v0.20.4
github.com/gobwas/ws v1.1.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.8.1
github.com/thingio/edge-device-std v0.1.0
github.com/thingio/edge-device-std v0.2.1
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
25 changes: 25 additions & 0 deletions pkg/api/http/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package http

import (
"github.com/emicklei/go-restful/v3"
"github.com/patrickmn/go-cache"
"github.com/thingio/edge-device-manager/pkg/api/http/device"
"github.com/thingio/edge-device-manager/pkg/api/http/product"
"github.com/thingio/edge-device-manager/pkg/api/http/protocol"
"github.com/thingio/edge-device-manager/pkg/api/http/swagger"
"github.com/thingio/edge-device-manager/pkg/metastore"
"github.com/thingio/edge-device-std/operations"
)

const (
ApiRoot = "/api/v1"
)

func MountAllModules(protocols *cache.Cache, metaStore metastore.MetaStore,
mc operations.ManagerClient, ms operations.ManagerService) {
restful.Add(swagger.Resource{}.WebService("/apidocs"))

restful.Add(protocol.Resource{ProtocolCache: protocols}.WebService(ApiRoot + "/protocols"))
restful.Add(product.Resource{ProtocolCache: protocols, MetaStore: metaStore, OperationClient: mc}.WebService(ApiRoot + "/products"))
restful.Add(device.Resource{MetaStore: metaStore, OperationClient: mc, OperationService: ms}.WebService(ApiRoot + "/devices"))
}
Loading

0 comments on commit 742a3d5

Please sign in to comment.