-
Notifications
You must be signed in to change notification settings - Fork 5
Build for Development
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 go:
- golang 1.15.2 (switch to 1.17.6 on 2/2/2022 is postponed).
- Install Docker:
- 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).
- Make sure installed version is 1.7.6. If it is not, then uninstall it and install it from this tar pkg on Macos:
https://dl.influxdata.com/influxdb/releases/influxdb-1.7.6_darwin_amd64.tar.gz
- brew uninstall influxdb (Macos)
- Download above tar ball & Untar it
- Copy influxd binary to /usr/local/bin/
- Make sure installed version is 1.7.6. If it is not, then uninstall it and install it from this tar pkg on Macos:
https://dl.influxdata.com/influxdb/releases/influxdb-1.7.6_darwin_amd64.tar.gz
- 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).
- Install brew (mac osx tool to install other tools) (reference: https://brew.sh/):
- /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install protobuf etcd redis influxdb postgres vault jq
brew upgrade postgres # fixes issues with initdb on version 10.5 not working
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
- 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
- ensure ~/.chefdk/gem/ruby/2.7.0/bin is in your PATH:
- Install chef workstation from https://downloads.chef.io/chef-workstation
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"
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
Create a ~/.gitconfig file:
[user]
name = FirstName LastName
email = firstname.lastname@mobiledgex.com
[core]
editor = nano
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)