Skip to content

Build and Deploy instructions

Aarti edited this page Jun 3, 2020 · 10 revisions

Create AWS instance

  1. Create an AWS instance. For this, go to the AWS console
  2. Go to EC2
  3. Running instances > launch instances
  4. In the search box, "Ubuntu Server 18.04 LTS (HVM), SS Volume Type"
  5. Select t2.medium (the management cluster needs to be big enough, anything smaller than this didn't work at the time of doing this). Click on Next
  6. Add Storage, and then go to Add tag button
  7. Add "key name" as Name and "cloud_test" as Value
  8. Click on configure security group
  9. Select all default security groups by clicking on all the checkboxes
  10. Click on launch
  11. From the dropdown select "Create a new pair"
  12. Select key pair name as "cloud_test"
  13. Click download key pair(use this key to ssh into the instance). Save it in ~/
  14. Click on launch instance.
  15. Finally, use the "IPv4 Public IP" to ssh into the instance.

ssh into the AWS EC2 instance

  1. On the AWS console, go to EC2 instances
  2. For the EC2 instance that you created, copy the IPv4 public address
  3. on your terminal, ssh -i <pem_file_created_above> ubuntu@<ip_adress from step2>

Install docker and k8s

sudo su
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.8.0/kind-$(uname)-amd64"
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
kind version

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
apt-cache policy docker-ce
sudo apt-get install -y docker-ce

kind create cluster
kubectl cluster-info --context kind-kind

Create required directories

assuming you are still in your cloud instance

cd /home/ubuntu
mkdir -p /home/ubuntu/cloud/kubernetes
mkdir -p /home/ubuntu/cloud/bin

apt-get update
apt install make

Install Go

Please note that the working directory("work" in the example below) should be an empty directory.

sudo su
curl -O https://dl.google.com/go/go1.14.3.linux-amd64.tar.gz
tar xvf go1.14.3.linux-amd64.tar.gz
sudo chown -R root:root ./go
sudo mv go /usr/local
mkdir -p $HOME/work
export GOPATH=$HOME/work
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
mkdir -p $HOME/work/src
cd $HOME/work/src

build the project

You should be in $HOME/work/src directory

git clone https://github.com/AartiJivrajani/All-On-Cloud-9.git
cd All-On-Cloud-9
export GO111MODULE=on
go mod tidy
export INSTANCE=<ip_address_of EC2 instance>
make deploy-local //ensure your pem file is present in ~/

Build docker and k8s artefacts

cd /home/ubuntu/cloud

docker build -t aartij17/cloud:nats -f Dockerfile.nats --no-cache .
docker build -t aartij17/server:v1 -f Dockerfile.server --build-arg basedir=. --no-cache  .
docker build -t aartij17/orderer:v1 -f Dockerfile.orderer --build-arg basedir=. --no-cache  .
kind load docker-image aartij17/orderer:v1
kind load docker-image aartij17/server:v1
kind load docker-image aartij17/cloud:nats

cd kubernetes
kubectl create -f .

// now check if all the pods are running
kubectl get pods -w (all the pods should be in running state)

Invoke APIs

fetch the node IP address

kubectl describe node | grep Internal | cut -f 2 -d : | sed 's/^ *//g'

Invoke APIs

curl -X POST \
  http://<node_IP>:30085/app/manufacturer \
  -H 'Content-Type: application/json' \
  --data-raw '{
	"num_units_to_sell":10,
	"amount_to_be_collected":50,
	"transaction_type": "LOCAL_TXN"
}'

kubectl get pods | grep manufacturer1
copy the name of the pod that you see
kubectl logs -f <pod_name>
You should be able to see logs such as these: 
**********************************************************************************************
WARNING[0082] [Node], [Outgoing edges], [Incoming Edges]
WARNING[0082] {[XXX] [] [LOCAL-MANUFACTURER-11]}
WARNING[0082] {[LOCAL-MANUFACTURER-11] [XXX] []}
**********************************************************************************************

Repeat again for the below API(local supplier transaction)
curl -X POST \
  http://<node_IP>:30086/app/supplier \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
	"to_application":"SUPPLIER",
	"num_units_to_buy":20,
	"amount_paid":102,
	"shipping_service": "FEDEX",
	"shipping_cost": 2, 
	"transaction_type": "LOCAL_TXN"
}'