Usage

Requisites

Installation

Keep in mind that the environment generated is only for development and demos, not for production.

Clone this repo:

export MICROBASE_HOME=~/micro
mkdir $MICROBASE_HOME
cd $MICROBASE_HOME
git clone https://bitbucket.org/thinkwrap/microbase.git

Create the private NPM repository environment variables (here)

export NPM_REGISTRY_URL=https://npm-proxy.fury.io/ncornag/
export NPM_TOKEN=...

Option 1: running the stack in "production" mode from docker hub

Run the docker containers from the images on docker hub.

Please be sure that docker has full access to the $MICROBASE_HOME folder.

cd $MICROBASE_HOME/microbase/ecomm/etc/setup
docker-compose -f $MICROBASE_HOME/microbase/ecomm/etc/dc/docker-compose.yml up -d

Option 2: running the stack in "production" mode, building from the source

Download the ecomm repos into $MICROBASE_HOME, build the images and run the docker containers from those images.

Please be sure that docker has full access to the $MICROBASE_HOME folder.

cd $MICROBASE_HOME/microbase/ecomm/etc/setup
./pullFromRepo.sh $MICROBASE_HOME/ecomm
./buildDockerImages.sh $MICROBASE_HOME/ecomm develop
docker-compose -f $MICROBASE_HOME/microbase/ecomm/etc/dc/docker-compose.yml up -d

Option 3: running the stack in "development" mode

Download the ecomm repos into $MICROBASE_HOME, build the images and run the docker containers mounting the source code folders, allowing the detection of code changes and automatically restarting the service.

Please be sure that docker has full access to the $MICROBASE_HOME folder.

cd $MICROBASE_HOME/microbase/ecomm/etc/setup
./pullFromRepo.sh $MICROBASE_HOME/ecomm
docker-compose -f $MICROBASE_HOME/microbase/ecomm/etc/dc/docker-compose-dev.yml up -d --build

Access

On both cases you could access the consul server at:

http://localhost:8501

The gateway UI at:

http://localhost:8080

and the api service at:

http://localhost:80

Test

Test the installation using curl:

curl --request POST \
  --url http://localhost:80/services/catalog/v1/category \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL21pY3JvYmFzZS5pbyIsInN1YiI6ImNsaWVudC9pbnRlcm5hbCIsInNjb3BlIjpbIklOVEVSTkFMIl0sImp0aSI6IjgyM2Y1MjY2LWEzYjEtNDkzNi1hMDk4LTc1Y2EzYzJlMmZmZSIsImlhdCI6MTQ5ODIwNTUwMX0.z3z2U_xTSSkLbB2e6WqV7ipidvGny7x6bZVm-mxMbU4' \
  --data '{"title": "Category 01", "description": "This is the Category 01", "slug": "category01", "parent": "ROOT"}'

The authorizarion header is based on the default security configuration. It should be changed in production.

Postman

API usage examples can be found in a Postman export file:

ls -l $MICROBASE_HOME/microbase/ecomm/etc/postman

Containers generated

The docker configuration starts several containers:

  • consul - The services registry. http://localhost:8501
  • gateway - The API endpoint. http://localhost:80
  • mongo - The database. mongo://localhost:27018
  • bus - RabbitMQ messaging. http://localhost:15673
  • elasticsearch - Search server. Logs aggregation server. http://localhost:9201
  • redis (optional) - Cache server. redis://localhost:6380
  • logstash (optional) - Logs redirection server. localhost:5000
  • kibana (optional) - Logs visualization server: http://localhost:5602/
  • *-service - All the microbase ecomm services, with no ports exposed.

Miscellaneous

Itermocil

If you use Itermocil, this configuration will allow you to easly open terminals with the services logs:

itermocil --edit micrologs

windows:
  - name: micro
    root: $MICROBASE_HOME
    layout: tiled
    panes:
      - docker logs -f micro-gateway
      - docker logs -f micro-oauth
      - docker logs -f micro-cart
      - docker logs -f micro-customer
      - docker logs -f micro-catalog
      - docker logs -f micro-payment
      - docker logs -f micro-promotion
      - docker logs -f micro-recommendation
      - docker logs -f micro-stock
      - docker logs -f micro-tax

Add this to your .bash_profile or .zshrc:

alias micrologs="itermocil --here micrologs"