Skip to content

Commit 129e16e

Browse files
Merge pull request #23 from industrial-edge/v1.8.0-1-1739181663
Sync version v1.8.0-1
2 parents 6f6e274 + 6b71368 commit 129e16e

29 files changed

Lines changed: 243 additions & 78 deletions

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ logs\\pclint-importer/
99
**/coverage_global.txt
1010
**/*report.out
1111
build/package/dist**
12+
.cache/*
13+
.gitlab/*
14+
build/package/govet-report.out
15+
build/package/golint-report.out
16+
build/package/golangcilint-report.xml
17+
build/package/gosec-report.json
18+
build/package/bin

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Siemens 2021
3+
Copyright (c) 2021 Siemens Aktiengesellschaft
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ Purpose of these repositories is to share reference implementation of IE Device
99

1010
NTP Service is a gRPC & Go based NTP configurator microservice for Edge Devices.
1111

12+
```bash
13+
//Set ntp server
14+
rpc SetNtpServer(Ntp) returns(google.protobuf.Empty);
15+
16+
//Returns ntp servers
17+
rpc GetNtpServer(google.protobuf.Empty) returns(Ntp);
18+
19+
//Returns NTP Status message.
20+
rpc GetStatus(google.protobuf.Empty) returns (Status);
21+
22+
```
23+
1224
## Overview
1325

1426
_Ntp Service_ is developed in the go programming language and gRPC. More information can be found [here](https://grpc.io/docs/). The Ntp service runs as a systemd service within the device that has a debian-based operating system.

api/siemens_iedge_dmapi_v1/Ntp.pb.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/siemens_iedge_dmapi_v1/Ntp.proto

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/*
2-
* Copyright (c) Siemens 2023
2+
* Copyright © Siemens 2021 - 2025. ALL RIGHTS RESERVED.
33
* Licensed under the MIT license
44
* See LICENSE file in the top-level directory
55
*/
66

7-
87
syntax = "proto3";
98
import "google/protobuf/empty.proto";
109
option go_package = ".;siemens_iedge_dmapi_v1";

api/siemens_iedge_dmapi_v1/Ntp_grpc.pb.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/ntpservice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) Siemens 2022
2+
* Copyright © Siemens 2020 - 2025. ALL RIGHTS RESERVED.
33
* Licensed under the MIT license
44
* See LICENSE file in the top-level directory
55
*/

app/ntpservice_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Copyright © Siemens 2020 - 2025. ALL RIGHTS RESERVED.
3+
* Licensed under the MIT license
4+
* See LICENSE file in the top-level directory
5+
*/
6+
17
package app
28

39
import (

build/package/.goreleaser.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Copyright © Siemens 2020 - 2025. ALL RIGHTS RESERVED.
2+
# Licensed under the MIT license
3+
# See LICENSE file in the top-level directory
4+
5+
version: 2
16
project_name: dm-ntp
27
dist: dist
38
env:
@@ -9,7 +14,7 @@ snapshot:
914
# for example).
1015
#
1116
# Default is `{{ .Tag }}-SNAPSHOT-{{.ShortCommit}}`.
12-
name_template: "{{ .Env.TAG }}"
17+
version_template: "{{ .Env.TAG }}"
1318

1419
# Build customization
1520
builds:
@@ -37,7 +42,7 @@ nfpms:
3742
homepage: https://github.com/industrial-edge/device-kit-ntp-service
3843
maintainer: https://github.com/industrial-edge/device-kit-ntp-service
3944
description: NTP service is a gRPC based ntp configurator microservice for SIEMENS devices.
40-
license: Copyright (c) Siemens 2023
45+
license: Copyright (c) 2023 Siemens AG
4146

4247
# Packages to be generated.
4348
formats:

build/package/Makefile

Lines changed: 87 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,100 @@
1-
PROJECT_ROOT:=${PWD}/../../
2-
LD_FLAGS="-w -s"
3-
VERSION=$(shell git describe --tags --match=v* --always --dirty)
4-
5-
SERVER_OUT := "bin/ntpservice"
6-
7-
PKG := "${PROJECT_ROOT}"
8-
SERVER_PKG_BUILD := "${PKG}/cmd/ntpservice"
9-
PKG_LIST := $(shell go list ${PKG}/...)
10-
GO_FILES := $(shell find . -name '*.go' | grep -v _test.go | grep -v .pb)
11-
12-
.PHONY: all
13-
all: build test vet lint fmt ## Run build, test, vet, lint and fmt
14-
15-
.PHONY: build
16-
# build: clean server client ## Build server
17-
build: clean server ## Build both api, server (maybe clients)
18-
19-
.PHONY: test
20-
test: ## Run unit tests
21-
$(info Running unit tests...)
22-
@go test -cover -short ${PKG_LIST}
23-
24-
.PHONY: vet
25-
vet:
26-
$(info Running go vet...)
27-
@go vet -all ${PKG_LIST} | tee -a govet-report.out
28-
29-
.PHONY: lint
30-
lint: # Lint the files
31-
$(info Running golint...)
1+
# Global Variables (Immutable)
2+
PROJECT_ROOT := $(CURDIR)/../..
3+
VERSION := $(shell git describe --tags --match='v*' --always --dirty)
4+
GO_MODULE := $(shell go list -m)
5+
6+
# Output Directories
7+
BIN_DIR := bin
8+
SERVER_OUT := $(BIN_DIR)/ntpservice
9+
10+
# Build Flags
11+
GO_LDFLAGS := -w -s
12+
GO_TAGS :=
13+
GO_TEST_FLAGS := -gcflags=all=-l -v -cover -short
14+
GO_RACE_FLAGS := -race
15+
GO_MSAN_FLAGS := -msan
16+
17+
# Packages
18+
PKG := $(PROJECT_ROOT)
19+
SERVER_PKG_BUILD := $(PKG)/cmd/ntpservice
20+
PKG_LIST := $(shell go list $(PKG)/...)
21+
22+
# Tools
23+
GOLANGCI_LINT_VERSION := latest
24+
GOSEC_VERSION := latest
25+
GORELEASER_CONFIG := $(PROJECT_ROOT)/build/package/.goreleaser.yml
26+
27+
# Phony Targets
28+
.PHONY: all build test govet golint golangcilint gosec race msan coverage coverhtml dep clean deb help
29+
30+
##@ General
31+
all: build test govet golint golangcilint gosec ## Build, test, govet, golint, golangcilint and gosec (default workflow)
32+
33+
help: ## Display this help
34+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) }' $(MAKEFILE_LIST)
35+
36+
##@ Build
37+
build: dep ## Build server binary
38+
@mkdir -p $(BIN_DIR)
39+
@echo "⇒ Building server..."
40+
@go build -trimpath -tags='$(GO_TAGS)' -ldflags='$(GO_LDFLAGS)' -o $(SERVER_OUT) $(SERVER_PKG_BUILD)
41+
@echo "✓ Server built: $(SERVER_OUT)"
42+
43+
##@ Testing & Validation
44+
test: dep ## Run unit tests
45+
@echo "⇒ Running unit tests..."
46+
@go test $(GO_TEST_FLAGS) $(PKG_LIST)
47+
48+
govet: dep ## Run static analysis with go vet
49+
@echo "⇒ Running govet..."
50+
@go vet -json $(PKG_LIST) 2>&1 | tee -a govet-report.out
51+
52+
golint: dep ## Run golint linter
53+
@echo "⇒ Running golint..."
54+
@go install golang.org/x/lint/golint@latest
3255
@golint ${PKG_LIST} | tee -a golint-report.out
3356

