From 3b817a27c4a30c4a0ae26723da76a7c50c42f51e Mon Sep 17 00:00:00 2001 From: GuptaManan100 Date: Fri, 5 Mar 2021 15:27:57 +0530 Subject: [PATCH] Added vschema to the vttestserver image and authorized all users for ddl commands Signed-off-by: GuptaManan100 --- docker/vttestserver/Dockerfile.mysql57 | 5 +- docker/vttestserver/Dockerfile.mysql80 | 5 +- docker/vttestserver/runMysql57.sh | 20 ++++++++ docker/vttestserver/runMysql80.sh | 20 ++++++++ docker/vttestserver/setupVschemaFolder.sh | 59 +++++++++++++++++++++++ 5 files changed, 107 insertions(+), 2 deletions(-) create mode 100755 docker/vttestserver/runMysql57.sh create mode 100755 docker/vttestserver/runMysql80.sh create mode 100755 docker/vttestserver/setupVschemaFolder.sh diff --git a/docker/vttestserver/Dockerfile.mysql57 b/docker/vttestserver/Dockerfile.mysql57 index 3ebed377933..383df899e73 100644 --- a/docker/vttestserver/Dockerfile.mysql57 +++ b/docker/vttestserver/Dockerfile.mysql57 @@ -55,4 +55,7 @@ COPY --from=builder --chown=vitess:vitess /vt/install /vt VOLUME /vt/vtdataroot USER vitess -CMD /vt/bin/vttestserver -port $PORT -keyspaces $KEYSPACES -num_shards $NUM_SHARDS -mysql_bind_host ${MYSQL_BIND_HOST:-127.0.0.1} -mysql_server_version ${MYSQL_SERVER_VERSION:-5.7.9-vitess} +COPY docker/vttestserver/setupVschemaFolder.sh /vt/setupVschemaFolder.sh +COPY docker/vttestserver/runMysql57.sh /vt/run.sh + +CMD /vt/run.sh diff --git a/docker/vttestserver/Dockerfile.mysql80 b/docker/vttestserver/Dockerfile.mysql80 index 71c0632c165..c9fd502182d 100644 --- a/docker/vttestserver/Dockerfile.mysql80 +++ b/docker/vttestserver/Dockerfile.mysql80 @@ -55,4 +55,7 @@ COPY --from=builder --chown=vitess:vitess /vt/install /vt VOLUME /vt/vtdataroot USER vitess -CMD /vt/bin/vttestserver -port $PORT -keyspaces $KEYSPACES -num_shards $NUM_SHARDS -mysql_bind_host ${MYSQL_BIND_HOST:-127.0.0.1} -mysql_server_version ${MYSQL_SERVER_VERSION:-8.0.21-vitess} +COPY docker/vttestserver/setupVschemaFolder.sh /vt/setupVschemaFolder.sh +COPY docker/vttestserver/runMysql80.sh /vt/run.sh + +CMD /vt/run.sh diff --git a/docker/vttestserver/runMysql57.sh b/docker/vttestserver/runMysql57.sh new file mode 100755 index 00000000000..1a623e7daee --- /dev/null +++ b/docker/vttestserver/runMysql57.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2021 The Vitess Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Setup the Vschema Folder +/vt/setupVschemaFolder.sh "$KEYSPACES" "$NUM_SHARDS" +# Run the vttestserver binary +/vt/bin/vttestserver -port "$PORT" -keyspaces "$KEYSPACES" -num_shards "$NUM_SHARDS" -mysql_bind_host "${MYSQL_BIND_HOST:-127.0.0.1}" -mysql_server_version "${MYSQL_SERVER_VERSION:-5.7.9-vitess}" -vschema_ddl_authorized_users=% -schema_dir="/vt/schema/" \ No newline at end of file diff --git a/docker/vttestserver/runMysql80.sh b/docker/vttestserver/runMysql80.sh new file mode 100755 index 00000000000..4cd4391ee61 --- /dev/null +++ b/docker/vttestserver/runMysql80.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2021 The Vitess Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Setup the Vschema Folder +/vt/setupVschemaFolder.sh "$KEYSPACES" "$NUM_SHARDS" +# Run the vttestserver binary +/vt/bin/vttestserver -port "$PORT" -keyspaces "$KEYSPACES" -num_shards "$NUM_SHARDS" -mysql_bind_host "${MYSQL_BIND_HOST:-127.0.0.1}" -mysql_server_version "${MYSQL_SERVER_VERSION:-8.0.21-vitess}" -vschema_ddl_authorized_users=% -schema_dir="/vt/schema/" diff --git a/docker/vttestserver/setupVschemaFolder.sh b/docker/vttestserver/setupVschemaFolder.sh new file mode 100755 index 00000000000..fcf1bf746f1 --- /dev/null +++ b/docker/vttestserver/setupVschemaFolder.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Copyright 2021 The Vitess Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# getLength gets the number of elements in a comma separated string +function getLength() { + COUNT=0 + for _ in ${1//,/ } + do + ((COUNT++)) + done + echo "$COUNT" +} + +# The first argument to the file is a comma separated list of keyspaces and the second argument is the comma separated list of number of shards. + +KEYSPACES="$1" +NUM_SHARDS="$2" + +COUNT_KEYSPACES=$(getLength "$KEYSPACES") +COUNT_NUM_SHARDS=$(getLength "$NUM_SHARDS") + +# Incase the number of keyspaces and num_shards do not match, throw an error +if [ "$COUNT_KEYSPACES" != "$COUNT_NUM_SHARDS" ]; then + echo "Incompatible list of keyspaces and number of shards" + exit 1 +fi + +# Convert the strings to lists +read -ra KEYSPACES_LIST <<<"${KEYSPACES//,/ }" +read -ra NUM_SHARDS_LIST <<<"${NUM_SHARDS//,/ }" + +# create the main schema directory +mkdir /vt/schema/ + +i=0; +for keyspace in "${KEYSPACES_LIST[@]}"; +do + # create a directory for each keyspace + mkdir "/vt/schema/$keyspace" + num_shard=${NUM_SHARDS_LIST[$i]} + # Create a vschema.json file only if the number of shards are more than 1 + if [[ $num_shard -gt "1" ]]; then + printf "{\n\t\"sharded\": true\n}" > "/vt/schema/$keyspace/vschema.json" + fi + ((i++)) +done