Browse Source

Refactoring

Alexey Kim 10 months ago
parent
commit
606ddb8a3c
5 changed files with 47 additions and 17 deletions
  1. 7 1
      Makefile
  2. 0 4
      app/daemon/action.go
  3. 0 5
      app/daemon/config.go
  4. 0 7
      app/daemon/flags.go
  5. 40 0
      build.sh

+ 7 - 1
Makefile

@@ -9,7 +9,7 @@ PROJECT := $(shell cat go.mod | grep '^module\s' | cut -b 8-)
 export VERSION ?= $(shell date -u '+%F')-snapshot
 BUILD_TIME := $(shell date -u '+%F_%T')
 COMMIT_HASH := $(shell git rev-parse --short HEAD)
-GOLDFLAGS := '-linkmode external -w -s -extldflags "-static" -X $(PROJECT)/internal/version.BuildVersion=$(VERSION) -X $(PROJECT)/internal/version.BuildCommitId=$(COMMIT_HASH) -X ${PROJECT}/internal/version.BuildTime=$(BUILD_TIME)'
+GOLDFLAGS := '-linkmode external -w -s -X $(PROJECT)/version.BuildVersion=$(VERSION) -X $(PROJECT)/version.BuildCommitId=$(COMMIT_HASH) -X ${PROJECT}/version.BuildTime=$(BUILD_TIME)'
 
 .PHONY: all
 all: gen deps fmt test
@@ -45,3 +45,9 @@ test:
 	-@echo "-> $@"
 	CGO_ENABLED=1 go test -tags musl $(shell go list ./...)
 	-go vet $(shell go list ./...)
+
+.PHONY: build
+build:
+	-@echo "-> $@"
+	-$(if $(filter $(VERSION),0.0.0), $(error "Please, provide version name"), @echo "== Starting to build version: $(VERSION)")
+	@bash ./build.sh $(PROJECT) $(VERSION) $(GOLDFLAGS)

+ 0 - 4
app/daemon/action.go

@@ -34,10 +34,6 @@ var action = func(ctx *cli.Context) error {
 
 		close(chMessage)
 		close(ctrlSignal)
-
-		if chStream != nil {
-			close(chStream)
-		}
 	}()
 
 	if cfg == nil {

+ 0 - 5
app/daemon/config.go

@@ -4,8 +4,6 @@ import (
 	"errors"
 	"git.beejay.kim/WatchDog/ward/platform"
 	"git.beejay.kim/tool/service/config"
-	"git.beejay.kim/tool/service/consumer"
-	"git.beejay.kim/tool/service/producer"
 	"reflect"
 	"strings"
 )
@@ -13,9 +11,6 @@ import (
 type Configuration struct {
 	config.Configuration `yaml:",inline"`
 
-	Consumer consumer.Config `yaml:"consumer"`
-	Producer producer.Config `yaml:"producer"`
-
 	Platform _platform `yaml:"platform"`
 }
 

+ 0 - 7
app/daemon/flags.go

@@ -14,13 +14,6 @@ var flags = []cli.Flag{
 		TakesFile: false,
 		Action:    config.Load[Configuration],
 	},
-	&cli.StringFlag{
-		Name:        "topic",
-		Usage:       "kafka producer topic name",
-		Required:    true,
-		Destination: &topic,
-		Aliases:     []string{"T"},
-	},
 	&cli.StringFlag{
 		Name:        "pid",
 		Usage:       "platform ID",

+ 40 - 0
build.sh

@@ -0,0 +1,40 @@
+#!/bin/bash
+
+PROJECT="$1"
+if [[ -z "$PROJECT" ]]; then
+  echo "usage: $0 <package-name>"
+  exit 1
+fi
+
+VERSION="$2"
+if [[ -z "$VERSION" ]]; then
+  echo "usage: $0 <version-name>"
+  exit 1
+fi
+
+GOLDFLAGS="$3"
+if [[ -z "$GOLDFLAGS" ]]; then
+  GOLDFLAGS='-w -s -extldflags "-static"'
+fi
+
+PLATFORMS=("darwin/amd64")
+for platform in "${PLATFORMS[@]}"
+do
+  platform_split=(${platform//\// })
+
+  GOOS=${platform_split[0]}
+  GOARCH=${platform_split[1]}
+
+  output_name='cli-'$VERSION'-'$GOOS'-'$GOARCH
+  echo "== Building $output_name"
+  echo "== FLAGS: $GOLDFLAGS"
+
+  CGO_ENABLED=1 GOOS=$GOOS GOARCH=$GOARCH go build -a -ldflags="$GOLDFLAGS" -gcflags=all="-l -B" -installsuffix cgo -o bin/$output_name $PROJECT/app
+
+  if [ $? -ne 0 ]; then
+      echo 'An error has occurred! Aborting the script execution...'
+      exit 1
+  fi
+done
+
+echo "== DONE"