Monday, December 17, 2018

Docker 12 Factor Methodology Step 01 Codebase Repository git


$ git clone https://bitbucket.org/maximilianou/messageapp

educacion@educacion:~/src/docker12factor/messageapp$ git status

educacion@educacion:~/src/docker12factor/messageapp$ git add .

educacion@educacion:~/src/docker12factor/messageapp$ git commit -m 'first commit'

educacion@educacion:~/src/docker12factor/messageapp$ git push origin master



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/

Tuesday, December 4, 2018

docker nodejs IDE visual studio 2018


educacion@educacion:~/src/docker02$ cat Dockerfile 
FROM node
WORKDIR /code
RUN npm install -g nodemon
COPY package.json /code/package.json
RUN npm install && npm ls
RUN mv /code/node_modules /node_modules
COPY . /code
CMD ["npm", "start"]


educacion@educacion:~/src/docker02$ cat  docker-compose.yml 
version: "2"
services:
  web:
    build: .
    command: nodemon -L --inspect=0.0.0.0:5858
    volumes:
      - .:/code
    ports:
      - "8000:8000"
      - "5858:5858"


educacion@educacion:~/src/docker02$ cat package.json 
{
    "main": "app.js",
    "dependencies": {
        "express": "~4.14.0",
        "express-handlebars": "~3.0.0"
    }
}


educacion@educacion:~/src/docker02$ cat app.js
const express = require('express');
const expressHandlebars = require('express-handlebars');
const http = require('http');
const PORT = 8000;
const LINES = [
    "One thing at the time.",
    "Start from the beginning!",
    "Up to date!",
    "As Simple As Possible",
];
let lineIndex = 0;
const app = express();
app.engine('html', expressHandlebars());
app.set('view engine', 'html');
app.set('views', __dirname);
app.get('/', (req, res) => {
    let message = LINES[lineIndex];
    lineIndex += 1;
    if (lineIndex >= LINES.length) {
        lineIndex = 0;
    }
    res.render('index', {message: message});
});
http.Server(app).listen(PORT, () => {
    console.log("HTTP server listening on port %s", PORT);
});



educacion@educacion:~/src/docker02$ cat index.html
< !doctype html>
< html>
    < head>
        < meta http-equiv="refresh" content="2">
        < style type="text/css">
            .sample_docker_nodejs {
                font-family: Helvetica, Arial, sans-serif;
                font-weight: 600;
                font-size: 56pt;
                text-transform: uppercase;
                text-align: center;
                background: #3c3;
                color: white;
            }
        < /style>
    < /head>
    < body class='sample_docker_nodejs'>“{{message}}”
< /html>


root@educacion:/home/educacion# apt install libgconf-2-4 desktop-file-utils 
mime-support gconf2-common gconf-service


educacion@educacion:~/src/docker02$ docker-compose up
Creating network "docker02_default" with the default driver
Building web
Step 1/8 : FROM node
 ---> e6825fa3bd20
Step 2/8 : WORKDIR /code
 ---> Running in 7f475c6a9926
Removing intermediate container 7f475c6a9926
 ---> 325c768f008c
Step 3/8 : RUN npm install -g nodemon
 ---> Running in 37c3e446896d
/usr/local/bin/nodemon -> /usr/local/lib/node_modules/nodemon/bin/nodemon.js

> nodemon@1.18.7 postinstall /usr/local/lib/node_modules/nodemon
> node bin/postinstall || exit 0

Love nodemon? You can now support the project via the open collective:
 > https://opencollective.com/nodemon/donate

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 
(node_modules/nodemon/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform 
for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} 
(current: {"os":"linux","arch":"x64"})

+ nodemon@1.18.7
added 223 packages from 130 contributors in 291.478s
Removing intermediate container 37c3e446896d
 ---> a7a86d38c2a1
Step 4/8 : COPY package.json /code/package.json
 ---> 80630e53397b
Step 5/8 : RUN npm install && npm ls
 ---> Running in c7347533b05c
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN code No description
npm WARN code No repository field.
npm WARN code No license field.

added 70 packages from 80 contributors in 474.487s
/code
+-- express@4.14.1
| +-- accepts@1.3.5
| | +-- mime-types@2.1.21
..........................

Removing intermediate container c7347533b05c
 ---> 5d15000e4998
Step 6/8 : RUN mv /code/node_modules /node_modules
 ---> Running in e7368c6b5409
Removing intermediate container e7368c6b5409
 ---> c80d1a0c6d8a
Step 7/8 : COPY . /code
 ---> 69f216de5856
Step 8/8 : CMD ["npm", "start"]
 ---> Running in 220eb2ed498c
Removing intermediate container 220eb2ed498c
 ---> 9ce32b100e72
Successfully built 9ce32b100e72
Successfully tagged docker02_web:latest
WARNING: Image for service web was built because it did not already exist. To rebuild this image 
you must use `docker-compose build` or `docker-compose up --build`.
Creating docker02_web_1
Attaching to docker02_web_1
web_1  | [nodemon] 1.18.7
web_1  | [nodemon] to restart at any time, enter `rs`
web_1  | [nodemon] watching: *.*
web_1  | [nodemon] starting `node --inspect=0.0.0.0:5858 app.js`
web_1  | Debugger listening on ws://0.0.0.0:5858/08100114-cd8e-4e44-be6f-855309ffa8b6
web_1  | For help, see: https://nodejs.org/en/docs/inspector
web_1  | HTTP server listening on port 8000


http://localhost:8000/

 * Edit with VSCode in realtime!


 * Connect with a container in runtime!

educacion@educacion:~/src/docker02$ docker exec -i -t docker02_web_1 /bin/bash

