Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3899529

Browse files
committedJan 27, 2024
Adapted for go mod and vendored some libs:
- added Makefile for easy build - added future build build bin in container - added future bulld packages in container - adapted for go mod - vendored some library
1 parent 7cb9005 commit 3899529

32 files changed

+520
-2776
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
pkg
2+
pkgs_out
3+
bin
4+
.prepared_cmd

‎Dockerfile

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
FROM gliderlabs/alpine:3.2
2-
3-
MAINTAINER Ryan Eschinger <ryanesc@gmail.com>
4-
5-
COPY . /go/src/github.com/outbrain/zookeepercli/
6-
7-
RUN apk add --update go git \
8-
&& cd /go/src/github.com/outbrain/zookeepercli/ \
9-
&& export GOPATH=/go \
10-
&& go get \
11-
&& go build -o /bin/zookeepercli \
12-
&& rm -rf /go \
13-
&& apk del --purge go git
1+
# syntax=docker/dockerfile:experimental
142

3+
FROM scratch
4+
COPY bin/zookeepercli /bin/zookeepercli
155
ENTRYPOINT ["/bin/zookeepercli"]

‎Makefile

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
.PHONY: clean
2+
3+
BINARY_NAME ?= zookeepercli
4+
VERSION ?= $(shell git describe --long --tags --always --dirty --abbrev=10)
5+
GOLANG_VERSION ?= 1.21-alpine
6+
7+
CURRENT_DIR := $(shell pwd)
8+
9+
DOCKER ?= docker
10+
11+
.prepare_cmd:
12+
printf "go build -o ./bin/%s -ldflags \"-X 'main.Version=%s'\"\n" "$(BINARY_NAME)" "$(VERSION)" > .prepared_cmd
13+
14+
# build bin in docker, package in docker and build the docker image
15+
all_in_docker: package_in_docker build_docker_image
16+
@echo "All done"
17+
18+
# build bin and package locally
19+
all: package
20+
@echo "All done"
21+
22+
build: .prepare_cmd
23+
sh .prepared_cmd
24+
25+
package: build
26+
@ /bin/sh ./scripts/build_package.sh
27+
@ echo "=== Packaged files: ==="
28+
@ echo "==== in ./pkgs_out ===="
29+
@ ls -1 ./pkgs_out
30+
@ echo "======================="
31+
32+
build_in_docker: .prepare_cmd
33+
${DOCKER} run --rm -t -v "$(CURRENT_DIR):/app" -w /app \
34+
-e CGO_ENABLED=0 \
35+
golang:$(GOLANG_VERSION) /bin/sh .prepared_cmd
36+
37+
package_in_docker: build_in_docker
38+
${DOCKER} run --rm -t -v "$(CURRENT_DIR):/app" -w /app \
39+
-e CGO_ENABLED=0 \
40+
golang:$(GOLANG_VERSION) \
41+
/bin/sh -c \
42+
"/bin/sh ./scripts/prepare_container.sh && /bin/sh ./scripts/build_package.sh"
43+
@ echo "=== Packaged files: ==="
44+
@ echo "==== in ./pkgs_out ===="
45+
@ ls -1 ./pkgs_out
46+
@ echo "======================="
47+
48+
build_docker_image: build_in_docker
49+
${DOCKER} build -t zookeepercli:$(VERSION) -t zookeepercli:latest .
50+
51+
clean:
52+
rm -rf ./bin
53+
rm -rf ./pkgs_out
54+
rm -rf .prepared_cmd

‎README.md

+63-51
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# zookeepercli
22

