Star

Nebula Graph 2.0 Compilation on MacOS+Docker

Nebula Graph 2.0 Compilation on MacOS+Docker

This tutorial will walk you through all steps from setting up the development environment to compiling and running Nebula Graph 2.0 in Docker container on MacOS.

Overview

Nebula Graph has provided a docker image with the whole compiling environment vesoft/nebula-dev, which will make it possible to change source code locally, build and debug within the container.

Requirements

The following are the configuration requirements for compiling Nebula Graph 2.0. For the configuration requirements of the running environment, see here.

  • CPU: x86_64

  • Memory: 4GB at least

  • Disk space: 10GB at least

  • Is able to run Docker

  • Access to the Internet

Build Nebula Graph 2.0

This section will guide the user to set up everything needed to start Nebula Graph database service.

Download the Source Code to Your Local Directory

  1. Open temiminal and head to the directory where the source code will be stored

  2. Clone the source code using:

bash> git clone [https://github.com/vesoft-inc/nebula-graph.git](https://github.com/vesoft-inc/nebula-graph.git)

Pull Image From Docker Hub

bash> docker pull vesoft/nebula-dev

Run Docker Container

Run Docker container and mount your local source code directory into the container working_dir /home/nebula with the following commands:


bash> docker run -ti \

--security-opt seccomp=unconfined \

-v /path/to/nebula/directory:/home/nebula \

-w /home/nebula \

vesoft/nebula-dev \

bash

Note: To automatically release disk space held by containers when they exit, add --rm flag:


bash> docker run --rm -ti \

--security-opt seccomp=unconfined \

-v /path/to/nebula/directory:/home/nebula \

-w /home/nebula \

vesoft/nebula-dev \

bash

Replace /path/to/nebula/directory with your local Nebula Graph source code directory.

Compiling Within the Container

  1. docker> mkdir build && cd build

  2. docker> cmake -DENABLE_BUILD_STORAGE=on -DCMAKE_EXPORT_COMPILE_COMMANDS=on ..

  3. To reduce the time of building in the unit tests, storage building is off by default since storage remains unchanged in the unit tests.

  4. The default installation path is /user/local/nebula, if you are using ssh and do not have the root access, an error message will be printed.image

  5. To change the install path, use:

docker> cmake -DCMAKE_INSTALL_PREFIX=user_install_path -DENABLE_BUILD_STORAGE=on -DCMAKE_EXPORT_COMPILE_COMMANDS=on .. Replace user_install_path with your local Nebula Graph source code directory.

  1. docker> make -jN#

note: Assuming cores is the number of cores and mem_gb is the memory size (in GB), the value of N is recommended to select the smaller one from cores and mem_gb / 2


# Assuming cores is the number of cores and mem_gb is the memory size (in GB), the value of N is recommended to select the smaller one from cores and mem_gb / 2

# We suggest choosing release build type to speed up compilation#


Tip: It is possible to encounter the error below if the resources allocated to Docker is not sufficient enough

To prevent the error showing above, You may change the setting in docker->Preferences->Resources to adjust the CPU and memory setting. In this example, I am using 4 CPUs with 6GB memory

  1. docker> make install-all

Run Nebula Graph Service

  1. Once the preceding installation is completed, you can run Nebula Graph service within the container, the default installation directory is /usr/local/nebula/

docker> cd /usr/local/nebula

  1. Rename config files of Nebula Graph service.

docker> cp etc/nebula-graphd.conf.default etc/nebula-graphd.conf

docker> cp etc/nebula-metad.conf.default etc/nebula-metad.conf

docker> cp etc/nebula-storaged.conf.default etc/nebula-storaged.conf

  1. Start service.

docker> ./scripts/nebula.service start all
Below message indicates the Nebula service has been lauched successfully

Run Nebula Graph 2.0

This section will go through the process of installing the required tools in docker to connect the console to Nebula Graph services.


IMPORTANT: Make sure Nebula Graph services are started.

Install Go in Docker

  1. Switch to the directoy you would like Go to be installed in. docker> cd

  2. Go to https://golang.org/doc/install and right click on Download Go for Linux, select Copy Link Addressimage

  3. docker> wget LINK_ADDRESS Replace LINK_ADDRESS with the link copied in step 2.

  4. Extract the archive into /usr/local, creating a Go tree in /usr/local/go.

    For example, run the following as root or through sudo:
    tar -C /usr/local -xzf go1.15.2.linux-amd64.tar.gz

  5. Add /usr/local/go/bin to the PATH environment variable.You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):

    export PATH=$PATH:/usr/local/go/bin`
    
  6. Note: Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source $HOME/.profile.

  7. Verify that you’ve installed Go by opening a command prompt and typing the following command:

    $ go version

  8. Confirm that the command prints the installed version of Go.

Install Nebula Graph Console

Full document:https://github.com/vesoft-inc/nebula-console

  1. Install golang by https://golang.org/doc/install,

  2. Clone source code at https://github.com/vesoft-inc/nebula-console to the docker directory, and build with following commands:


docker> cd nebula-console

docker> make

  1. Start the console:

docker> ./nebula-console [-address ip] [-port port] [-u user] [-p password] [-e "nGQL query statement" | -f file.nGQL]

# default setting

# user and password are optional

docker> ./nebula-console -u root -p nebula --port 3699 --addr="127.0.0.1"

A welcome message is expected:


Welcome to Nebula Graph v2.0.0-alpha!


-h : help

-address : the Nebula Graph IP address, default value is 127.0.0.1

-port : the Nebula Graph Port, default value is 3699

-u : the Nebula Graph login user name, default value is user

-p : the Nebula Graph login password, default value is password

-e : the nGQL directly

-f : the nGQL script file name

Check options for ./nebula-console -h , try ./nebula-console in interactive mode directly. And try ./nebula-console -e 'show hosts' for the direct script mode. And try ./nebula-console -f demo.nGQL for the script file mode.


For more details, check https://github.com/vesoft-inc/nebula-console


Remote Container Using VS Code

This chapter will introduce how to remote control the container using VS Code to view/edit files with VS Code.

  1. Install Docker extension in VS Code

    a. On Linux, you should also enable Docker CLI for the non-root user account that will be used to run VS Code.

    b. To install the extension, open the Extensions view (⇧⌘X), search for docker to filter results and select Docker extension authored by Microsoft.

    image

  2. Attach VS Code to the container

  3. Open VS Code, click the docker icon on the sidebar, then right-click on the container, select “Attach Visual Studio Code”
    image

  4. VS Code explorer will automatically load the Nebula directoryimage

  5. Happy coding with VS Code!


More details avaliable at https://code.visualstudio.com/docs/containers/overview.




Ref:
GO Download and install https://golang.org/doc/install
Working with containers https://code.visualstudio.com/docs/containers/overview

3 Likes