From 51f853100b58d1aac86d0cee49deb957aeaf1652 Mon Sep 17 00:00:00 2001 From: Cyber-SiKu Date: Mon, 9 Jan 2023 15:02:15 +0800 Subject: [PATCH] [feat]toolsv2: build to image Signed-off-by: Cyber-SiKu --- curvefs/docker/debian9/Dockerfile | 3 +- docker/debian9/Dockerfile | 3 +- docker/debian9/compile/Dockerfile | 34 ++++++++++---- tools-v2/Makefile | 76 ++++++++++++++++++++++++------- tools-v2/README.md | 4 +- tools-v2/pkg/config/curve.yaml | 25 ++++++++++ util/build.sh | 9 ++++ util/image.sh | 3 +- util/install.sh | 11 +++++ 9 files changed, 139 insertions(+), 29 deletions(-) create mode 100644 tools-v2/pkg/config/curve.yaml diff --git a/curvefs/docker/debian9/Dockerfile b/curvefs/docker/debian9/Dockerfile index a424f9fbfc..166fec558c 100644 --- a/curvefs/docker/debian9/Dockerfile +++ b/curvefs/docker/debian9/Dockerfile @@ -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"] diff --git a/docker/debian9/Dockerfile b/docker/debian9/Dockerfile index 109f834370..662cc89d5d 100644 --- a/docker/debian9/Dockerfile +++ b/docker/debian9/Dockerfile @@ -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"] diff --git a/docker/debian9/compile/Dockerfile b/docker/debian9/compile/Dockerfile index fe0ac3151e..cfc68e429b 100644 --- a/docker/debian9/compile/Dockerfile +++ b/docker/debian9/compile/Dockerfile @@ -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" \ @@ -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 \ @@ -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/ \ @@ -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 diff --git a/tools-v2/Makefile b/tools-v2/Makefile index 87c3698828..e125987843 100644 --- a/tools-v2/Makefile +++ b/tools-v2/Makefile @@ -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/protoc-gen-go@v1.28 - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2 + # 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 diff --git a/tools-v2/README.md b/tools-v2/README.md index 1b83993ce0..055d53f71e 100644 --- a/tools-v2/README.md +++ b/tools-v2/README.md @@ -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 diff --git a/tools-v2/pkg/config/curve.yaml b/tools-v2/pkg/config/curve.yaml new file mode 100644 index 0000000000..96ccc637db --- /dev/null +++ b/tools-v2/pkg/config/curve.yaml @@ -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 diff --git a/util/build.sh b/util/build.sh index 41fbccca9e..62a702ef1d 100644 --- a/util/build.sh +++ b/util/build.sh @@ -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 } diff --git a/util/image.sh b/util/image.sh index c9ac156526..f3b71ce98b 100644 --- a/util/image.sh +++ b/util/image.sh @@ -83,6 +83,7 @@ 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` @@ -90,7 +91,7 @@ do # delimiter dsv="=" - if [ $file = "etcd.conf" ]; then + if [ $file = "etcd.conf" -o $file = "curve.yaml" ]; then dsv=": " fi diff --git a/util/install.sh b/util/install.sh index 7f15e6944d..9c012b685d 100644 --- a/util/install.sh +++ b/util/install.sh @@ -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 @@ -335,6 +345,7 @@ main() { else install_curvefs fi + install_tools-v2 } ############################ MAIN()