Skip to content

Commit

Permalink
[feat]toolsv2: build to image
Browse files Browse the repository at this point in the history
Signed-off-by: Cyber-SiKu <[email protected]>
  • Loading branch information
Cyber-SiKu committed Mar 3, 2023
1 parent 9d5a18a commit 51f8531
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 29 deletions.
3 changes: 2 additions & 1 deletion curvefs/docker/debian9/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ COPY entrypoint.sh /
COPY curvefs /curvefs
COPY libmemcached.so libmemcached.so.11 libhashkit.so.2 /usr/lib/
RUN mkdir -p /etc/curvefs /core /etc/curve && chmod a+x /entrypoint.sh \
&& cp /curvefs/tools/sbin/curvefs_tool /usr/bin
&& cp /curvefs/tools/sbin/curvefs_tool /usr/bin \
&& cp curvefs/tools-v2/sbin/curve /usr/bin/
ENTRYPOINT ["/entrypoint.sh"]
3 changes: 2 additions & 1 deletion docker/debian9/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ COPY curvebs /curvebs
RUN mkdir -p /etc/curve /etc/nebd \
&& chmod a+x /entrypoint.sh \
&& cp curvebs/tools/sbin/curve_ops_tool curvebs/nbd/sbin/curve-nbd \
&& cp curvebs/tools/sbin/curve_ops_tool /usr/bin/
&& cp curvebs/tools/sbin/curve_ops_tool /usr/bin/ \
&& cp curvebs/tools-v2/sbin/curve /usr/bin/
ENTRYPOINT ["/entrypoint.sh"]
34 changes: 26 additions & 8 deletions docker/debian9/compile/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
FROM debian:9

ENV GITHUB_PROXY=https://ghproxy.com/
ENV ETCD_VER=v3.4.0 \
DOWNLOAD_ETCD_URL=${GITHUB_PROXY}https://github.com/etcd-io/etcd/releases/download
ENV ETCD_VERSION=v3.4.0 \
DOWNLOAD_ETCD_URL=${GITHUB_PROXY}https://github.com/etcd-io/etcd/releases/download \
GOPROXY=https://goproxy.io,direct \
PROTOC_VERSION=21.8 \
GO_VERSION=1.19.6 \
PROTOC_GEN_GO_VERSION=v1.28 \
PROTOC_GEN_GO_GRPC_VERSION=v1.2
RUN echo "deb http://mirrors.163.com/debian/ stretch main\n" \
"deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib\n" \
"deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib\n" \
Expand Down Expand Up @@ -46,6 +51,8 @@ RUN echo "deb http://mirrors.163.com/debian/ stretch main\n" \
procps \
lsof \
gdb \
unzip \
musl-tools \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
Expand All @@ -62,17 +69,17 @@ RUN echo "deb http://mirrors.163.com/debian/ stretch main\n" \
&& mkdir -p /root/.cache/bazelisk/downloads/bazelbuild/bazel-0.17.2-linux-x86_64/bin \
&& mv bazel-0.17.2-linux-x86_64 /root/.cache/bazelisk/downloads/bazelbuild/bazel-0.17.2-linux-x86_64/bin/bazel \
&& chmod +x /root/.cache/bazelisk/downloads/bazelbuild/bazel-4.2.2-linux-x86_64/bin/bazel /root/.cache/bazelisk/downloads/bazelbuild/bazel-0.17.2-linux-x86_64/bin/bazel /usr/bin/bazel /usr/bin/bazelisk \
&& wget ${GITHUB_PROXY}/https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.tar.gz \
&& wget ${GITHUB_PROXY}https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-Linux-x86_64.tar.gz \
&& tar Cxzf /usr/share/ cmake-3.13.4-Linux-x86_64.tar.gz \
&& rm cmake-3.13.4-Linux-x86_64.tar.gz \
&& ln -s /usr/share/cmake-3.13.4-Linux-x86_64/bin/cmake /usr/bin/cmake \
&& wget https://curve-build.nos-eastchina1.126.net/fuse3.tar.gz \
&& tar Cxzf /usr/include/ fuse3.tar.gz && rm fuse3.tar.gz \
&& rm -f /usr/local/etcd-${ETCD_VER}-linux-amd64.tar.gz \
&& rm -f /usr/local/etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
&& rm -rf /usr/local/etcd && mkdir -p /usr/local/etcd \
&& curl -L ${DOWNLOAD_ETCD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /usr/local/etcd-${ETCD_VER}-linux-amd64.tar.gz \
&& tar xzvf /usr/local/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /usr/local/etcd --strip-components=1 \
&& rm -f /usr/local/etcd-${ETCD_VER}-linux-amd64.tar.gz \
&& curl -L ${DOWNLOAD_ETCD_URL}/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz -o /usr/local/etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
&& tar xzvf /usr/local/etcd-${ETCD_VERSION}-linux-amd64.tar.gz -C /usr/local/etcd --strip-components=1 \
&& rm -f /usr/local/etcd-${ETCD_VERSION}-linux-amd64.tar.gz \
&& ln -sf /usr/local/etcd/etcd /usr/bin/etcd && ln -sf /usr/local/etcd/etcdctl /usr/bin/etcdctl \
&& wget https://curve-build.nos-eastchina1.126.net/memcache/memcached-1.6.17.tar.gz \
&& tar xvf memcached-1.6.17.tar.gz && cd memcached-1.6.17/ \
Expand All @@ -84,4 +91,15 @@ RUN echo "deb http://mirrors.163.com/debian/ stretch main\n" \
&& mv libetcdclient.so /usr/lib/ \
&& mv libfuse3.so libfuse3.so.3 libfuse3.so.3.10.5 libnl-3.so.200 libnl-genl-3.so.200 /usr/lib/x86_64-linux-gnu/ \
&& mv libjemalloc.so libjemalloc.so.1 libjemalloc.so.2 /usr/local/lib/ \
&& rm curve-base.tar.gz
&& rm curve-base.tar.gz \
&& wget https://golang.google.cn/dl/go${GO_VERSION}.linux-amd64.tar.gz \
&& tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz \
&& rm go${GO_VERSION}.linux-amd64.tar.gz \
&& export PATH=$PATH:/usr/local/go/bin \
&& go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct \
&& wget ${GITHUB_PROXY}https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip \
&& unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip "bin/protoc" -d /usr/ \
&& rm protoc-${PROTOC_VERSION}-linux-x86_64.zip \
&& go install google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION} \
&& go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION}
ENV PATH=$PATH:/usr/local/go/bin:/root/go/bin
76 changes: 60 additions & 16 deletions tools-v2/Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,76 @@
# Copyright (C) 2022 Jingli Chen (Wine93), NetEase Inc.
.PHONY: build debug init proto clean install_grpc_protobuf

