Skip to content

Commit

Permalink
Merge pull request #11 from waldirborbajr/parameters
Browse files Browse the repository at this point in the history
Parameters
  • Loading branch information
waldirborbajr authored Oct 7, 2024
2 parents c573cc0 + 3ddd437 commit a427317
Show file tree
Hide file tree
Showing 13 changed files with 549 additions and 239 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Go
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.21
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
71 changes: 49 additions & 22 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,53 @@
# run:
# timeout: 5m
# tests: false
# issues:
# include:
# - EXC0001
# - EXC0005
# - EXC0011
# - EXC0012
# - EXC0013
# max-issues-per-linter: 0
# max-same-issues: 0
# linters:
# enable:
# - bodyclose
# - goimports
# - gosec
# - nilerr
# - predeclared
# - revive
# - rowserrcheck
# - sqlclosecheck
# - tparallel
# - unconvert
# - unparam
# - whitespace

run:
timeout: 5m
tests: false
issues:
include:
- EXC0001
- EXC0005
- EXC0011
- EXC0012
- EXC0013
max-issues-per-linter: 0
max-same-issues: 0
skip-dirs:
- .tmp
- vendor
linters:
disable-all: true
enable:
- bodyclose
# - errcheck
- gocritic
- goconst
- goimports
- gosec
- nilerr
- predeclared
- revive
- rowserrcheck
- sqlclosecheck
- tparallel
- unconvert
- unparam
- whitespace
- gosimple
- govet
- ineffassign
- staticcheck
- stylecheck
- typecheck
- unused
linters-settings:
govet:
# report about shadowed variables
check-shadowing: true
issues:
exclude-rules:
- linters: [stylecheck]
text: "ST1005:"
28 changes: 28 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
project_name: tmux-monitor
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
ldflags:
- "-X=main.version={{.Env.VERSION}}"
goos:
- linux
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- test
- README
51 changes: 45 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# VERSION := $(shell cat VERSION | sed 's/^VERSION=//')
# VERSION := $(shell git describe --tags --abbrev=0 | sed 's/^VERSION=//')

# Get the version from git tags, or use a default if not available
VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0-dev")

# Remove any "v" prefix and "VERSION=" text if present
VERSION := $(shell echo $(VERSION) | sed -e 's/^v//' -e 's/^VERSION=//')

# If VERSION is empty, set a default development version
ifeq ($(strip $(VERSION)),)
VERSION := 0.0.0-dev
endif

# Makefile for Tmux Docker Monitor
# Go parameters
GOCMD=go
Expand All @@ -21,7 +35,7 @@ MAIN_PACKAGE_PATH=./cmd/main.go
INSTALL_DIR=$(HOME)/.tmux/plugins/tmux-monitor

# Build flags
LDFLAGS=-ldflags "-s -w -X main.version=$(shell git describe --tags --always --dirty)"
LDFLAGS=-ldflags "-s -w -X=main.version=$(VERSION)"
GCFLAGS=-gcflags="all=-trimpath=$(pwd);-N -l"
ASMFLAGS=-asmflags="all=-trimpath=$(pwd)"

Expand All @@ -35,6 +49,9 @@ RELEASE_FLAGS=$(LDFLAGS) $(GCFLAGS) $(ASMFLAGS) $(OPTIMIZATION_FLAGS) -trimpath

all: deps build

version:
@echo $(VERSION)

deps:
$(TIDY)

Expand All @@ -53,14 +70,36 @@ test: deps

install: build
mkdir -p $(INSTALL_DIR)
cp $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_DIR)/
cp tmux-monitor.tmux $(INSTALL_DIR)/
chmod u+x $(INSTALL_DIR)/tmux-monitor.tmux
install -D -m 755 $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_DIR)/tmux-monitor
install -D -m 755 tmux-monitor.tmux $(INSTALL_DIR)/tmux-monitor.tmux
# cp $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_DIR)/
# chmod u+x $(INSTALL_DIR)/tmux-monitor.tmux
@echo "Plugin installed to $(INSTALL_DIR)"

release: deps
CGO_ENABLED=0 $(GOBUILD) $(RELEASE_FLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PACKAGE_PATH)
@echo "Release version built with optimizations for speed, size, and security"
# Linux AMD64
env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(RELEASE_FLAGS) -o $(BUILD_DIR)/linux/$(BINARY_NAME) $(MAIN_PACKAGE_PATH)
@echo ""
@echo "Release version built for Linux AMD64 with optimizations for speed, size, and security"
@echo ""
# Mac Intel
env GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(RELEASE_FLAGS) -o $(BUILD_DIR)/macos/$(BINARY_NAME) $(MAIN_PACKAGE_PATH)
@echo ""
@echo "Release version built for MacOS Intel (AMD64) with optimizations for speed, size, and security"
@echo ""
# Mac M1~2
env GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(RELEASE_FLAGS) -o $(BUILD_DIR)/macosarm/$(BINARY_NAME) $(MAIN_PACKAGE_PATH)
@echo ""
@echo "Release version built for MacOS M1~2 (ARM64) with optimizations for speed, size, and security"
@echo ""
install -D -m 755 $(BUILD_DIR)/linux/$(BINARY_NAME) $(INSTALL_DIR)/tmux-monitor
install -D -m 755 tmux-monitor.tmux $(INSTALL_DIR)/tmux-monitor.tmux
# cp $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_DIR)/
# cp tmux-monitor.tmux $(INSTALL_DIR)/
# chmod u+x $(INSTALL_DIR)/tmux-monitor.tmux
@echo ""
@echo "Installation for Linux AMD64 finished."
@echo ""

# Help target
help:
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION=0.1.0
45 changes: 43 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"
"strings"

"github.com/urfave/cli"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/knownhosts"

Expand All @@ -19,9 +20,10 @@ const (
resetColor = "\x1b[0m"
configFile = "$HOME/.tmux-monitor"
knownHostsFile = "$HOME/.ssh/known_hosts"
version = "v0.1.0"
)

var version = "[dev build]"

type ServerConfig struct {
Address string
User string
Expand All @@ -30,6 +32,45 @@ type ServerConfig struct {
}

func main() {
app := cli.NewApp()

app.Version = version
app.Name = "tmux-monitor"
app.HelpName = "tmux-monitor"
app.Usage = "monitor Docker containers running on a remote server"
app.Description = strings.Join([]string{
"tmux-monitor connects to remote server and get containers status.",
"This allows to monitor healthcheck of docker containers.",
}, " ")
app.Author = "Waldir \"Borba\" Junior"
app.Email = "wborbajr@gmail.com"

app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, d",
Usage: "enable debug logging",
},
}

app.Commands = []cli.Command{
{
Name: "short",
ShortName: "s",
Usage: "show short stats version",
Action: print_short,
},
{
Name: "full",
ShortName: "f",
Usage: "show full stats version",
Action: print_short,
},
}

app.Run(os.Args)
}

func print_short(*cli.Context) {
config, err := readConfig(configFile)
if err != nil {
fmt.Printf("%sError reading config: %v%s\n", redBold, err, resetColor)
Expand All @@ -42,7 +83,7 @@ func main() {
}

func refreshTmux() {
_ = tmux.RefreshClient("-S")
_, _ = tmux.RefreshClient("-S")
}

func readConfig(filename string) (ServerConfig, error) {
Expand Down
Loading

0 comments on commit a427317

Please sign in to comment.