3-
[![downloads](https://img.shields.io/github/downloads/outbrain/zookeepercli/total.svg)](https://github.com/outbrain/zookeepercli/releases)
3+
[![downloads](https://img.shields.io/github/downloads/outbrain/zookeepercli/total.svg)](https://github.com/outbrain/zookeepercli/releases)
44

55
Simple, lightweight, dependable CLI for ZooKeeper
66

@@ -9,109 +9,126 @@ Simple, lightweight, dependable CLI for ZooKeeper
99
* Basic CRUD-like operations: `create`, `set`, `delete` (aka `rm`), `exists`, `get`, `ls` (aka `children`).
1010
* Extended operations: `lsr` (ls recursive), `creater` (create recursively), `deleter` (aka `rmr`, delete recursively)
1111
* Well formatted and controlled output: supporting either `txt` or `json` format
12-
* Single, no-dependencies binary file, based on a native Go ZooKeeper library
12+
* Single, no-dependencies binary file, based on a native Go ZooKeeper library
1313
by [github.com/samuel/go-zookeeper](http://github.com/samuel/go-zookeeper) ([LICENSE](https://github.com/outbrain/zookeepercli/blob/master/go-zookeeper-LICENSE))
1414

15-
### Download & Install
15+
### Build:
16+
Clone the repository:
17+
```
18+
git clone --depth 1 https://github.com/openark/zookeepercli.git && zookeepercli
19+
```
1620

17-
There are [pre built binaries](https://github.com/outbrain/zookeepercli/releases) for download.
18-
You can find `RPM` and `deb` packages, as well as pre-compiled, dependency free `zookeepercli` executable binary.
19-
In fact, the only file installed by the pre-built `RPM` and `deb` packages is said executable binary file.
21+
Build :
22+
```
23+
make build # build binary with local goland
24+
make package # previous + build deb, rpm, apk, tar, zip packages
25+
make all # all previous steps
2026
21-
Otherwise the source code is freely available; you will need `git` installed as well as `go`, and you're on your own.
27+
make build_in_docker # build binary with using docker container (golang-alpine)
28+
make package_in_docker # previous + build deb, rpm, apk, tar, zip packages with using docker container
29+
make build_docker_image # build docker image with zookeepercli
30+
make all_in_docker # all previous steps
2231
23-
24-
### Usage:
32+
make clean # clean all build artifacts
33+
```
34+
35+
For build packages locally you need requires fpm: https://github.com/jordansissel/fpm.
36+
37+
You can find the binary in the `bin` directory. \
38+
Also you can find `deb`, `rpm`, `apk`, `tar` and `zip` packages in pkgs_out.
2539

40+
### Usage:
41+
```
2642
$ zookeepercli --help
2743
Usage of zookeepercli:
28-
-acls="31": optional, csv list [1|,2|,4|,8|,16|,31]
29-
-auth_pwd="": optional, digest scheme, pwd
30-
-auth_usr="": optional, digest scheme, user
31-
-c="": command (exists|get|ls|lsr|create|creater|set|delete|rm|deleter|rmr|getacl|setacl)
32-
-debug=false: debug mode (very verbose)
33-
-force=false: force operation
34-
-format="txt": output format (txt|json)
35-
-servers="": srv1[:port1][,srv2[:port2]...]
36-
-stack=false: add stack trace upon error
44+
-acls="31": optional, csv list [1|,2|,4|,8|,16|,31]
45+
-auth_pwd="": optional, digest scheme, pwd
46+
-auth_usr="": optional, digest scheme, user
47+
-c="": command (exists|get|ls|lsr|create|creater|set|delete|rm|deleter|rmr|getacl|setacl)
48+
-debug=false: debug mode (very verbose)
49+
-force=false: force operation
50+
-format="txt": output format (txt|json)
51+
-servers="": srv1[:port1][,srv2[:port2]...]
52+
-stack=false: add stack trace upon error
3753
-verbose=false: verbose
38-
54+
-version: print version and exit
55+
```
3956

4057
### Examples:
41-
42-
58+
59+
4360
$ zookeepercli --servers srv-1,srv-2,srv-3 -c create /demo_only some_value
44-
61+
4562
# Default port is 2181. The above is equivalent to:
4663
$ zookeepercli --servers srv-1:2181,srv-2:2181,srv-3:2181 -c create /demo_only some_value
47-
64+
4865
$ zookeepercli --servers srv-1,srv-2,srv-3 --format=txt -c get /demo_only
4966
some_value
50-
67+
5168
# Same as above, JSON format output:
5269
$ zookeepercli --servers srv-1,srv-2,srv-3 --format=json -c get /demo_only
5370
"some_value"
54-
55-
# exists exits with exit code 0 when path exists, 1 when path does not exist
71+
72+
# exists exits with exit code 0 when path exists, 1 when path does not exist
5673
$ zookeepercli --servers srv-1,srv-2,srv-3 -c exists /demo_only
5774
true
58-
75+
5976
$ zookeepercli --servers srv-1,srv-2,srv-3 -c set /demo_only another_value
60-
77+
6178
$ zookeepercli --servers srv-1,srv-2,srv-3 --format=json -c get /demo_only
6279
"another_value"
63-
80+
6481
$ zookeepercli --servers srv-1,srv-2,srv-3 -c delete /demo_only
65-
82+
6683
$ zookeepercli --servers srv-1,srv-2,srv-3 -c get /demo_only
6784
2014-09-15 04:07:16 FATAL zk: node does not exist
68-
85+
6986
$ zookeepercli --servers srv-1,srv-2,srv-3 -c create /demo_only "path placeholder"
7087
$ zookeepercli --servers srv-1,srv-2,srv-3 -c create /demo_only/key1 "value1"
7188
$ zookeepercli --servers srv-1,srv-2,srv-3 -c create /demo_only/key2 "value2"
7289
$ zookeepercli --servers srv-1,srv-2,srv-3 -c create /demo_only/key3 "value3"
73-
90+
7491
$ zookeepercli --servers srv-1,srv-2,srv-3 -c ls /demo_only
7592
key3
7693
key2
7794
key1
78-
95+
7996
# Same as above, JSON format output:
8097
$ zookeepercli --servers srv-1,srv-2,srv-3 --format=json -c ls /demo_only
8198
["key3","key2","key1"]
82-
99+
83100
$ zookeepercli --servers srv-1,srv-2,srv-3 -c delete /demo_only
84101
2014-09-15 08:26:31 FATAL zk: node has children
85-
102+
86103
$ zookeepercli --servers srv-1,srv-2,srv-3 -c delete /demo_only/key1
87104
$ zookeepercli --servers srv-1,srv-2,srv-3 -c delete /demo_only/key2
88105
$ zookeepercli --servers srv-1,srv-2,srv-3 -c delete /demo_only/key3
89106
$ zookeepercli --servers srv-1,srv-2,srv-3 -c delete /demo_only
90107

91108
# /demo_only path now does not exist.
92-
109+
93110
# Create recursively a path:
94111
$ zookeepercli --servers=srv-1,srv-2,srv-3 -c creater "/demo_only/child/key1" "val1"
95112
$ zookeepercli --servers=srv-1,srv-2,srv-3 -c creater "/demo_only/child/key2" "val2"
96-
113+
97114
# "-c creater" is same as "-c create --force"
98115

99116
$ zookeepercli --servers=srv-1,srv-2,srv-3 -c get "/demo_only/child/key1"
100117
val1
101118

102119
# This path was auto generated due to recursive create:
103-
$ zookeepercli --servers=srv-1,srv-2,srv-3 -c get "/demo_only"
120+
$ zookeepercli --servers=srv-1,srv-2,srv-3 -c get "/demo_only"
104121
zookeepercli auto-generated
105-
122+
106123
# ls recursively a path and all sub children:
107-
$ zookeepercli --servers=srv-1,srv-2,srv-3 -c lsr "/demo_only"
124+
$ zookeepercli --servers=srv-1,srv-2,srv-3 -c lsr "/demo_only"
108125
child
109126
child/key1
110127
child/key2
111128

112129
# set value with read and write acl using digest authentication
113130
$ zookeepercli --servers 192.168.59.103 --auth_usr "someuser" --auth_pwd "pass" --acls 1,2 -c create /secret4 value4
114-
131+
115132
# get value using digest authentication
116133
$ zookeepercli --servers 192.168.59.103 --auth_usr "someuser" --auth_pwd "pass" -c get /secret4
117134

@@ -132,17 +149,17 @@ Otherwise the source code is freely available; you will need `git` installed as
132149
# set an acl with world and digest authentication creating the node if it doesn't exist
133150
$ zookeepercli --servers srv-1,srv-2,srv-3 -force -c setacl /demo_acl_create "world:anyone:rw,digest:someuser:hashedpw:crdwa"
134151

135-
The tool was built in order to allow with shell scripting seamless integration with ZooKeeper.
136-
There is another, official command line tool for ZooKeeper that the author found inadequate
137-
in terms of output format and output control, as well as large footprint.
152+
The tool was built in order to allow with shell scripting seamless integration with ZooKeeper.
153+
There is another, official command line tool for ZooKeeper that the author found inadequate
154+
in terms of output format and output control, as well as large footprint.
138155
**zookeepercli** overcomes those limitations and provides with quick, well formatted output as well as
139-
enhanced functionality.
156+
enhanced functionality.
140157

141158
### Docker
142159

143160
You can also build and run **zookeepercli** in a Docker container. To build the image:
144161

145-
$ docker build -t zookeepercli .
162+
$ make build_docker_image
146163

147164
Now, you can run **zookeepercli** from a container. Examples:
148165

@@ -158,9 +175,4 @@ Now, you can run **zookeepercli** from a container. Examples:
158175
Release under the [Apache 2.0 license](https://github.com/outbrain/zookeepercli/blob/master/LICENSE)
159176

160177
Authored by [Shlomi Noach](https://github.com/shlomi-noach) at [Outbrain](https://github.com/outbrain)
161-
162-
163-
164-
165178

166-

‎go.mod

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/openark/zookeepercli
2+
3+
go 1.21.5
4+
5+
require (
6+
github.com/outbrain/golib v0.0.0-20200503083229-2531e5dbcc71
7+
github.com/samuel/go-zookeeper v0.0.0-20201211165307-7117e9ea2414
8+
)

‎go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/outbrain/golib v0.0.0-20200503083229-2531e5dbcc71 h1:5FSwz/q8DhpkUsq8cqRN7gRVWWnfXfjeOeB8Bhj5ARc=
2+
github.com/outbrain/golib v0.0.0-20200503083229-2531e5dbcc71/go.mod h1:JDhu//MMvcPVPH889Xr7DyamEbTLumgDBALGUyXrz1g=
3+
github.com/samuel/go-zookeeper v0.0.0-20201211165307-7117e9ea2414 h1:AJNDS0kP60X8wwWFvbLPwDuojxubj9pbfK7pjHw0vKg=
4+
github.com/samuel/go-zookeeper v0.0.0-20201211165307-7117e9ea2414/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=

‎main.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ package main
1919
import (
2020
"flag"
2121
"fmt"
22-
"github.com/outbrain/golib/log"
23-
"github.com/outbrain/zookeepercli/output"
24-
"github.com/outbrain/zookeepercli/zk"
2522
"io/ioutil"
2623
"math/rand"
2724
"os"
2825
"sort"
2926
"strings"
3027
"time"
28+
29+
"github.com/openark/zookeepercli/output"
30+
"github.com/openark/zookeepercli/zk"
31+
"github.com/outbrain/golib/log"
3132
)
3233

34+
var Version = "undefined-dev-version"
35+
3336
// main is the application's entry point.
3437
func main() {
3538
servers := flag.String("servers", "", "srv1[:port1][,srv2[:port2]...]")
@@ -43,8 +46,14 @@ func main() {
4346
authUser := flag.String("auth_usr", "", "optional, digest scheme, user")
4447
authPwd := flag.String("auth_pwd", "", "optional, digest scheme, pwd")
4548
acls := flag.String("acls", "31", "optional, csv list [1|,2|,4|,8|,16|,31]")
49+
version := flag.Bool("version", false, "print version and exit")
4650
flag.Parse()
4751

52+
if *version {
53+
fmt.Println("zookeepercli version:", Version)
54+
os.Exit(0)
55+
}
56+
4857
log.SetLevel(log.ERROR)
4958
if *verbose {
5059
log.SetLevel(log.INFO)
File renamed without changes.

‎scripts/build_package.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh -e
2+
# Build deb package for zookeepercli
3+
# Sergei Kraev <skraev@tradingview.com>
4+
#
5+
6+
echo "========= Preparing packing start =========";
7+
PKGNAME="zookeepercli"
8+
VER=$(git describe --long --tags --always --abbrev=10 | sed 's/^[^0-9]//ig')
9+
ARCH=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/)
10+
RDIR="$(pwd)/pkgs_out/"
11+
12+
rm -rf "${RDIR}"
13+
mkdir -p "$RDIR"
14+
15+
OUTTYPES="rpm deb apk tar zip"
16+
17+
for OUTTYPE in $OUTTYPES; do
18+
echo "========= Packing ${OUTTYPE} start =========";
19+
fpm \
20+
--output-type "${OUTTYPE}" \
21+
--input-type dir \
22+
--force \
23+
\
24+
--name "${PKGNAME}" \
25+
--package "${RDIR}" \
26+
--version "${VER}" \
27+
--architecture "${ARCH}" \
28+
--maintainer 'Shlomi Noach <shlomi-noach@github.com>' \
29+
--url 'https://github.com/openark/zookeepercli' \
30+
--description 'Zookeeper client console' \
31+
--license 'Apache 2.0' \
32+
--category 'universe/net' \
33+
--no-depends --no-auto-depends \
34+
--prefix /usr/local/bin \
35+
--chdir "./bin" .
36+
done

‎scripts/prepare_container.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh -e
2+
# Build deb package for zookeepercli
3+
# Sergei Kraev <skraev@tradingview.com>
4+
#
5+
6+
echo "========= Preparing packing start =========";
7+
apk update
8+
apk add --no-cache \
9+
git \
10+
ruby \
11+
rpm-dev \
12+
tar \
13+
zip
14+
15+
git config --global --add safe.directory "$(pwd)"
16+
gem install fpm

‎vendor/github.com/outbrain/golib/LICENSE

+201
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/samuel/go-zookeeper/.gitignore

-1
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/.travis.yml

-33
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/README.md

-11
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/examples/basic.go

-22
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/cluster_test.go

-314
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/conn.go

+74-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/samuel/go-zookeeper/zk/conn_test.go

-57
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/constants.go

+17-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/samuel/go-zookeeper/zk/constants_test.go

-24
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/dnshostprovider_test.go

-224
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/flw.go

+6-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/samuel/go-zookeeper/zk/flw_test.go

-330
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/lock_test.go

-94
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/server_help.go

-216
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/server_java.go

-136
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/structs.go

+17-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/samuel/go-zookeeper/zk/structs_test.go

-83
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/throttle_test.go

-136
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/util_test.go

-53
This file was deleted.

‎vendor/github.com/samuel/go-zookeeper/zk/zk_test.go

-939
This file was deleted.

‎vendor/modules.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# github.com/outbrain/golib v0.0.0-20200503083229-2531e5dbcc71
2+
## explicit
3+
github.com/outbrain/golib/log
4+
# github.com/samuel/go-zookeeper v0.0.0-20201211165307-7117e9ea2414
5+
## explicit
6+
github.com/samuel/go-zookeeper/zk

0 commit comments

Comments
 (0)
Please sign in to comment.