github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docker/custom-scripts/install-dapr-tools.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # Copyright 2021 The Dapr Authors
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  # Unless required by applicable law or agreed to in writing, software
     9  # distributed under the License is distributed on an "AS IS" BASIS,
    10  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  # See the License for the specific language governing permissions and
    12  # limitations under the License.
    13  #
    14  #
    15  # Syntax: ./install-dapr-tools.sh [USERNAME] [GOROOT] [GOPATH] [DAPR_CLI_VERSION] [PROTOC_VERSION] [PROTOC_GEN_GO_VERSION] [PROTOC_GEN_GO_GRPC_VERSION] [GOLANGCI_LINT_VERSION]
    16  
    17  USERNAME=${1:-"dapr"}
    18  GOROOT=${2:-"/usr/local/go"}
    19  GOPATH=${3:-"/go"}
    20  DAPR_CLI_VERSION=${4:-""}
    21  PROTOC_VERSION=${5:-"21.1"}
    22  PROTOC_GEN_GO_VERSION=${6:-"1.28"}
    23  PROTOC_GEN_GO_GRPC_VERSION=${7:-"1.2"}
    24  GOLANGCI_LINT_VERSION=${8:-"1.45.2"}
    25  
    26  set -e
    27  
    28  if [ "$(id -u)" -ne 0 ]; then
    29      echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
    30      exit 1
    31  fi
    32  
    33  # Install socat
    34  apt-get install -y socat
    35  
    36  # Install Dapr CLI
    37  dapr_cli_ver=""
    38  if [ "${DAPR_CLI_VERSION}" != "latest" ]; then
    39      dapr_cli_ver="${DAPR_CLI_VERSION}"
    40  fi
    41  wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash -s "${dapr_cli_ver}"
    42  
    43  # Install protoc compiler required by 'make gen-proto'
    44  architecture="$(uname -m)"
    45  case $architecture in
    46      x86_64) architecture="x86_64";;
    47      aarch64 | armv8*) architecture="aarch_64";;
    48      i?86) architecture="x86_32";;
    49      *) echo "(!) Architecture $architecture unsupported"; exit 1 ;;
    50  esac
    51  
    52  PROTOC_ZIP=protoc-${PROTOC_VERSION}-linux-${architecture}.zip
    53  curl -LO "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}"
    54  unzip -o "${PROTOC_ZIP}" -d /usr/local bin/protoc
    55  chmod -R 755 /usr/local/bin/protoc
    56  unzip -o "${PROTOC_ZIP}" -d /usr/local 'include/*'
    57  chmod -R 755 /usr/local/include/google/protobuf
    58  rm -f "${PROTOC_ZIP}"
    59  
    60  # Install protoc-gen-go and protoc-gen-go-grpc
    61  # Must be installed as the non-root user
    62  export GOBIN="${GOPATH}/bin"
    63  sudo -u ${USERNAME} --preserve-env=GOPATH,GOBIN,GOROOT \
    64      go install "google.golang.org/protobuf/cmd/protoc-gen-go@v${PROTOC_GEN_GO_VERSION}"
    65  sudo -u ${USERNAME} --preserve-env=GOPATH,GOBIN,GOROOT \
    66      go install "google.golang.org/grpc/cmd/protoc-gen-go-grpc@v${PROTOC_GEN_GO_GRPC_VERSION}"
    67  
    68  # Install golangci-lint using the recommended method (best to avoid using go install according to their docs)
    69  # Must be installed as the non-root user
    70  sudo -u ${USERNAME} --preserve-env=GOLANGCI_LINT_VERSION,GOPATH,GOBIN,GOROOT \
    71      sh -c 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOBIN}" "v${GOLANGCI_LINT_VERSION}"'