Skip to content

Commit

Permalink
feat: Update device service example for Levski (#139)
Browse files Browse the repository at this point in the history
* feat: Update device service example for Levski

Signed-off-by: Leonard Goodell <[email protected]>
  • Loading branch information
Lenny Goodell authored Nov 9, 2022
1 parent 08c0a1c commit 37066ee
Show file tree
Hide file tree
Showing 7 changed files with 570 additions and 20 deletions.
1 change: 0 additions & 1 deletion device-services/device-random/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
vendor/
cmd/device-random
glide.lock
go.sum
coverage.out
VERSION
8 changes: 2 additions & 6 deletions device-services/device-random/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@
# limitations under the License.
#

ARG BASE=golang:1.16-alpine3.12
ARG BASE=golang:1.18-alpine3.16
FROM ${BASE} AS builder
ARG ALPINE_PKG_BASE="make git openssh-client gcc libc-dev zeromq-dev libsodium-dev"
ARG ALPINE_PKG_EXTRA=""

# Replicate the APK repository override.
# If it is no longer necessary to avoid the CDN mirros we should consider dropping this as it is brittle.
RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories
# Install our build time packages.
RUN apk add --update --no-cache ${ALPINE_PKG_BASE} ${ALPINE_PKG_EXTRA}

WORKDIR /device-random

COPY . .

RUN go mod tidy
RUN go mod download

# To run tests in the build container:
Expand All @@ -38,7 +34,7 @@ RUN go mod download
ARG MAKE='make build'
RUN $MAKE

FROM alpine:3.12
FROM alpine:3.16

# dumb-init needed for injected secure bootstrapping entrypoint script when run in secure mode.
RUN apk add --update --no-cache zeromq dumb-init
Expand Down
4 changes: 3 additions & 1 deletion device-services/device-random/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ GOFLAGS=-ldflags "-X github.com/edgexfoundry/device-random.Version=$(VERSION)"

build: $(MICROSERVICES)

cmd/device-random:
tidy:
go mod tidy

cmd/device-random:
$(GOCGO) build $(GOFLAGS) -o $@ ./cmd

test:
Expand Down
1 change: 0 additions & 1 deletion device-services/device-random/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Random Integer Device Service
[![Build Status](https://jenkins.edgexfoundry.org/view/EdgeX%20Foundry%20Project/job/edgexfoundry/job/device-random/job/master/badge/icon)](https://jenkins.edgexfoundry.org/view/EdgeX%20Foundry%20Project/job/edgexfoundry/job/device-random/job/master/) [![Code Coverage](https://codecov.io/gh/edgexfoundry/device-random/branch/master/graph/badge.svg?token=tYEN8Kf8HF)](https://codecov.io/gh/edgexfoundry/device-random) [![Go Report Card](https://goreportcard.com/badge/github.com/edgexfoundry/device-random)](https://goreportcard.com/report/github.com/edgexfoundry/device-random) [![GitHub Latest Dev Tag)](https://img.shields.io/github/v/tag/edgexfoundry/device-random?include_prereleases&sort=semver&label=latest-dev)](https://github.com/edgexfoundry/device-random/tags) ![GitHub Latest Stable Tag)](https://img.shields.io/github/v/tag/edgexfoundry/device-random?sort=semver&label=latest-stable) [![GitHub License](https://img.shields.io/github/license/edgexfoundry/device-random)](https://choosealicense.com/licenses/apache-2.0/) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/edgexfoundry/device-random) [![GitHub Pull Requests](https://img.shields.io/github/issues-pr-raw/edgexfoundry/device-random)](https://github.com/edgexfoundry/device-random/pulls) [![GitHub Contributors](https://img.shields.io/github/contributors/edgexfoundry/device-random)](https://github.com/edgexfoundry/device-random/contributors) [![GitHub Committers](https://img.shields.io/badge/team-committers-green)](https://github.com/orgs/edgexfoundry/teams/device-random-committers/members) [![GitHub Commit Activity](https://img.shields.io/github/commit-activity/m/edgexfoundry/device-random)](https://github.com/edgexfoundry/device-random/commits)

## Overview
This Device Service is a reference example of a Device Service developed with **[Go Device Service SDK](https://github.com/edgexfoundry/device-sdk-go)**.
Expand Down
46 changes: 40 additions & 6 deletions device-services/device-random/cmd/res/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ LogLevel = 'INFO'
[Writable.InsecureSecrets.DB.Secrets]
username = ""
password = ""
[Writable.Reading]
ReadingUnits = true
[Writable.Telemetry]
Interval = "30s"
PublishTopicPrefix = "edgex/telemetry" # /<service-name>/<metric-name> will be added to this Publish Topic prefix
[Writable.Telemetry.Metrics] # All service's metric names must be present in this list.
# Device SDK provided Metrics
EventsSent = false
ReadingsSent = false
# Common Security Service Metrics
SecuritySecretsRequested = false
SecuritySecretsStored = false
SecurityConsulTokensRequested = false
SecurityConsulTokenDuration = false
[Writable.Telemetry.Tags] # Contains the service level tags to be attached to all the service's metrics
#Gateway="my-iot-gateway" # Tag must be added here since Env Override can only change existing value, not added new ones.

[Service]
HealthCheckInterval = '10s'
Expand All @@ -17,6 +33,14 @@ StartupMsg = 'device random started'
# MaxRequestSize limit the request body size in byte of put command
MaxRequestSize = 0 # value 0 unlimit the request size.
RequestTimeout = '5s'
[Service.CORSConfiguration]
EnableCORS = false
CORSAllowCredentials = false
CORSAllowedOrigin = "https://localhost"
CORSAllowedMethods = "GET, POST, PUT, PATCH, DELETE"
CORSAllowedHeaders = "Authorization, Accept, Accept-Language, Content-Language, Content-Type, X-Correlation-ID"
CORSExposeHeaders = "Cache-Control, Content-Language, Content-Length, Content-Type, Expires, Last-Modified, Pragma, X-Correlation-ID"
CORSMaxAge = 3600

[Registry]
Host = 'localhost'
Expand All @@ -42,17 +66,27 @@ Type = 'redis'
AuthMode = 'usernamepassword' # required for redis messagebus (secure or insecure).
SecretName = "redisdb"
PublishTopicPrefix = 'edgex/events/device' # /<device-profile-name>/<device-name>/<source-name> will be added to this Publish Topic prefix
[MessageQueue.Topics]
CommandRequestTopic = "edgex/device/command/request/device-random/#" # subscribing for inbound command requests
CommandResponseTopicPrefix = "edgex/device/command/response" # publishing outbound command responses; <device-service>/<device-name>/<command-name>/<method> will be added to this publish topic prefix
[MessageQueue.Optional]
# Default MQTT Specific options that need to be here to enable environment variable overrides of them
# Client Identifiers
# Default MQTT & NATS Specific options that need to be here to enable environment variable overrides of them
ClientId = "device-random"
# Connection information
Qos = "0" # Quality of Sevice values are 0 (At most once), 1 (At least once) or 2 (Exactly once)
KeepAlive = "10" # Seconds (must be 2 or greater)
Qos = "0" # Quality of Service values are 0 (At most once), 1 (At least once) or 2 (Exactly once)
KeepAlive = "10" # Seconds (must be 2 or greater)
Retained = "false"
AutoReconnect = "true"
ConnectTimeout = "5" # Seconds
SkipCertVerify = "false" # Only used if Cert/Key file or Cert/Key PEMblock are specified [MessageQueue.Optional]
SkipCertVerify = "false"
# Default NATS Specific options that need to be here to enable environment variable overrides of them
Format = "nats"
RetryOnFailedConnect = "true"
QueueGroup = ""
Durable = ""
AutoProvision = "true"
Deliver = "new"
DefaultPubRetryAttempts = "2"
Subject = "edgex/#" # Required for NATS JetStream only for stream auto provisioning

# Example SecretStore configuration.
# Only used when EDGEX_SECURITY_SECRET_STORE=true
Expand Down
70 changes: 65 additions & 5 deletions device-services/device-random/go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
module github.com/edgexfoundry/device-random

go 1.18

require (
github.com/edgexfoundry/device-sdk-go/v2 v2.0.0
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.0.0
github.com/hashicorp/go-sockaddr v1.0.1 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/edgexfoundry/device-sdk-go/v2 v2.3.0
github.com/edgexfoundry/go-mod-core-contracts/v2 v2.3.0
)

go 1.16
require (
bitbucket.org/bertimus9/systemstat v0.5.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/eclipse/paho.mqtt.golang v1.4.1 // indirect
github.com/edgexfoundry/go-mod-bootstrap/v2 v2.3.0 // indirect
github.com/edgexfoundry/go-mod-configuration/v2 v2.3.0 // indirect
github.com/edgexfoundry/go-mod-messaging/v2 v2.3.0 // indirect
github.com/edgexfoundry/go-mod-registry/v2 v2.3.0 // indirect
github.com/edgexfoundry/go-mod-secrets/v2 v2.3.0 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/go-redis/redis/v7 v7.3.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/consul/api v1.15.3 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-hclog v0.14.1 // indirect
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/serf v0.9.7 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/consulstructure v0.0.0-20190329231841-56fdc4d2da54 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/nats-io/nats.go v1.18.0 // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/pebbe/zmq4 v1.2.7 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/spiffe/go-spiffe/v2 v2.1.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zeebo/errs v1.2.2 // indirect
golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/grpc v1.46.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/square/go-jose.v2 v2.4.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 37066ee

Please sign in to comment.