Skip to content

Build for Development

Jon edited this page Mar 26, 2022 · 5 revisions

This is a getting started guide for building locally for development and local test. See building for deployment for creating docker images of the services for deployment.

Install Tools

The following tools can be installed by running the commands below for your operating system.

  • Protoc is used to generate code for etcd, grpc, and our own project
  • gcc. Some libraries use cgo so this is required. Macos will have it already installed.
  • Etcd. Needed for local unit and e2e tests.
  • Redis. Needed for local unit and e2e tests (last tested with version 6.2.4)
  • InfluxDB. Needed for local unit and e2e tests (version: 1.7.6).
  • PostgresSQL. Needed for local unit and e2e tests.
  • Hashicorp Vault for secrets management, for local unit and e2e tests (NOTE: make sure the version is >= v1.1.0).

Macos using brew

brew install protobuf etcd redis influxdb postgres vault jq
brew upgrade postgres # fixes issues with initdb on version 10.5 not working

Ubuntu

sudo apt install protobuf-compiler gcc pkg-config etcd postgresql jq
# vault
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install vault
# redis 2.6.4 for unit tests
wget https://download.redis.io/releases/redis-6.2.4.tar.gz
tar xpf redis-6.2.4.tar.gz
(cd redis; make; sudo make install)
# influxdb version 1.7.6 for unit-tests
wget https://dl.influxdata.com/influxdb/releases/influxdb_1.7.6_amd64.deb
sudo dpkg -i influxdb_1.7.6_amd64.deb
# helm (for KIND tests)
wget https://get.helm.sh/helm-v3.5.4-linux-amd64.tar.gz
tar xvpf helm-v3.5.4-linux-amd64.tar.gz
sudo cp linux-amd64/helm /usr/local/bin/helm
# ipset for KIND tests
sudo apt-get install ipset -y

On Macos, pg_ctl is on path, but not on Ubuntu. Make sure it's on the path. On Ubuntu we should switch to pg_ctlcluster, but that's not part of the Macos brew package.

ls /usr/lib/postgresql/<version>/bin
# add PATH=${PATH}:/usr/lib/postgresql/<version>/bin to .profile or .bashrc or .zsh
# fix perms on /var/run/postgresql, needs to be done every reboot
sudo mkdir /var/run/postgresql
sudo chmod a+rw /var/run/postgresql

Extra

  • For local Chef testing:
    • Install chef workstation from https://downloads.chef.io/chef-workstation
      • Chef Workstation installs to /opt/chef-workstation/ on macOS / Linux and C:\opscode\chef-workstation\ on Windows
      • Make sure above path is accessible by non-root user, otherwise you'll see failures like:
        • Bundler::SudoNotPermittedError
    • After chef is installed, Install ruby and chef-zero using
      • ensure ~/.chefdk/gem/ruby/2.7.0/bin is in your PATH:
        • export PATH=$PATH:$HOME/.chefdk/gem/ruby/2.6.0/bin
      • chef gem install chef-zero

In case you have any issues with an existing brew package, it's probably a good idea to reinstall it rather than uninstalling it and installing it again as it will reinstall the existing version.

For example: "brew reinstall postgres"

Set up source dir and GOPATH

Go only has one workspace, and it is typically at ~/go/src.

mkdir -p ~/go/src/github.com/mobiledgex/

If needed, add the following to ~/.bash_profile (create it if it doesn't exist) for bash shell users. If you're using zsh, add it to ~/.zshrc instead. If you're using a different shell, you'll have to figure out which shell config file to add it to. You can check which shell you're using by echo $SHELL.

export GOROOT=/usr/local/go
export GOPATH=~/go
export PATH=$PATH:$GOROOT/bin
export PATH=$PATH:$GOPATH/bin
export GO111MODULE=on

Open up a new terminal window for the exports to take effect. Check the value of your PATH variable in new terminal window by typing 'echo $PATH'. Both /usr/local/go/bin and ~/go/bin should be in your $PATH variable.

Install go-swagger for MC API docs generation:

go get -u github.com/go-swagger/go-swagger/cmd/swagger

Github setup, if not done already

Create a ~/.gitconfig file:

[user]
    name = FirstName LastName
    email = firstname.lastname@mobiledgex.com
[core]
    editor = nano

Check out Code

The following retrieves the source code and updates the vendor dependencies.

Note that for our forked version of grpc-gateway, we clone it under it's original unforked path. This allows all the absolute import paths in the code to remain valid.

mkdir -p ~/go/src/github.com/grpc-ecosystem
cd ~/go/src/github.com/grpc-ecosystem
git clone https://github.com/mobiledgex/grpc-gateway.git
cd ~/go/src/github.com/mobiledgex/
git clone https://github.com/mobiledgex/edge-proto.git
git clone https://github.com/mobiledgex/edge-cloud.git
git clone https://github.com/mobiledgex/edge-cloud-infra.git
cd edge-cloud
GO111MODULE=on go mod download
make tools
cd ../edge-cloud-infra

Building the code (from edge-cloud-infra dir):

make

Running unit tests (from edge-cloud dir or edge-cloud-infra dir):

make unit-test

Running e2e tests (from edge-cloud dir or edge-cloud-infra dir - not that infra will run edge-cloud's e2e tests as well)

make test (or make test-debug to stop on error)

Clone this wiki locally