diff --git a/.circleci/config.yml b/.circleci/config.yml index 3cfce53..676a85d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ jobs: - run: name: build - command: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -v -o release/ipvsctl ipvsctl.go + command: GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -v -o release/ipvsctl ipvsctl.go - save_cache: key: go-mod-v4-{{ checksum "go.sum" }} diff --git a/.gitignore b/.gitignore index a2e333d..ce1657d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,6 @@ *.code-workspace *.sh +dist/ release/ .vscode/ \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..33dbf49 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,22 @@ +before: + hooks: + - go mod download +builds: + - goos: + - linux +archives: + - replacements: + linux: Linux + 386: i386 + amd64: x86_64 +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - '^tests:' diff --git a/Makefile b/Makefile index 2fd1017..a360cfc 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ -VERSION := `cat VERSION` SOURCES ?= $(shell find . -name "*.go" -type f) BINARY_NAME = ipvsctl @@ -6,7 +5,7 @@ all: clean lint build .PHONY: build build: - GOOS=linux GOARCH=amd64 go build -o release/${BINARY_NAME} -ldflags="-X main.version=${VERSION}" ipvsctl.go + GOOS=linux GOARCH=amd64 go build -o dist/${BINARY_NAME} ipvsctl.go lint: @for file in ${SOURCES} ; do \ @@ -24,6 +23,9 @@ cover: .PHONY: clean clean: - @rm -rf release/* + @rm -rf dist/* @rm -f cover.out +.PHONY: release +release: + goreleaser --snapshot --rm-dist diff --git a/README.md b/README.md index b3c374c..d46ae64 100644 --- a/README.md +++ b/README.md @@ -73,13 +73,27 @@ INFO Updated weight to 100 for service tcp://10.1.2.3:80/10.50.0.1:8080 * Linux * ipvs kernel modules installed and loaded +## Install + +You can build this as describe below or install one of the versions under the `releases` tab. +`ipvsctl` makes modifications to the ipvs tables, so it either needs to be run as root or equipped +with the appropriate capabilities, e.g.: + +```bash +$ chmod +x ipvsctl +$ sudo cp ipvsctl /usr/local/bin +$ sudo setcap 'cap_net_admin+eip' /usr/local/bin/ipvsctl +``` + +Caution as this allows any user to modify ipvs tables! Please evaluate whether `sudo` or `setcap` is the right approach for you. + ## Build This project builds correctly for Linux only. ```bash $ make -$ release/ipvsctl --version +$ dist/ipvsctl --version 0.2.1 ``` diff --git a/VERSION b/VERSION deleted file mode 100644 index 0c62199..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.2.1 diff --git a/ipvsctl.go b/ipvsctl.go index 5e84c95..469f004 100644 --- a/ipvsctl.go +++ b/ipvsctl.go @@ -11,7 +11,9 @@ import ( ) var ( - version string + version = "dev" + commit = "none" + date = "unknown" ) func main() { @@ -27,9 +29,9 @@ func main() { verbose := app.BoolOpt("v verbose", c.Verbose, "Show information. Default: false. False equals to being quiet") paramsHostNetwork := app.BoolOpt("params-network", c.ParamsHostNetwork, "Dynamic parameters. Add every network interface name as resolvable ip address, e.g. net.eth0") paramsHostEnv := app.BoolOpt("params-env", c.ParamsHostNetwork, "Dynamic parameters. Add every environment entry, e.g. env.port=") - paramsFiles := make([]string,10) + paramsFiles := make([]string, 10) app.StringsOptPtr(¶msFiles, "params-file", []string{c.ParamsFilesFromEnv}, "Dynamic parameters. Add parameters from yaml or json file.") - paramsURLs := make([]string,10) + paramsURLs := make([]string, 10) app.StringsOptPtr(¶msURLs, "params-url", []string{c.ParamsURLsFromEnv}, "Dynamic parameters. Add parameters from yaml or json resource given by URL.") app.Command("get", "retrieve ipvs configuration and returns as yaml", cmd.Get)