.PHONY: build init proto clean
version?=unknown
GITHUB_PROXY="https://ghproxy.com/"
PROTOC_VERSION= 21.8
PROTOC_GEN_GO_VERSION= "v1.28"
PROTOC_GEN_GO_GRPC_VERSION= "v1.2"

release?= 0
version?= "unknown"
# go env
GOPROXY :=https://goproxy.cn,direct
GOOS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
GOARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
CGO_LDFLAGS := "-static"
CC := musl-gcc

GOENV := GO111MODULE=on
GOENV += GOPROXY=$(GOPROXY)
GOENV += CC=$(CC)
GOENV += CGO_ENABLED=1 CGO_LDFLAGS=$(CGO_LDFLAGS)
GOENV += GOOS=$(GOOS) GOARCH=$(GOARCH)

# go
GO := go

# output
OUTPUT := sbin/curve

# version
VERSION_FLAG := -X github.com/opencurve/curve/tools-v2/pkg/cli/command/version.Version=$(version)

# build flags
CGO_BUILD_LDFLAGS := -s -w -linkmode external
CGO_BUILD_LDFLAGS += -extldflags "-static -fpic"
CGO_BUILD_FLAG += -ldflags '$(CGO_BUILD_LDFLAGS) $(VERSION_FLAG)'

BUILD_FLAGS := -a
BUILD_FLAGS += -trimpath
BUILD_FLAGS += $(CGO_BUILD_FLAG)
BUILD_FLAGS += $(EXTRA_FLAGS)

# debug flags
GCFLAGS := "all=-N -l"

CGO_DEBUG_LDFLAGS := -linkmode external
CGO_DEBUG_LDFLAGS += -extldflags "-static -fpic"
CGO_DEBUG_FLAG += -ldflags '$(CGO_DEBUG_LDFLAGS) $(VERSION_FLAG)'

DEBUG_FLAGS := -gcflags=$(GCFLAGS)
DEBUG_FLAGS += $(CGO_DEBUG_FLAG)

# packages
PACKAGES := $(PWD)/cmd/curvecli/main.go

build: proto
@if [ ${release} = 1 ];then\
go build -ldflags "-w -s \
-X github.com/opencurve/curve/tools-v2/pkg/cli/command/version.Version=${version}" \
-o sbin/curve $(PWD)/cmd/curvecli/main.go;\
else\
go build -gcflags "-N -l" -ldflags \
"-X github.com/opencurve/curve/tools-v2/pkg/cli/command/version.Version=${version}" \
-o sbin/curve $(PWD)/cmd/curvecli/main.go;\
fi
$(GOENV) $(GO) build -o $(OUTPUT) $(BUILD_FLAGS) $(PACKAGES)

