Skip to content

Commit 7826b64

Browse files
committed
Merge remote-tracking branch 'upstream/master' into feature/fix-global-variable-str-handling
2 parents c5cdfeb + e87c46d commit 7826b64

File tree

4 files changed

+211
-113
lines changed

4 files changed

+211
-113
lines changed

.circleci/config.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Use the latest 2.1 version of CircleCI pipeline process engine.
2+
# See: https://circleci.com/docs/2.1/configuration-reference
3+
version: 2.1
4+
5+
jobs:
6+
gotest:
7+
docker:
8+
- image: golang:1.18
9+
working_directory: /terraform-provider-mysql
10+
steps:
11+
- checkout
12+
- run:
13+
name: Test
14+
environment:
15+
# DB override is there only to skip some tests.
16+
DB: mysql:something
17+
command: |
18+
make test
19+
- run:
20+
name: Vet
21+
command: |
22+
make vet
23+
integration:
24+
machine:
25+
image: ubuntu-2004:current
26+
docker_layer_caching: true
27+
parameters:
28+
target:
29+
type: string
30+
steps:
31+
- checkout
32+
- run:
33+
name: Install mysql client
34+
command: |
35+
sudo apt-get update
36+
sudo apt-get -f -y install mysql-client
37+
- run:
38+
name: Run test << parameters.target >>
39+
command: |
40+
make << parameters.target >>
41+
42+
workflows:
43+
all-tests:
44+
jobs:
45+
- integration:
46+
matrix:
47+
parameters:
48+
target: ["testversion5.6", "testversion5.7", "testversion8.0", "testpercona5.7", "testpercona8.0", "testmariadb10.3", "testmariadb10.8", "testtidb6.1.0"]
49+
- gotest

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ testtidb%:
5353
$(MAKE) MYSQL_VERSION=$* MYSQL_PORT=34$(shell echo "$*" | tr -d '.') testtidb
5454

5555
testtidb:
56-
@sh -c "'$(CURDIR)/scripts/tidb-test-cluster.sh' --init --port $(MYSQL_PORT)"
56+
@sh -c "'$(CURDIR)/scripts/tidb-test-cluster.sh' --init --port $(MYSQL_PORT) --version $(MYSQL_VERSION)"
5757
@echo 'Waiting for TiDB...'
5858
@while ! mysql -h 127.0.0.1 -P $(MYSQL_PORT) -u "$(TEST_USER)" -e 'SELECT 1' >/dev/null 2>&1; do printf '.'; sleep 1; done ; echo ; echo "Connected!"
5959
MYSQL_USERNAME="$(TEST_USER)" MYSQL_PASSWORD="" MYSQL_ENDPOINT=127.0.0.1:$(MYSQL_PORT) $(MAKE) testacc

scripts/tidb-test-cluster.sh

Lines changed: 48 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
23
# This file creates minimal TiDB cluster for tests
34

45
REALPATH=$(which realpath)
@@ -10,13 +11,12 @@ fi
1011

1112
# Set up constants
1213
SCRIPT_PATH=$(realpath $(dirname "$0"))
13-
TEMPDIR=$(mktemp -d)
1414
DOCKER=$(which docker)
15-
TAG_VERSION="v6.1.0"
1615
SCRIPT_INIT=false
17-
MYIP="127.0.0.1"
16+
DOCKER_NETWORK="mysql_provider_test_network"
1817
RUNNING_CONTAINERS=""
1918
export MYSQL_PORT=${MYSQL_PORT:-4000}
19+
export TAG_VERSION="v${MYSQL_VERSION:-6.1.0}"
2020

2121
# Sanity checks
2222
if [ -z "$DOCKER" ]; then
@@ -31,12 +31,13 @@ set -o nounset # Disallow expansion of unset variables
3131
set -o pipefail # Use last non-zero exit code in a pipeline
3232

