Monday, December 17, 2018

Docker 12 Factors Methodology Step 00 Application NodeJS Debian REST api



root@educacion:/home/educacion/src/docker12factor# apt install dirmngr

root@educacion:/home/educacion/src/docker12factor# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

root@educacion:/home/educacion/src/docker12factor# echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list

root@educacion:/home/educacion/src/docker12factor# apt update -y

root@educacion:/home/educacion/src/docker12factor# apt install -y mongodb-org

root@educacion:/home/educacion/src/docker12factor# service mongod status

root@educacion:/home/educacion/src/docker12factor# service mongod start

root@educacion:/home/educacion/src/docker12factor# mongo

> help;
> exit;

educacion@educacion:~/src/docker12factor$ npm init

educacion@educacion:~/src/docker12factor$ npm get prefix
/usr
educacion@educacion:~/src/docker12factor$ npm set prefix /usr/local
educacion@educacion:~/src/docker12factor$ npm get prefix 
/usr/local

educacion@educacion:~/src/docker12factor$ npm install sails -g

educacion@educacion:~/src/docker12factor$ sails new messageApp
 Choose a template for your new Sails app:
 1. Web App  ·  Extensible project with auth, login, & password recovery
 2. Empty    ·  An empty Sails app, yours to configure
 (type "?" for help, or  to cancel)
? 2

educacion@educacion:~/src/docker12factor$ cd messageApp

educacion@educacion:~/src/docker12factor$ sails generate api message

educacion@educacion:~/src/docker12factor$ sails lift


educacion@educacion:~/src/docker12factor/messageApp$ curl --header "Content-Type: application/json"   --request POST   --data '"text":"Hello Javascript FullStack DevOps"}'   http://localhost:1337/message

educacion@educacion:~/src/docker12factor/messageApp$ curl --header "Content-Type: application/json"   --request POST   --data '"text":"Hola Javascript FullStack DevOps"}'   http://localhost:1337/message

educacion@educacion:~/src/docker12factor/messageApp$ curl http://localhost:1337/message/
[
  {
    "text": "Hello Javascript FullStack DevOps",
    "createdAt": 1545061317524,
    "updatedAt": 1545061317524,
    "id": 1
  },
  {
    "text": "Hola Javascript FullStack DevOps",
    "createdAt": 1545061415586,
    "updatedAt": 1545061415586,
    "id": 2
  }
]


educacion@educacion:~/src/docker12factor/messageApp$ curl --header "Content-Type: application/json"   --request PUT  --data '{"ext":"Hello Javascript FullStack !! DevOps !!"}'   http://localhost:1337/message/2

educacion@educacion:~/src/docker12factor/messageApp$ curl http://localhost:1337/message/
[
  {
    "text": "Hello Javascript FullStack DevOps",
    "createdAt": 1545061317524,
    "updatedAt": 1545061317524,
    "id": 1
  },
  {
    "text": "Hello Javascript FullStack !! DevOps !!",
    "createdAt": 1545061415586,
    "updatedAt": 1545065865167,
    "id": 2
  }
]


educacion@educacion:~/src/docker12factor/messageApp$ curl   --request DELETE   http://localhost:1337/message/1

educacion@educacion:~/src/docker12factor/messageApp$ curl http://localhost:1337/message/
[
  {
    "text": "Hello Javascript FullStack !! DevOps !!",
    "createdAt": 1545061415586,
    "updatedAt": 1545065865167,
    "id": 2
  }
]


Reference: 
https://github.com/docker/labs/blob/master/12factor/00_application.md
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/

No comments: