Build on macOS

Instructions for building Vitess on your machine for testing and development purposes

If you run into issues or have questions, we recommend posting in our Slack channel, click the Slack icon in the top right to join. This is a very active community forum and a great place to interact with other users.

The following has been verified to work on macOS Mojave. If you are new to Vitess, it is recommended to start with the local install guide instead.

Install Dependencies

Install Xcode

Install Xcode.

Install Homebrew and Dependencies

Install Homebrew. From here you should be able to install:

  1. brew install go automake git curl wget mysql@5.7 etcd

Add mysql@5.7 to your PATH:

  1. echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

Do not setup MySQL or etcd to restart at login.

Install Docker

Running the testsuite requires that you install Docker. Should you decide to skip this step, you will still be able to compile and run Vitess.

Build Vitess

Navigate to the directory where you want to download the Vitess source code and clone the Vitess GitHub repo. After doing so, navigate to the src/vitess.io/vitess directory.

  1. mkdir -p ~/vitess
  2. cd ~/vitess
  3. git clone https://github.com/vitessio/vitess.git \
  4. src/vitess.io/vitess
  5. cd src/vitess.io/vitess

Set environment variables that Vitess will require. It is recommended to put these in your ~/.bash_profile file:

  1. # Vitess
  2. export VTROOT=~/vitess
  3. export VTTOP=~/vitess/src/vitess.io/vitess
  4. export VTDATAROOT=~/vitess/vtdataroot
  5. export PATH=${VTROOT}/bin:${PATH}

Run bootstrap.sh script to download additional dependencies. If your machine requires a proxy to access the Internet, you will need to set the usual environment variables (e.g. http_proxy, https_proxy, no_proxy):

  1. BUILD_PYTHON=0 BUILD_JAVA=0 ./bootstrap.sh

This should result in output similar to the following:

  1. morgans-mini:vitess morgo$ BUILD_PYTHON=0 BUILD_JAVA=0 ./bootstrap.sh
  2. creating git hooks
  3. installing protoc 3.6.1
  4. --2019-11-05 14:44:32-- https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-osx-x86_64.zip
  5. Resolving github.com (github.com)... 140.82.114.4
  6. Connecting to github.com (github.com)|140.82.114.4|:443... connected.
  7. HTTP request sent, awaiting response... 302 Found
  8. ...
  9. ...
  10. ...
  11. 2019-11-05 14:44:39 (20.1 MB/s) - consul_1.4.0_darwin_amd64.zip saved [34526567/34526567]
  12. Archive: consul_1.4.0_darwin_amd64.zip
  13. inflating: consul
  14. bootstrap finished - run 'source dev.env' or 'source build.env' in your shell before building.

Build Vitess:

  1. source ./dev.env
  2. make build

Testing your Binaries

Run the included local example:

  1. cd examples/local
  2. ./101_initial_cluster.sh

You should see the following:

  1. $ ./101_initial_cluster.sh
  2. morgans-mini:local morgo$ ./101_initial_cluster.sh
  3. enter etcd2 env
  4. add /vitess/global
  5. add /vitess/zone1
  6. add zone1 CellInfo
  7. Error: client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint
  8. Error: client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint
  9. etcd start done...
  10. enter etcd2 env
  11. Starting vtctld...
  12. Access vtctld web UI at http://morgans-mini.lan:15000
  13. Send commands with: vtctlclient -server morgans-mini.lan:15999 ...
  14. enter etcd2 env
  15. Starting MySQL for tablet zone1-0000000100...
  16. Starting MySQL for tablet zone1-0000000101...
  17. Starting MySQL for tablet zone1-0000000102...
  18. Starting vttablet for zone1-0000000100...
  19. Access tablet zone1-0000000100 at http://morgans-mini.lan:15100/debug/status
  20. Starting vttablet for zone1-0000000101...
  21. Access tablet zone1-0000000101 at http://morgans-mini.lan:15101/debug/status
  22. Starting vttablet for zone1-0000000102...
  23. Access tablet zone1-0000000102 at http://morgans-mini.lan:15102/debug/status
  24. W1027 20:11:49.555831 35859 main.go:64] W1028 02:11:49.555179 reparent.go:182] master-elect tablet zone1-0000000100 is not the shard master, proceeding anyway as -force was used
  25. W1027 20:11:49.556456 35859 main.go:64] W1028 02:11:49.556135 reparent.go:188] master-elect tablet zone1-0000000100 is not a master in the shard, proceeding anyway as -force was used
  26. New VSchema object:
  27. {
  28. "tables": {
  29. "corder": {
  30. },
  31. "customer": {
  32. },
  33. "product": {
  34. }
  35. }
  36. }
  37. If this is not what you expected, check the input data (as JSON parsing will skip unexpected fields).
  38. enter etcd2 env
  39. Access vtgate at http://morgans-mini.lan:15001/debug/status

You can continue the remaining parts of this example by following the local get started guide.

Full testsuite

To run the testsuite in Docker:

  1. make docker_test flavor=mysql57

Running the full suite currently takes 2+ hours to complete.

Common Build Issues

Key Already Exists

This error is because etcd was not cleaned up from the previous run of the example. You can manually fix this by running ./401_teardown.sh and then start again:

  1. Error: 105: Key already exists (/vitess/zone1) [6]
  2. Error: 105: Key already exists (/vitess/global) [6]

Python Errors

The end-to-end test suite currently requires Python 2.7. We are working on removing this dependency, but in the mean time you can run tests from within Docker. The MySQL 5.7 container provided includes the required dependencies:

  1. make docker_test flavor=mysql57

No .installed_version file

This error indicates that you have not put the required vitess environment variables in your .bashrc file:

  1. enter etcd2 env
  2. cat: /dist/etcd/.installed_version: No such file or directory

Make sure the following variables are defined:

  1. export VTROOT=~/vitess
  2. export VTTOP=~/vitess/src/vitess.io/vitess
  3. export VTDATAROOT=~/vitess/vtdataroot
  4. export PATH=${VTROOT}/bin:${PATH}

Cannot create dir /etcd

This indicates that the environment variable VTDATAROOT is not defined, and you have not put the required vitess environment variables in your .bashrc file:

  1. ./101_initial_cluster.sh
  2. enter etcd2 env
  3. mkdir: cannot create directory ‘/etcd’: Permission denied

Make sure the following variables are defined:

  1. export VTROOT=~/vitess
  2. export VTTOP=~/vitess/src/vitess.io/vitess
  3. export VTDATAROOT=~/vitess/vtdataroot
  4. export PATH=${VTROOT}/bin:${PATH}