Reference:
https://github.com/elPoeta/docker-nodejs-postgres-example
https://github.com/docker/labs/blob/master/developer-tools/README.md
https://code.visualstudio.com/
https://github.com/docker/labs/blob/master/developer-tools/nodejs-debugging/VSCode-README.md


Thursday, November 29, 2018

docker install debian stretch 2018


root@educacion:~# apt update

root@educacion:~# apt install \
     apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     software-properties-common

root@educacion:~# curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -

root@educacion:~# apt-key fingerprint 0EBFCD88

root@educacion:~# add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"

root@educacion:~# apt update

root@educacion:~# apt upgrade

root@educacion:~# apt install docker-ce

root@educacion:~# docker run hello-world

-( root@educacion:~# apt install docker-compose ) # OLD release of docker-compose, we must install from git repo
-( root@educacion:~# apt remove docker-compose )

root@educacion:~# usermod -aG docker educacion

root@educacion:~# usermod -aG staff educacion

educacion@educacion:~$ curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

educacion@educacion:~$ chmod +x /usr/local/bin/docker-compose

educacion@educacion:~$ docker-compose --version


educacion@educacion:~$ docker run hello-world


root@educacion:/etc/docker# cat daemon.json 
{
"log-driver": "json-file",
"log-opts": {
    "max-size": "5m",    
    "max-file": "3"    
    }
} 


version: '3.2'
services:
  nginx:
    image: 'nginx:latest'
    ports:
      - '80:80'
    logging:
      driver: "json-file"
      options:
        max-size: "1m"
        max-file: "3"

Reference:
https://gist.github.com/elPoeta/2e0490f61b978da0379f26fec91695e5
https://www.docker.com/

Monday, August 14, 2017

install debian 9 pendrive java web sql nginx jetty9 phpmyadmin mariadb mercurial git, agosto 2017



Infraestructura de Desarrollo en un pedrive, portable, economico ( the cheap way )



1. Pendrive de 16gb espacio, 100Mbps velocidad de transferencia.

2. Bajar con torrent, es mucho mas rapido, y menos carga para los servidores que nos proveen estas facilidades

https://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/current-live/amd64/bt-hybrid/debian-live-9.1.0-amd64-lxde+nonfree.iso.torrent

3. Con la .iso o .img se puede llevar el instalador a un pendrive de al menos 4gb de espacio.

https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/bsdinstall-pre.html

# dd if=FreeBSD-10.2-RELEASE-amd64-memstick.img of=/dev/da0 bs=1M conv=sync
 En este caso con el debian queda algo asi:

#dd if=firmware-9.0.0-amd64-DVD-1.iso of=/dev/sdb bs=512; sync;

4. Una vez que booteamos de este pendrive,
F12: en algunas maquinas con alternative boot del F12
ESC: otras maquinas

Pero a partir de UEFI,
en mi caso particular, en las  5 o 7 tipos de maquinas distintas que probe,
portatiles y de escritorio,
necesite entrar a la BIOS
y cambiar a UEFI and Legacy

( es muy probable que encuentre la forma de no modificar el UEFI, en algun momento, por algo esta )

5. Para empezar, perfiero dejar todo eun una sola particion, en el disco pendrive de 16gb
     Ojo NO en la opcion disco mas grande
     Sino en la opcion disco completo y poder seleccionar el de 16gb

6. Cuando logramos bootear el linux, instalador es practicamente intuitivo.
 - Yo prefiero instalarlo todo por defecto,
     excepto que
     prefiero LXDE,
     sin impresora
     y con ssh

7. Permito instalar el Grub, y listo, a rebootear.

8. Una vez que booteo con el sistema nuevo instalado
    Verifico tener internet

    $ip addr 

    me dara si detecto las placas de red eth y wifi
    y si tiene asignada una ip

9. edito el archivo de configuracion

/etc/apt/source.list

 deb http://security.debian.org/debian-security stretch/updates main contrib non-free
 deb http://deb.debian.org/debian/ stretch main contrib non-free
 deb http://deb.debian.org/debian/ stretch-updates main contrib non-free
 deb http://deb.debian.org/debian/ stretch-backports main contrib non-free

10. Actualizo la lista de soft disponible

 # apt -y update; apt -y upgrade; sync;

11. Instalo el soft base para desarrollo, tomando en cuenta programar de forma simple para alumnos que recien comienzan:

#apt -y install openjdk-8-jdk mercurial git medit chromium mariadb-client mariadb-server php-fpm phpmyadmin nginx jetty9

12. Configuro el Mysql

# mysql -u root -e " CREATE USER 'educacion'@'%' IDENTIFIED BY 'educacion'; GRANT ALL PRIVILEGES ON *.* TO 'educacion'@'%' WITH GRANT OPTION;"

13. Configuro el phpmyadmin

#vi /etc/nginx/sites-available/default



# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}

14. Link Simbolico de phpmyadmin en el directorio donde levanta la web el Nginx

#ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin



15. Restarteo el Nginx

#systemctl restart nginx

16. Verifico

http://localhost/phpmyadmin

17. Busco el NetBeans  

https://netbeans.org/downloads/

Instalo la version con Apache Tomcat, no utilizo el Glassfish porque es muy pesado, para desarrollo en un pendrive. ( tomando en cuenta que las maquinas en las que a veces trabajo tienen poca potencia, otras no )




18. Ajuste de la version, que algun bug puede tener: Hay que Comentar una linea ( con el caracter # )

/usr/lib/jvm/default-java/jre/lib/accessibility.properties

#assistive_technologies=org.GNOME.Accessibility.AtkWrapper



Friday, September 2, 2011