debug: proto
$(GOENV) $(GO) build -o $(OUTPUT) $(DEBUG_FLAGS) $(PACKAGES)

init: proto
go mod init github.com/opencurve/curve/tools-v2
go mod tidy

proto:
proto: install_grpc_protobuf
@bash mk-proto.sh

install_grpc_protobuf:
# install protoc (https://github.com/protocolbuffers/protobuf/releases/tag/v21.8)
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
# wget ${GITHUB_PROXY}https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip \
# && unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip "bin/protoc" -d /usr/ \
# && rm protoc-${PROTOC_VERSION}-linux-x86_64.zip
go install google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION}
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION}

clean:
rm -rf sbin
Expand Down
4 changes: 2 additions & 2 deletions tools-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ mv curve-latest /usr/bin/curve
set configure file

```bash
wget https://raw.githubusercontent.com/opencurve/curve/master/tools-v2/pkg/config/template.yaml
wget https://raw.githubusercontent.com/opencurve/curve/master/tools-v2/pkg/config/curve.yaml
```

or

```
wget https://curve-tool.nos-eastchina1.126.net/config/template.yaml
wget https://curve-tool.nos-eastchina1.126.net/config/curve.yaml
```

Please modify the `mdsAddr, mdsDummyAddr, etcdAddr` under `curvefs/bs` in the template.yaml file as required
Expand Down
25 changes: 25 additions & 0 deletions tools-v2/pkg/config/curve.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
global:
httpTimeout: 500ms
rpcTimeout: 500ms
rpcRetryTimes: 1
maxChannelSize: 4
showError: false

curvefs:
mdsAddr: 127.0.0.1:6700,127.0.0.1:6701,127.0.0.1:6702 # __CURVEADM_TEMPLATE__ ${cluster_mds_addr} __CURVEADM_TEMPLATE__
mdsDummyAddr: 127.0.0.1:7700,127.0.0.1:7701,127.0.0.1:7702 # __CURVEADM_TEMPLATE__ ${cluster_mds_dummy_addr} __CURVEADM_TEMPLATE__
etcdAddr: 127.0.0.1:23790,127.0.0.1:23791, 127.0.0.1:23792 # __CURVEADM_TEMPLATE__ ${cluster_etcd_addr} __CURVEADM_TEMPLATE__
s3:
ak: ak
sk: sk
endpoint: http://localhost:9000
bucketname: bucketname
blocksize: 4 mib
chunksize: 64 mib
curvebs:
mdsAddr: 127.0.0.1:6700,127.0.0.1:6701,127.0.0.1:6702 # __CURVEADM_TEMPLATE__ ${cluster_mds_addr} __CURVEADM_TEMPLATE__
mdsDummyAddr: 127.0.0.1:7700,127.0.0.1:7701,127.0.0.1:7702 # __CURVEADM_TEMPLATE__ ${cluster_mds_dummy_addr} __CURVEADM_TEMPLATE__
etcdAddr: 127.0.0.1:23790,127.0.0.1:23791,127.0.0.1:23792 # __CURVEADM_TEMPLATE__ ${cluster_etcd_addr} __CURVEADM_TEMPLATE__
root:
user: root
password: root_password
9 changes: 9 additions & 0 deletions util/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ build_target() {
die "$target ${version}\n"
fi
done

# build tools-v2
g_toolsv2_root="tools-v2"
if [ $g_release -eq 1 ]
then
(cd ${g_toolsv2_root} && make build version=${curve_version})
else
(cd ${g_toolsv2_root} && make debug version=${curve_version})
fi
}


Expand Down
3 changes: 2 additions & 1 deletion util/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ if [ "$1" == "bs" ]; then
else
paths=`ls curvefs/conf/*`
fi
paths="$paths tools-v2/pkg/config/curve.yaml"
for path in $paths;
do
dir=`dirname $path`
file=`basename $path`

# delimiter
dsv="="
if [ $file = "etcd.conf" ]; then
if [ $file = "etcd.conf" -o $file = "curve.yaml" ]; then
dsv=": "
fi

Expand Down
11 changes: 11 additions & 0 deletions util/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ install_monitor() {
success "install $project_name success\n"
}

install_tools-v2() {
local project_name="tools-v2"
g_project_name=$project_name
project_prefix="$g_prefix/tools-v2"
mkdir -p $project_prefix/sbin
mkdir -p $project_prefix/conf
copy_file "$project_name/sbin/curve" "$project_prefix/sbin"
copy_file "$project_name/pkg/config/curve.yaml" "$g_prefix/conf"
}

main() {
get_options "$@"
get_build_mode
Expand All @@ -335,6 +345,7 @@ main() {
else
install_curvefs
fi
install_tools-v2
}

############################ MAIN()
Expand Down

0 comments on commit 51f8531

Please sign in to comment.