3333
function script_usage() {
34-
cat <<EOF
34+
cat <<EOF | column -t -s"^"
3535
Usage:
36-
--mysql-port <MYSQL_PORT> TiDB Listen port
37-
--init Init TiDB cluster
38-
--destroy Destroy resources
39-
-h|--help Displays this help
36+
--init ^ Init TiDB cluster
37+
--destroy ^ Destroy resources
38+
--port <MYSQL_PORT> ^ TiDB Listen port (default: 4000)
39+
--version <MYSQL_VERSION> ^ TiDB version (default: 6.1.0)
40+
-h|--help ^ Displays this help
4041
EOF
4142
}
4243

@@ -46,20 +47,31 @@ function parse_params() {
4647
param="$1"
4748
case $param in
4849
--port)
49-
if [ -z "$2" ]; then
50-
echo missing param
50+
shift
51+
if [ -z "$1" ]; then
52+
echo "Missing port"
53+
exit 1
5154
fi
52-
export MYSQL_PORT=${2:-4000}
53-
shift # past argument
54-
shift # past value
55+
export MYSQL_PORT=${1:-4000}
56+
shift
5557
;;
58+
--version)
59+
shift
60+
if [ -z "$1" ]; then
61+
echo "Missing version"
62+
exit 1
63+
fi
64+
export TAG_VERSION="v${1:-6.1.0}"
65+
shift
66+
;;
67+
5668
--init)
5769
export SCRIPT_INIT=true
5870
shift
5971
;;
6072
--destroy)
6173
if [ -z "$SCRIPT_INIT" ]; then
62-
echo "Cant destroy and init at once"
74+
echo "Can't destroy and init at once"
6375
exit 1
6476
fi
6577
destroy_cluster
@@ -80,81 +92,13 @@ function parse_params() {
8092
done
8193
}
8294

83-
84-
85-
# My IP detection source code
86-
function get_my_ip() {
87-
if [ ! -d "$SCRIPT_PATH/../bin" ]; then
88-
mkdir -p $SCRIPT_PATH/../bin
89-
fi
90-
cat <<\__END__ > $SCRIPT_PATH/../bin/myip.go
91-
package main
92-
93-
import (
94-
"errors"
95-
"fmt"
96-
"net"
97-
"os"
98-
)
99-
100-
func main() {
101-
102-
ip, err := externalIP()
103-
if err != nil {
104-
fmt.Println(err)
105-
os.Exit(1)
106-
}
107-
fmt.Println(ip)
108-
109-
}
110-
111-
func externalIP() (string, error) {
112-
ifaces, err := net.Interfaces()
113-
if err != nil {
114-
return "", err
115-
}
116-
for _, iface := range ifaces {
117-
if iface.Flags&net.FlagUp == 0 {
118-
continue // interface down
119-
}
120-
if iface.Flags&net.FlagLoopback != 0 {
121-
continue // loopback interface
122-
}
123-
addrs, err := iface.Addrs()
124-
if err != nil {
125-
return "", err
126-
}
127-
for _, addr := range addrs {
128-
var ip net.IP
129-
switch v := addr.(type) {
130-
case *net.IPNet:
131-
ip = v.IP
132-
case *net.IPAddr:
133-
ip = v.IP
134-
}
135-
if ip == nil || ip.IsLoopback() {
136-
continue
137-
}
138-
ip = ip.To4()
139-
if ip == nil {
140-
continue // not an ipv4 address
141-
}
142-
return ip.String(), nil
143-
}
144-
}
145-
return "", errors.New("are you connected to the network?")
146-
}
147-
__END__
148-
gofmt -w $SCRIPT_PATH/../bin/myip.go || return 1
149-
MYIP=$(go run $SCRIPT_PATH/../bin/myip.go)
150-
}
151-
15295
function destroy_cluster() {
15396
RUNNING_CONTAINERS=$(${DOCKER} ps -a -q -f name=tidb -f name=tikv -f name=pd)
15497
echo "==> Removing any existing TiDB cluster components"
15598
if [ ! -z "$RUNNING_CONTAINERS" ]; then
15699
${DOCKER} rm -f $RUNNING_CONTAINERS >/dev/null 2>&1
157100
fi
101+
${DOCKER} network rm ${DOCKER_NETWORK} >/dev/null 2>&1 || true
158102
}
159103

