Monday, June 8, 2020

How to get kubeconfig file from a k8s cluster running on IBMCloud

Once your k8s cluster is up running, follow the below steps to get kubeconfig file.


1. install ibmcloud CLI tools if you do not already have it
   curl -sL https://ibm.biz/idt-installer | bash

2. install ibmcloud CLI ks plugin
   ibmcloud plugin install kubernetes-service

3. login to the account
   ibmcloud login -a cloud.ibm.com -r us-south --sso
   -u <id@us.ibm.com> -p <password> -g Default

this step will ask you to get a one-time passcode by providing a url you can copy and paste the url to a browser to get one-time passcode to proceed. Once you provide the passcode, it will ask you to select an account to continue.

4. retrieve the kubeconfig file, the kubeconfig file should be saved at the current directory.
   ibmcloud ks cluster config --cluster <cluster-id>

Note:
* To check what plugins are available for CLI, run the following command
ibmcloud plugin repo-plugins -r 'IBM Cloud'

** The kubeconfig should normally reference a cert .pem file, when move this kubeconfig file to another environment, the referenced pem file should also be moved.

Monday, May 4, 2020

Resync with upstream git repo

To complete resynch with upstream repo, do the following:

1. git remote add upstream https://github.com/hyperledger-cicd/cello.git
2. git fetch upstream
3. git reset --hard upstream/master
4. git checkout master
5. git merge upstream/master
6. git push --force

Once this is done, your forked repo should be completely insynch with the upstream repo. the word upstream in this case is just a name for the upstream repo, it can be named any thing you like. If you are not using the word upstream, you will have to make sure that the following on commands using the correct upstream name.

Friday, May 1, 2020

Improve bash script with parameter

# parameter should be the component name such as api, dashboard or ansibleagent etc
api=("src/api-engine/"
     "build_image/docker/common/api-engine")
dashboard=("src/dashboard/"
     "build_image/docker/common/dashboard")
ansibleagent=("src/agent/ansible/"
     "build_image/docker/agent/ansible")


cdir=$(pwd)
cd ~/hl/src/github.com/realcello
allchanges=$(git diff --name-only HEAD~15 HEAD~20)
cd $cdir

echo "$allchanges"
hasTopChanges=$(echo "$allchanges" | grep -v '/')
if [ ! -z "$hasTopChanges" ]; then
  echo 'Has changes at the root, need to proceed'
  exit 0
fi

comp=$1
compItems="${comp}[@]"
changesFound='False'
echo 'Items in '${comp}
for item in "${!compItems}"; do
  echo "   checking $item"
  if echo "${allchanges}" | grep -q "$item"
  then
    changesFound='True'
  fi
done

if [ "$changesFound" == 'True' ]; then
  echo 'Need to proceed'
else
  echo "##vso[task.complete result=Succeeded;]No changes found!"
fi

Script to check if changes have happened under a particular directory

api=("src/api-engine/"
     "build_image/docker/common/api-engine")
dashboard=("src/dashboard/"
     "build_image/docker/common/dashboard")
ansibleagent=("src/agent/ansible/"
     "build_image/docker/agent/ansible")

allcomps=("api" "dashboard" "ansibleagent")
declare -A OPS

cdir=$(pwd)
cd ~/hl/src/github.com/realcello
allchanges=$(git diff --name-only HEAD~1 HEAD~10)
cd $cdir

echo "$allchanges"

for value in ${allcomps[@]}; do
  comps="${value}[@]"
  echo 'Items in '${value}
  for item in "${!comps}"; do
    echo "   checking $item"
    if echo "${allchanges}" | grep -q "$item"
    then
      OPS["${value}"]='true'
    fi
  done
done

for item in "${allcomps[@]}"; do
  echo "$item"="${OPS[$item]}"
done

Tuesday, March 17, 2020

The script to start and stop wordpress using docker

<code>
#!/bin/bash
netexist=$(docker network ls --format "{{.Name}}" -f "name=rccc")
if [[ $1 == "start" ]]; then
  if [[ -z $netexist ]]; then
    docker network create rccc
  fi
  docker run -d --name mysql --network rccc \
    -v $(pwd)/data:/var/lib/mysql \
    -e MYSQL_ROOT_PASSWORD=mysecret \
    -e MYSQL_DATABASE=wordpress \
    -e MYSQL_USER=tongli -e MYSQL_PASSWORD=secret \
    mysql:latest mysqld --default-authentication-plugin=mysql_native_password

  sleep 3

  while : ; do
    res=$(docker logs mysql 2>&1 | grep 'ready for connections')
      if [[ ! -z $res ]]; then
        break
      fi
      echo 'Waiting for mysql to be ready...'
      sleep 3
  done

  docker run -d --name rcccsite --network rccc \
    -v $(pwd)/content:/var/www/html \
    -e WORDPRESS_DB_HOST=mysql \
    -e WORDPRESS_DB_USER=tongli \
    -e WORDPRESS_DB_PASSWORD=secret \
    -e WORDPRESS_DB_NAME=wordpress \
    -p 8080:80 wordpress:latest

elif [[ $1 == "stop" ]]; then
  docker rm -f rcccsite mysql
  if [[ $netexist == "rccc" ]]; then
    docker network rm rccc
  fi
fi
</code>

Wednesday, March 11, 2020

IBM Blockchain Platform vscode extension wallet structure

File directory structure:

<root>/
    Admin/
        <hashcode>-priv
        <hashcode>-pub
        Admin -- this is a json file with the following structure
           {"name":"Admin",
             "mspid":"org0examplecom",
             "role": null, "affiliation": "",
             "enrollmentSecret": "",
             "enrollment": {
                  "signingIdentity": <hash, which used as the priv and pub name>,
                  "identity": {"certificate": "The plan new line contained certificate"}
             }
           }

Monday, March 9, 2020

New Go chaincode header import

import (
    "encoding/base64"
    "encoding/json"
    "fmt"
    "github.com/golang/protobuf/proto"
    "github.com/hyperledger/fabric-chaincode-go/shim"
    "github.com/hyperledger/fabric-protos-go/common"
    "github.com/hyperledger/fabric-protos-go/msp"
    pb "github.com/hyperledger/fabric-protos-go/peer"
    "math/rand"
    "time"
)