Skip to content

Commit

Permalink
Added vschema to the vttestserver image and authorized all users for …
Browse files Browse the repository at this point in the history
…ddl commands

Signed-off-by: GuptaManan100 <[email protected]>
  • Loading branch information
GuptaManan100 committed Mar 5, 2021
1 parent 49b29d1 commit 3b817a2
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docker/vttestserver/Dockerfile.mysql57
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion docker/vttestserver/Dockerfile.mysql80
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions docker/vttestserver/runMysql57.sh
Original file line number Diff line number Diff line change
@@ -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/"
20 changes: 20 additions & 0 deletions docker/vttestserver/runMysql80.sh
Original file line number Diff line number Diff line change
@@ -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/"
59 changes: 59 additions & 0 deletions docker/vttestserver/setupVschemaFolder.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3b817a2

Please sign in to comment.