Merge pull request #3 from edgebox-iot/make

Makefile + more
pull/5/head
Paulo Truta 2021-02-12 18:40:45 +01:00 committed by GitHub
commit 34a21094ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 5 deletions

View File

@ -30,7 +30,7 @@ jobs:
fi
- name: Build
run: go build -v .
run: make build
- name: Test
run: go test -v .
run: go test -v ./...

4
.gitignore vendored
View File

@ -14,3 +14,7 @@ main
# Dependency directories (remove the comment below to include it)
# vendor/
# Build
/bin

View File

@ -8,4 +8,4 @@ RUN go mod download
RUN go get github.com/githubnemo/CompileDaemon
ENTRYPOINT CompileDaemon --build="go build main.go" --command=./main
ENTRYPOINT CompileDaemon --build="make build" --command=./bin/sysctl

23
Makefile 100644
View File

@ -0,0 +1,23 @@
PROJECT?=github.com/edgebox-iot/sysctl
RELEASE ?= dev
COMMIT := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
BUILD_DIR = bin
build-all:
GOOS=linux GOARCH=amd64 make build
GOOS=linux GOARCH=arm make build
build:
@echo "Building ${GOOS}-${GOARCH}"
GOOS=${GOOS} GOARCH=${GOARCH} go build \
-trimpath -ldflags "-s -w -X ${PROJECT}/internal/diagnostics.Version=${RELEASE} \
-X ${PROJECT}/internal/diagnostics.Commit=${COMMIT} \
-X ${PROJECT}/internal/diagnostics.BuildDate=${BUILD_DATE}" \
-o bin/sysctl-${GOOS}-${GOARCH} ${PROJECT}/cmd/sysctl
cp ./bin/sysctl-${GOOS}-${GOARCH} ./bin/sysctl
clean:
rm -rf ${BUILD_DIR}
go clean

View File

@ -7,16 +7,24 @@ import (
"os/signal"
"time"
//"syscall"
"github.com/edgebox-iot/sysctl/internal/diagnostics"
"fmt"
)
func main() {
// load command line arguments
version := flag.Bool("version", false, "Get the version info")
name := flag.String("name", "edgebox", "name for the service")
flag.Parse()
if *version {
printVersion()
os.Exit(0)
}
log.Printf("Starting Sysctl service for %s", *name)
// setup signal catching
@ -32,7 +40,7 @@ func main() {
go func() {
s := <-sigs
log.Printf("RECEIVED SIGNAL: %s", s)
AppCleanup()
appCleanup()
os.Exit(1)
}()
@ -50,6 +58,13 @@ func main() {
}
// AppCleanup : cleanup app state before exit
func AppCleanup() {
func appCleanup() {
log.Println("Cleaning up app status before exit")
}
func printVersion() {
fmt.Printf(
"version: %s\ncommit: %s\nbuild time: %s",
diagnostics.Version, diagnostics.Commit, diagnostics.BuildDate,
)
}

View File

@ -0,0 +1,7 @@
package diagnostics
var Version string
var Commit string
var BuildDate string