34-
.PHONY: fmt
35-
fmt:
36-
$(info Running go fmt...)
37-
@test -z $$(go fmt ${PKG_LIST})
57+
golangcilint: dep ## Run golangci-lint linter
58+
@echo "⇒ Running golangci-lint..."
59+
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
60+
@${GOPATH}/bin/golangci-lint run --out-format=checkstyle $(PROJECT_ROOT)/... | tee -a golangcilint-report.xml
61+
62+
gosec: dep ## Run gosec security scanner
63+
@echo "⇒ Running gosec..."
64+
@go install github.com/securego/gosec/v2/cmd/gosec@$(GOSEC_VERSION)
65+
@${GOPATH}/bin/gosec -exclude-dir=.cache -fmt=sonarqube $(PROJECT_ROOT)/... | tee -a gosec-report.json
3866

39-
race: dep ## Run data race detector
40-
$(info Running data race detector...)
41-
@go test -race -short ${PKG_LIST}
67+
race: dep ## Run tests with race detector
68+
@echo "Running race detector..."
69+
@go test $(GO_TEST_FLAGS) $(GO_RACE_FLAGS) $(PKG_LIST)
4270

4371
msan: dep ## Run memory sanitizer
44-
$(info Running memory sanitizer...)
45-
@go test -msan -short ${PKG_LIST}
72+
@echo "Running memory sanitizer..."
73+
@go test $(GO_TEST_FLAGS) $(GO_MSAN_FLAGS) $(PKG_LIST)
4674

47-
coverage: ## Generate global code coverage report
48-
$(info Generating global code coverage report...)
49-
./coverage.sh;
75+
##@ Coverage
76+
coverage: dep ## Generate global code coverage report
77+
@echo "⇒ Generating global code coverage report..."
78+
@./coverage.sh
5079

51-
coverhtml: ## Generate global code coverage report in HTML
52-
$(info Generating global code coverage report in HTML...)
53-
./coverage.sh html;
80+
coverhtml: coverage ## Generate global code coverage report in HTML
81+
@echo "Generating global code coverage report in HTML..."
82+
@./coverage.sh html;
5483

55-
dep: ## Get the dependencies
56-
$(info Get the dependencies...)
57-
@go get -v -d $(PKG)/...
58-
@go get -v golang.org/x/lint/golint
84+
##@ Dependencies
85+
dep: ## Install dependencies
86+
@echo "⇒ Installing tools..."
5987
@go mod tidy
6088

61-
server: dep ## Build the binary file for server
62-
$(info Building server...)
63-
@go build -v -ldflags=$(LD_FLAGS) -o $(SERVER_OUT) $(SERVER_PKG_BUILD)
64-
$(info Built server at $(SERVER_OUT) )
65-
66-
clean: ## Remove previous builds
67-
$(info Running clean up, removing previous builds...)
68-
@rm -rf $(SERVER_OUT)
69-
70-
.PHONY: deb
71-
deb: ## Build Debian package (deb)
72-
@goreleaser -f "${PROJECT_ROOT}build/package/.goreleaser.yml" --snapshot --skip-publish --clean
73-
74-
75-
# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
76-
help: ## Display this help screen
77-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
89+
##@ Cleanup
90+
clean: ## Remove build artifacts
91+
@echo "⇒ Cleaning build artifacts..."
92+
@rm -rf $(BIN_DIR) dist/ *-report.xml *-report.json *-report.out
93+
@find . -name "coverage*" ! -name "coverage.sh" -exec rm -rf {} +
7894

95+
##@ Packaging
96+
deb: dep ## Build Debian package
97+
@echo "⇒ Building Debian package..."
98+
@goreleaser --config $(GORELEASER_CONFIG) --snapshot --skip=publish --clean
7999

80100
.DEFAULT_GOAL := help

0 commit comments

Comments
 (0)