From b30453cc09a05b37a37b65ba375d8f1839226596 Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Thu, 11 Feb 2021 21:21:22 +0100 Subject: [PATCH 1/9] Add basic Makefile --- .gitignore | 4 ++++ Makefile | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 525ab5b..ba2597d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,7 @@ main # Dependency directories (remove the comment below to include it) # vendor/ + +# Build + +/bin diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3c02029 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +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 + +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} + +clean: + rm -rf ${BUILD_DIR} ${DIST_DIR} + go clean From d9b0e71157d5127e8d1de94442d8e5b9774d6eb7 Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Thu, 11 Feb 2021 21:31:32 +0100 Subject: [PATCH 2/9] Structure --- internal/diagnostics/diagnostics.go | 7 +++++++ main.go | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 internal/diagnostics/diagnostics.go diff --git a/internal/diagnostics/diagnostics.go b/internal/diagnostics/diagnostics.go new file mode 100644 index 0000000..bd66329 --- /dev/null +++ b/internal/diagnostics/diagnostics.go @@ -0,0 +1,7 @@ +package diagnostics + +var Version string + +var Commit string + +var BuildDate string diff --git a/main.go b/main.go index 7d1d515..c9a736a 100644 --- a/main.go +++ b/main.go @@ -7,16 +7,24 @@ import ( "os/signal" "time" //"syscall" + "github.com/edgebox-iot/sysctl/internal/diagnostics" + ) 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() { + log.Printf( + "version: %s\ncommit: %s\nbuild time: %s", + diagnostics.Version, diagnostics.Commit, diagnostics.BuildDate, + ) +} From 9ec7cfd80da21ee874ac7aeb8ab91c9a5c072421 Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Thu, 11 Feb 2021 21:33:05 +0100 Subject: [PATCH 3/9] Move main.go --- Makefile | 2 +- main.go => cmd/sysctl/main.go | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename main.go => cmd/sysctl/main.go (100%) diff --git a/Makefile b/Makefile index 3c02029..4f81dc4 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ 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} + -o bin/sysctl-${GOOS}-${GOARCH} ${PROJECT}/cmd/sysctl clean: rm -rf ${BUILD_DIR} ${DIST_DIR} diff --git a/main.go b/cmd/sysctl/main.go similarity index 100% rename from main.go rename to cmd/sysctl/main.go From ef9ab09640eb323efcd38a190cad37366f6373f6 Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Thu, 11 Feb 2021 21:38:43 +0100 Subject: [PATCH 4/9] Use fmt --- cmd/sysctl/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/sysctl/main.go b/cmd/sysctl/main.go index c9a736a..9614ef7 100644 --- a/cmd/sysctl/main.go +++ b/cmd/sysctl/main.go @@ -63,7 +63,7 @@ func appCleanup() { } func printVersion() { - log.Printf( + fmt.Printf( "version: %s\ncommit: %s\nbuild time: %s", diagnostics.Version, diagnostics.Commit, diagnostics.BuildDate, ) From 81052a37c461a4b5f6edd20b63bb50a963b517df Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Thu, 11 Feb 2021 21:45:08 +0100 Subject: [PATCH 5/9] Remove dist --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4f81dc4..08fb020 100644 --- a/Makefile +++ b/Makefile @@ -17,5 +17,5 @@ build: -o bin/sysctl-${GOOS}-${GOARCH} ${PROJECT}/cmd/sysctl clean: - rm -rf ${BUILD_DIR} ${DIST_DIR} + rm -rf ${BUILD_DIR} go clean From 972a77173ac0a50ebb24d34d3d36cebe35cb87ca Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Thu, 11 Feb 2021 21:48:41 +0100 Subject: [PATCH 6/9] Fix --- .github/workflows/go.yml | 4 ++-- cmd/sysctl/main.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ebafbb6..8e7f5a0 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 ./... diff --git a/cmd/sysctl/main.go b/cmd/sysctl/main.go index 9614ef7..6bad8c6 100644 --- a/cmd/sysctl/main.go +++ b/cmd/sysctl/main.go @@ -8,7 +8,7 @@ import ( "time" //"syscall" "github.com/edgebox-iot/sysctl/internal/diagnostics" - + "fmt" ) func main() { From 2e8a73d0eae6b5859badc3a0032c58a97bcc3abd Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Fri, 12 Feb 2021 01:06:32 +0100 Subject: [PATCH 7/9] Fixed Dockerfile CompileDeamon to point to makefile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d617d40..5eb99ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,4 @@ RUN go mod download RUN go get github.com/githubnemo/CompileDaemon -ENTRYPOINT CompileDaemon --build="go build main.go" --command=./main \ No newline at end of file +ENTRYPOINT CompileDaemon --build="make build" --command=./main \ No newline at end of file From b689115105596be5a898b111e21a3c98b61ab875 Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Fri, 12 Feb 2021 01:23:16 +0100 Subject: [PATCH 8/9] Using Makefile in Dockerfile --- Dockerfile | 2 +- Makefile | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5eb99ba..3d21ce5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,4 @@ RUN go mod download RUN go get github.com/githubnemo/CompileDaemon -ENTRYPOINT CompileDaemon --build="make build" --command=./main \ No newline at end of file +ENTRYPOINT CompileDaemon --build="make build" --command=./bin/sysctl \ No newline at end of file diff --git a/Makefile b/Makefile index 08fb020..bc1b8a5 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ build: -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} From ba1fe45c1bb34ae7790e9f33d5ede984fea0c659 Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Fri, 12 Feb 2021 17:22:03 +0000 Subject: [PATCH 9/9] Added arm build to build-all Makefile command --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 08fb020..355b47c 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ BUILD_DIR = bin build-all: GOOS=linux GOARCH=amd64 make build + GOOS=linux GOARCH=arm make build build: @echo "Building ${GOOS}-${GOARCH}"