160104
function show_docker_logs_and_exit() {
@@ -165,66 +109,58 @@ function show_docker_logs_and_exit() {
165109
}
166110

167111
function run_pd() {
168-
local _myip=$1
169112
echo "==> Pulling up PD component"
170-
${DOCKER} run -d --name pd1 \
171-
-p 2379:2379 \
172-
-p 2380:2380 \
113+
${DOCKER} run -d --name pd \
173114
-v /etc/localtime:/etc/localtime:ro \
174-
-v /data:/data \
175-
-h pd1 \
115+
-h pd \
116+
--network "$DOCKER_NETWORK" \
176117
pingcap/pd:$TAG_VERSION \
177-
--name="pd1" \
178-
--data-dir="$TEMPDIR/pd1" \
118+
--name="pd" \
119+
--data-dir="/data" \
179120
--client-urls="http://0.0.0.0:2379" \
180-
--advertise-client-urls="http://$_myip:2379" \
121+
--advertise-client-urls="http://pd:2379" \
181122
--peer-urls="http://0.0.0.0:2380" \
182-
--advertise-peer-urls="http://$_myip:2380" \
183-
--initial-cluster="pd1=http://$_myip:2380" >/dev/null 2>&1 || show_docker_logs_and_exit pd
123+
--advertise-peer-urls="http://pd:2380" \
124+
--initial-cluster="pd=http://pd:2380" >/dev/null 2>&1 || show_docker_logs_and_exit pd
184125
}
185126

186127
function run_tikv() {
187-
local _myip=$1
188128
echo "==> Pulling up TiKV component"
189-
${DOCKER} run -d --name tikv1 \
190-
-p 20160:20160 \
191-
-p 20180:20180 \
129+
${DOCKER} run -d --name tikv \
192130
-v /etc/localtime:/etc/localtime:ro \
193-
-v /data:/data \
194-
-h tikv1 \
131+
-h tikv \
132+
--network "$DOCKER_NETWORK" \
195133
pingcap/tikv:v4.0.0 \
196134
--addr="0.0.0.0:20160" \
197-
--advertise-addr="$_myip:20160" \
135+
--advertise-addr="tikv:20160" \
198136
--status-addr="0.0.0.0:20180" \
199-
--data-dir="$TEMPDIR/tikv1" \
200-
--pd="$_myip:2379" >/dev/null 2>&1 || show_docker_logs_and_exit tikv
137+
--data-dir="/data" \
138+
--pd="pd:2379" >/dev/null 2>&1 || show_docker_logs_and_exit tikv
201139
}
202140

203141
function run_tidb() {
204-
local _myip=$1
205-
local _mysql_port=$2
142+
local _mysql_port=$1
206143
echo "==> Pulling up TiDB component"
207144
${DOCKER} run -d --name tidb \
208145
-p $_mysql_port:$_mysql_port \
209-
-p 10080:10080 \
210146
-v /etc/localtime:/etc/localtime:ro \
211147
-h tidb \
148+
--network "$DOCKER_NETWORK" \
212149
pingcap/tidb:$TAG_VERSION \
213150
--store=tikv \
214151
-P $_mysql_port \
215-
--path="$_myip:2379" >/dev/null 2>&1 || show_docker_logs_and_exit tidb
152+
--path="pd:2379" >/dev/null 2>&1 || show_docker_logs_and_exit tidb
216153
}
217154

218155
function main() {
219-
local _myip
220156
parse_params "$@"
221157
if [[ "$SCRIPT_INIT" = "true" ]]; then
222158
echo "==> Pulling up TiDB cluster with TiKV and TB components"
223-
get_my_ip && \
224159
destroy_cluster && \
225-
run_pd $MYIP && \
226-
run_tikv $MYIP && \
227-
run_tidb $MYIP $MYSQL_PORT
160+
${DOCKER} network create ${DOCKER_NETWORK} && \
161+
run_pd && \
162+
run_tikv && \
163+
run_tidb $MYSQL_PORT
228164

229165
else
230166
script_usage

0 commit comments

Comments
 (0)