github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/scripts/download-integration-test-binaries.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2023 PingCAP, Inc.
     3  #
     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  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  # download-integration-test-binaries.sh will
    16  # * download all the binaries you need for integration testing
    17  
    18  set -o errexit
    19  set -o pipefail
    20  
    21  # Specify which branch to be utilized for executing the test, which is
    22  # exclusively accessible when obtaining binaries from
    23  # http://fileserver.pingcap.net.
    24  branch=${1:-master}
    25  # Specify whether to download the community version of binaries, the following
    26  # four arguments are applicable only when utilizing the community version of
    27  # binaries.
    28  community=${2:-false}
    29  # Specify which version of the community binaries that will be utilized.
    30  ver=${3:-v8.1.0}
    31  # Specify which os that will be used to pack the binaries.
    32  os=${4:-linux}
    33  # Specify which architecture that will be used to pack the binaries.
    34  arch=${5:-amd64}
    35  
    36  set -o nounset
    37  
    38  # See https://misc.flogisoft.com/bash/tip_colors_and_formatting.
    39  color-green() { # Green
    40  	echo -e "\x1B[1;32m${*}\x1B[0m"
    41  }
    42  
    43  function download() {
    44  	local url=$1
    45  	local file_name=$2
    46  	local file_path=$3
    47  	if [[ -f "${file_path}" ]]; then
    48  		echo "file ${file_name} already exists, skip download"
    49  		return
    50  	fi
    51  	echo ">>>"
    52  	echo "download ${file_name} from ${url}"
    53  	wget --no-verbose --retry-connrefused --waitretry=1 -t 3 -O "${file_path}" "${url}"
    54  }
    55  
    56  # download_community_version will try to download required binaries from the
    57  # public accessible community version
    58  function download_community_binaries() {
    59  	local dist="${ver}-${os}-${arch}"
    60  	local tidb_file_name="tidb-community-server-$dist"
    61  	local tidb_tar_name="${tidb_file_name}.tar.gz"
    62  	local tidb_url="https://download.pingcap.org/$tidb_tar_name"
    63  	local toolkit_file_name="tidb-community-toolkit-$dist"
    64  	local toolkit_tar_name="${toolkit_file_name}.tar.gz"
    65  	local toolkit_url="https://download.pingcap.org/$toolkit_tar_name"
    66  
    67  	color-green "Download community binaries..."
    68  	download "$tidb_url" "$tidb_tar_name" "tmp/$tidb_tar_name"
    69  	download "$toolkit_url" "$toolkit_tar_name" "tmp/$toolkit_tar_name"
    70  	# extract the tidb community version binaries
    71  	tar -xz -C tmp -f tmp/$tidb_tar_name
    72  	# extract the pd server
    73  	tar -xz -C third_bin -f tmp/$tidb_file_name/pd-${dist}.tar.gz
    74  	# extract the tikv server
    75  	tar -xz -C third_bin -f tmp/$tidb_file_name/tikv-${dist}.tar.gz
    76  	# extract the tidb server
    77  	tar -xz -C third_bin -f tmp/$tidb_file_name/tidb-${dist}.tar.gz
    78  	# extract the tiflash
    79  	tar -xz -C third_bin -f tmp/$tidb_file_name/tiflash-${dist}.tar.gz &&
    80  		mv third_bin/tiflash third_bin/_tiflash &&
    81  		mv third_bin/_tiflash/* third_bin && rm -rf third_bin/_tiflash
    82  	# extract the pd-ctl
    83  	tar -xz -C third_bin pd-ctl -f tmp/$tidb_file_name/ctl-${dist}.tar.gz
    84  	# extract the toolkit community version binaries, get the etcdctl and
    85  	# the sync_diff_inspector
    86  	tar -xz -C third_bin \
    87  		$toolkit_file_name/etcdctl $toolkit_file_name/sync_diff_inspector \
    88  		-f tmp/$toolkit_tar_name &&
    89  		mv third_bin/$toolkit_file_name/* third_bin &&
    90  		rm -rf third_bin/$toolkit_file_name
    91  
    92  	# ycsb
    93  	local ycsb_file_name="go-ycsb-${os}-${arch}"
    94  	local ycsb_tar_name="${ycsb_file_name}.tar.gz"
    95  	local ycsb_url="https://github.com/pingcap/go-ycsb/releases/download/v1.0.0/${ycsb_tar_name}"
    96  	wget -O "tmp/$ycsb_tar_name" "$ycsb_url"
    97  	tar -xz -C third_bin -f tmp/$ycsb_tar_name
    98  
    99  	# minio
   100  	local minio_url="https://dl.min.io/server/minio/release/${os}-${arch}/minio"
   101  	download "$minio_url" "minio" "third_bin/minio"
   102  
   103  	# jq
   104  	local os_name=$([ "$os" == "darwin" ] && echo -n "macos" || echo -n "$os")
   105  	local jq_url="https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-${os_name}-${arch}"
   106  	wget -O third_bin/jq "$jq_url"
   107  
   108  	chmod a+x third_bin/*
   109  }
   110  
   111  function download_binaries() {
   112  	color-green "Download binaries..."
   113  	# PingCAP file server URL.
   114  	file_server_url="http://fileserver.pingcap.net"
   115  
   116  	# Get sha1 based on branch name.
   117  	tidb_sha1=$(curl "${file_server_url}/download/refs/pingcap/tidb/${branch}/sha1")
   118  	tikv_sha1=$(curl "${file_server_url}/download/refs/pingcap/tikv/${branch}/sha1")
   119  	pd_sha1=$(curl "${file_server_url}/download/refs/pingcap/pd/${branch}/sha1")
   120  	tiflash_sha1=$(curl "${file_server_url}/download/refs/pingcap/tiflash/${branch}/sha1")
   121  
   122  	# All download links.
   123  	tidb_download_url="${file_server_url}/download/builds/pingcap/tidb/${tidb_sha1}/centos7/tidb-server.tar.gz"
   124  	tikv_download_url="${file_server_url}/download/builds/pingcap/tikv/${tikv_sha1}/centos7/tikv-server.tar.gz"
   125  	pd_download_url="${file_server_url}/download/builds/pingcap/pd/${pd_sha1}/centos7/pd-server.tar.gz"
   126  	tiflash_download_url="${file_server_url}/download/builds/pingcap/tiflash/${branch}/${tiflash_sha1}/centos7/tiflash.tar.gz"
   127  	minio_download_url="${file_server_url}/download/minio.tar.gz"
   128  	go_ycsb_download_url="${file_server_url}/download/builds/pingcap/go-ycsb/test-br/go-ycsb"
   129  	etcd_download_url="${file_server_url}/download/builds/pingcap/cdc/etcd-v3.4.7-linux-amd64.tar.gz"
   130  	sync_diff_inspector_url="${file_server_url}/download/builds/pingcap/cdc/sync_diff_inspector_hash-79f1fd1e_linux-amd64.tar.gz"
   131  	jq_download_url="${file_server_url}/download/builds/pingcap/test/jq-1.6/jq-linux64"
   132  	schema_registry_url="${file_server_url}/download/builds/pingcap/cdc/schema-registry.tar.gz"
   133  
   134  	download "$tidb_download_url" "tidb-server.tar.gz" "tmp/tidb-server.tar.gz"
   135  	tar -xz -C third_bin bin/tidb-server -f tmp/tidb-server.tar.gz && mv third_bin/bin/tidb-server third_bin/
   136  
   137  	download "$pd_download_url" "pd-server.tar.gz" "tmp/pd-server.tar.gz"
   138  	tar -xz -C third_bin 'bin/*' -f tmp/pd-server.tar.gz && mv third_bin/bin/* third_bin/
   139  
   140  	download "$tikv_download_url" "tikv-server.tar.gz" "tmp/tikv-server.tar.gz"
   141  	tar -xz -C third_bin bin/tikv-server -f tmp/tikv-server.tar.gz && mv third_bin/bin/tikv-server third_bin/
   142  
   143  	download "$tiflash_download_url" "tiflash.tar.gz" "tmp/tiflash.tar.gz"
   144  	tar -xz -C third_bin -f tmp/tiflash.tar.gz
   145  	mv third_bin/tiflash third_bin/_tiflash
   146  	mv third_bin/_tiflash/* third_bin && rm -rf third_bin/_tiflash
   147  
   148  	download "$minio_download_url" "minio.tar.gz" "tmp/minio.tar.gz"
   149  	tar -xz -C third_bin -f tmp/minio.tar.gz
   150  
   151  	download "$go_ycsb_download_url" "go-ycsb" "third_bin/go-ycsb"
   152  	download "$jq_download_url" "jq" "third_bin/jq"
   153  	download "$etcd_download_url" "etcd.tar.gz" "tmp/etcd.tar.gz"
   154  	tar -xz -C third_bin etcd-v3.4.7-linux-amd64/etcdctl -f tmp/etcd.tar.gz
   155  	mv third_bin/etcd-v3.4.7-linux-amd64/etcdctl third_bin/ && rm -rf third_bin/etcd-v3.4.7-linux-amd64
   156  
   157  	download "$sync_diff_inspector_url" "sync_diff_inspector.tar.gz" "tmp/sync_diff_inspector.tar.gz"
   158  	tar -xz -C third_bin -f tmp/sync_diff_inspector.tar.gz
   159  
   160  	download "$schema_registry_url" "schema-registry.tar.gz" "tmp/schema-registry.tar.gz"
   161  	tar -xz -C third_bin -f tmp/schema-registry.tar.gz
   162  	mv third_bin/schema-registry third_bin/_schema_registry
   163  	mv third_bin/_schema_registry/* third_bin && rm -rf third_bin/_schema_registry
   164  
   165  	chmod a+x third_bin/*
   166  }
   167  
   168  # Some temporary dir.
   169  rm -rf tmp
   170  rm -rf third_bin
   171  
   172  mkdir -p third_bin
   173  mkdir -p tmp
   174  mkdir -p bin
   175  
   176  [ $community == true ] && download_community_binaries || download_binaries
   177  
   178  # Copy it to the bin directory in the root directory.
   179  rm -rf tmp
   180  rm -rf bin/bin
   181  mv third_bin/* ./bin
   182  rm -rf third_bin
   183  
   184  color-green "Download SUCCESS"