Mini “tuto” de acceso a Cloud Foundry a través de “vmc”
Voy a contar de manera muy escueta como accedo a un PaaS Cloud Foundry .
Instalaciones
He usado rvm para instalar vmc
Instalación rvm y vmc
Es necesario que el usuario haga uso de sudo . Para instalar:
1
2
3
4
5
6
7
8
9
10
11
imasd@corelia:~$ curl -#L https://get.rvm.io | bash -s stable --autolibs=3 --ruby
imasd@corelia:~$ source .bash_profile
imasd@corelia:~$ rvm list
rvm rubies
=* ruby-2.0.0-p0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
Una vez instalado rvm me creo un gemset especifico para albergar las utilidades.
1
2
imasd@corelia:~$ rvm gemset create cf-imasd
imasd@corelia:~$ rvm gemset use cf-imasd
Y ahora que ya estamos en el gemset especifico, instalamos vmc .
1
imasd@corelia:~$ gem install vmc --no-rdoc --no-ri
Uso de vmc
Lo primero es conectarse a la infraestructura.
1
2
imasd@corelia:~$ vmc target api.cfimasd.abadasoft.com
Setting target to http://api.cfimasd.abadasoft.com... OK
Si no tenemos usuario registrado, debemos crear uno, esto sólo es posible si el entorno lo permite.
1
2
3
4
5
6
7
8
9
10
imasd@corelia:~$ vmc register imasd@abadasoft.com
Password> *********
Confirm Password> *********
Your password strength is: good
Creating user... OK
target: http://api.cfimasd.abadasoft.com
Authenticating... OK
Una vez registrado, podemos logarnos.
1
2
3
4
5
6
imasd@corelia:~$ vmc login imasd@abadasoft.com
target: http://api.cfimasd.abadasoft.com
Password> *********
Authenticating... OK
Ya podríamos desplegar aplicaciones.
Ejemplo de despliegue
Para relizar el despliegue de una aplicación únicamente debemos ir al directorio de dicha aplicación, y ejecutar vmc push
.
Aplicacion ruby
Despliegue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
imasd@corelia:~/apps/env$ vmc push
Using manifest file manifest.yml
Creating env... OK
1: env.cfimasd.abadasoft.com
2: none
Domain> env.cfimasd.abadasoft.com
Updating env... OK
Uploading env... OK
Starting env... OK
Checking env...
0/1 instances: 1 starting
1/1 instances: 1 running
OK
El fichero manifest.yml tiene:
1
2
3
4
5
6
7
8
9
---
applications :
- name : env
framework : sinatra
runtime : ruby19
memory : 128 M
instances : 1
url : env . $ { target - base }
path : .
Prueba
1
2
imasd @corelia :~ /apps/en v $ lynx -- dump env . cfimasd . abadasoft . com
XXXXX Hello from the Cloud ! via : 192 . 168 . 242 . 137 : 54765
Si se hace un cambio en el codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
imasd @corelia :~ /apps/en v $ vim env . rb
imasd @corelia :~ /apps/en v $ vmc push
Using manifest file manifest . yml
Uploading env . . . OK
Stopping env . . . OK
Starting env . . . OK
Checking env . . .
0 / 1 instances : 1 starting
1 / 1 instances : 1 running
OK
imasd @corelia :~ /apps/en v $ lynx -- dump env . cfimasd . abadasoft . com
XXXXX Hello from the Cloud ! via : 192 . 168 . 242 . 137 : 46386
Your IP address is 213 . 37 . 69 . 91
Aplicacion Java
Despliegue
Enpaquetamos:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
imasd @corelia :~ /apps/ hello - java $ mvn clean package
[ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ]
[ INFO ] Packaging webapp
[ INFO ] Assembling webapp [ hello - java ] in [ /home/im asd / apps / hello - java / target / hello - java - 1 . 0 ]
[ INFO ] Processing war project
[ INFO ] Copying webapp resources [ /home/im asd / apps / hello - java / src / main / webapp ]
[ INFO ] Webapp assembled in [ 68 msecs ]
[ INFO ] Building war : /home/im asd / apps / hello - java / target / hello - java - 1 . 0 . war
[ INFO ] WEB - INF / web . xml already added , skipping
[ INFO ] ------------------------------------------------------------------------
[ INFO ] BUILD SUCCESS
[ INFO ] ------------------------------------------------------------------------
[ INFO ] Total time : 14 . 598 s
[ INFO ] Finished at : Fri Apr 19 11 : 32 : 40 CEST 2013
[ INFO ] Final Memory : 16 M / 148 M
[ INFO ] ------------------------------------------------------------------------
Desplegamos:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
imasd @corelia :~ /apps/ hello - java $ cd target /
imasd @corelia :~ /apps/ hello - java / target $ vmc push
Name > hello - java
Instances > 1
1 : java_web
2 : other
Framework > 1
1 : java
2 : java7
3 : other
Runtime > 1
1 : 64 M
2 : 128 M
3 : 256 M
4 : 512 M
5 : 1 G
Memory Limit > 512 M
Creating hello - java . . . OK
1 : hello - java . cfimasd . abadasoft . com
2 : none
Domain > hello - java . cfimasd . abadasoft . com
Updating hello - java . . . OK
Create services for application? > n
Save configuration? > n
Uploading hello - java . . . OK
Starting hello - java . . . OK
Checking hello - java . . .
0 / 1 instances : 1 starting
1 / 1 instances : 1 running
OK
Prueba
1
2
imasd @corelia :~ /apps/ hello - java / target $ lynx -- dump hello - java . cfimasd . abadasoft . com
Hello from 192 . 168 . 242 . 137 : 50389
Si se hace un cambio en el codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
imasd @corelia :~ /apps/ hello - java $ vim src / main / java / org / cloudfoundry / samples / HelloServlet . java
imasd @corelia :~ /apps/ hello - java $ mvn clean package
imasd @corelia :~ /apps/ hello - java $ vmc push -- path target /
Name > hello - java
Save configuration? > y
Saving to manifest . yml . . . OK
Uploading hello - java . . . OK
Stopping hello - java . . . OK
Starting hello - java . . . OK
Checking hello - java . . .
0 / 1 instances : 1 starting
1 / 1 instances : 1 running
OK
Al pulsar y
en Save configuration? se crea el fichero manifest.yml :
1
2
3
4
5
6
7
8
9
10
imasd @corelia :~ /apps/ hello - java $ cat manifest . yml
---
applications :
- name : hello - java
framework : java_web
runtime : java
memory : 512 M
instances : 1
url : hello - java . $ { target - base }
path : target /
El dump para comprobar si la aplicación ha cambiado:
1
2
3
imasd @corelia :~ /apps/ hello - java $ lynx -- dump hello - java . cfimasd . abadasoft . com
Hello from 192 . 168 . 242 . 137 : 47951
I am : hello - java