« Previous -
Version 19/33
(diff) -
Next » -
Current version
Guillermo Gómez, 02/24/2012 06:04 pm
Openshift¶
Instalación herramientas cliente¶
Fedora
$ su -c "yum install rubygem-rhc"
YUM
$ su - <contraseña> # cd /etc/yum.repos.d/ # wget https://openshift.redhat.com/app/repo/openshift.repo # yum install rhc
rubygems
$ su -c "gem install rhc"
Creación nombre de dominio¶
$ rhc-create-domain -n gomix -l guillermo.gomez@gmail.com Created local config file: /home/gomix/.openshift/express.conf express.conf contains user configuration and can be transferred across clients. Password: Generating Openshift Express ssh key to /home/gomix/.ssh/libra_id_rsa Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/gomix/.ssh/libra_id_rsa. Your public key has been saved in /home/gomix/.ssh/libra_id_rsa.pub. The key fingerprint is: 56:29:bc:e8:7f:95:6e:fb:2b:12:85:f5:6e:b2:44:9c gomix@movix.fedora-ve.org The key's randomart image is: +--[ RSA 2048]----+ | | | . .. | | o o+ o | | . +. E . | | . S o o | | . . . = o | | . = + | | . o = | | .. o.+o. | +-----------------+ Contacting https://openshift.redhat.com Adding rhlogin to /home/gomix/.openshift/express.conf Creation successful You may now create an application. Please make note of your local config file in /home/gomix/.openshift/express.conf which has been created and populated for you.
Creación de primera aplicación Rails¶
Rails está basado en rack por lo que se ha de instalar de entrada es una aplicación rack en Openshift.
$ rhc-create-app -a fudcon -t rack-1.1
Password:
Found a bug? Post to the forum and we'll get right on it.
IRC: #openshift on freenode
Forums: https://www.redhat.com/openshift/forums
Creating remote application space: fudcon
Contacting https://openshift.redhat.com
RESULT:
Successfully created application: fudcon
Checking ~/.ssh/config
Contacting https://openshift.redhat.com
Could not find /home/gomix/.ssh/config. This is ok, continuing
Adding rhcloud.com to ~/.ssh/config
Now your new domain name is being populated worldwide (this might take a minute)...
Pulling new repo down
Warning: Permanently added 'fudcon-gomix.rhcloud.com,67.202.44.44' (RSA) to the list of known hosts.
Confirming application fudcon is available
Attempt # 1
Success! Your application is now published here:
http://fudcon-gomix.rhcloud.com/
The remote repository is located here:
ssh://0b027ce8ffde4b7eb98e5bd63908ed21@fudcon-gomix.rhcloud.com/~/git/fudcon.git/
To make changes to your application, commit to fudcon/.
Then run 'git push' to update your Openshift Express space
Encima Rails 3.0.8¶
$ cd ..
$ rails new fudcon ;mismo directorio creado por las herramientas para app rack 1.0.1
$ rails new fudcon
exist
conflict README
Overwrite /home/gomix/tmp/fudcon/README? (enter "h" for help) [Ynaqdh] n
skip README
create Rakefile
conflict config.ru
Overwrite /home/gomix/tmp/fudcon/config.ru? (enter "h" for help) [Ynaqdh] n
skip config.ru
create .gitignore
...
Se evitó modificar el README y config.ru.
$ bundle install --deployment The --deployment flag requires a Gemfile.lock. Please make sure you have checked your Gemfile.lock into version control before deploying. $ echo "vendor/bundle/ruby/1.8/gems/sqlite3-*" >> .gitignore $ echo "vendor/bundle/ruby/1.8/gems/mysql-*" >> .gitignore
No necesariamente justo después, sino que tuve que dar unas cuantas vueltas por mi falta de conocimientos acerca de bundler y openshift:
Agregando un gem con bundle¶
Incompleto:
$ vim Gemfile ... gem 'cancan' # gem agregado al Gemfile :wq $ bundle install --no-deployment ... Enter your password to install the bundled RubyGems to your system: xxxxx ... Using bundler (1.0.12) Installing cancan (1.6.5) Using thor (0.14.6) ...
$ bundle install --deployment Fetching source index for http://rubygems.org/ Fetching source index for http://gems.github.com/ Using rake (0.9.2) Using abstract (1.0.0) ... Using activerecord (3.0.8) Using activeresource (3.0.8) Installing cancan (1.6.5) Using bundler (1.0.12) ... Your bundle is complete! It was installed into ./vendor/bundle $ git add vendor $ git commit $ git push
Rails rake:db:migrate¶
En la medida que vamos desarrollando nuestra aplicación el esquema de la base de datos va cambiando, entonces, ¿cómo ejecutamos rake db:migrate? La técnica es usar config/environments/production.rb de la siguiente manera:
1 config.after_initialize do
2 ActiveRecord::Migrator.migrate(RAILS_ROOT + "/db/migrate" )
3 end
Queda pendiente documentar otras técnicas para por ejemplo rehacer la base de datos desde cero, o eliminar la tabla de sesiones entre otras necesidades comunes.
Integración git/redmine/openshift¶
Al instalar y configurar openshift, se genera una configuración ssh , una llave específica de seguridad, y un archivo de hosts conocidos. Para poder acceder desde otra máquina, en este caso el servidor Redmine, estoy copiando los archivos correspondientes de configuración.
$ cd ~/.ssh
$ cat config
# Added by rhc-create-app on mié jun 15 17:22:53 VET 2011
Host *.rhcloud.com
IdentityFile ~/.ssh/libra_id_rsa
VerifyHostKeyDNS yes
StrictHostKeyChecking no
UserKnownHostsFile ~/.ssh/libra_known_hosts
$ scp config gomix.fedora-ve.org:~/.ssh/
...
$ scp libra_id_rsa gomix.fedora-ve.org:~/.ssh/
...
$ scp libra_known_hosts gomix.fedora-ve.org:~/.ssh/
...
Ahora en mi servidor Redmine:
$ cd cierto/directorio/accesible $ git clone --bare ssh://0b027ce8ffde4b7eb98e5bd63908ed21@fudcon-gomix.rhcloud.com/~/git/fudcon.git/ Cloning into bare repository fudcon.git... remote: Counting objects: 3470, done. remote: Compressing objects: 100% (2654/2654), done. remote: Total 3470 (delta 705), reused 3220 (delta 635) Receiving objects: 100% (3470/3470), 8.09 MiB | 118 KiB/s, done. Resolving deltas: 100% (705/705), done.
Edite la configuración git:
$ cat config
[core]
repositoryformatversion = 0
filemode = true
bare = true
[remote "origin"]
url = ssh://0b027ce8ffde4b7eb98e5bd63908ed21@fudcon-gomix.rhcloud.com/~/git/fudcon.git
fetch = +refs/heads/*:refs/remotes/origin/*
Solo debería necesitar agregar la línea fetch. Luego para refrescar su repositorio local cada quince minutos y a su vez Redmine lo pueda mostrar actualizado:
$ crontab -l */15 * * * * cd /home/gomix/Public/fudcon.git && git fetch && git reset --soft refs/remotes/origin/master
La configuración Redmine es simple, abajo un pantallazo, sólo debe seleccionar el tipo a git y pasarle la ruta al clone git (bare).
Abajo un pantallazo de un proyecto Redmine ejemplo conectado git con Openshift.
Herramientas express¶
/usr/bin/rhc-create-app /usr/bin/rhc-create-domain /usr/bin/rhc-ctl-app /usr/bin/rhc-snapshot /usr/bin/rhc-tail-files /usr/bin/rhc-user-info
rhc-create-app¶
$ rhc-create-app -d -a ipostel -t rack-1.1
Password:
Found a bug? Post to the forum and we'll get right on it.
IRC: #openshift on freenode
Forums: https://www.redhat.com/openshift/forums
Attempting to create remote application space: ipostel
Contacting https://openshift.redhat.com
Response from server:
DEBUG:
Validating application limit guillermo.gomez@gmail.com: num of apps(0) must be < app limit(5)
Exit Code: 0
broker: 1.1.1
api: 1.1.1
broker_c: namespacerhloginsshapp_uuiddebugaltercartridgecart_typeactionapp_nameapi
api_c: placeholder
API version: 1.1.1
Broker version: 1.1.1
RESULT:
Successfully created application: ipostel
Checking ~/.ssh/config
Contacting https://openshift.redhat.com
Submitting form:
debug: true
rhlogin: ggomix
Found rhcloud.com in ~/.ssh/config... No need to adjust
Now your new domain name is being propagated worldwide (this might take a minute)...
Pulling new repo down
git clone --quiet ssh://4ef0c99c6ff749d89d3362c8d81a6120@ipostel-gomix.rhcloud.com/~/git/ipostel.git/ ipostel
Warning: Permanently added 'ipostel-gomix.rhcloud.com,174.129.50.173' (RSA) to the list of known hosts.
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 11 (delta 0), reused 11 (delta 0)
Receiving objects: 100% (11/11), 13.49 KiB, done.
Confirming application ipostel is available
Attempt # 1
Success! Your application is now published here:
http://ipostel-gomix.rhcloud.com/
The remote repository is located here:
ssh://4ef0c99c6ff749d89d3362c8d81a6120@ipostel-gomix.rhcloud.com/~/git/ipostel.git/
To make changes to your application, commit to ipostel/.
Then run 'git push' to update your OpenShift Express space
rhc-ctl-app¶
$ rhc-ctl-app app -h Usage: /usr/bin/rhc-ctl-app Control an OpenShift express app -a|--app application Application name (alphanumeric) (required) -l|--rhlogin rhlogin Red Hat login (RHN or OpenShift login with OpenShift Express access) (Default: guillermo.gomez@gmail.com) -p|--password password RHLogin password (optional, will prompt) -c|--command command (start|stop|restart|reload|status|destroy) -L|--embedded-list List supported embedded cartridges -e|--embed (add-$cartridge|remove-$cartridge) eg: add-mysql-5.1 -b|--bypass Bypass warnings -d|--debug Print Debug info -h|--help Show Usage info
start
$ rhc-ctl-app -a fudcon -c start Password: Contacting https://openshift.redhat.com Contacting https://openshift.redhat.com API version: 1.1.1 Broker version: 1.1.1 RESULT: Success
stop
$ rhc-ctl-app -a fudcon -c stop Password: Contacting https://openshift.redhat.com Contacting https://openshift.redhat.com API version: 1.1.1 Broker version: 1.1.1 RESULT: Success
restart
$ rhc-ctl-app -a fudcon -c restart Password: Contacting https://openshift.redhat.com Contacting https://openshift.redhat.com API version: 1.1.1 Broker version: 1.1.1 RESULT: Success
status
$ rhc-ctl-app -a fudcon -c status Password: Contacting https://openshift.redhat.com Contacting https://openshift.redhat.com API version: 1.1.1 Broker version: 1.1.1 RESULT: Total Accesses: 0 Total kBytes: 0 Uptime: 44 ReqPerSec: 0 BytesPerSec: 0 BusyWorkers: 1 IdleWorkers: 0 Scoreboard: W....
rhc-user-info¶
$ rhc-user-info
Password:
Contacting https://openshift.redhat.com
Application Info
================
fudcon
Framework: rack-1.1
Creation: 2011-06-15T17:52:39-04:00
UUID: 0b027ce8ffde4b7eb98e5bd63908ed21
Git URL: ssh://0b027ce8ffde4b7eb98e5bd63908ed21@fudcon-gomix.rhcloud.com/~/git/fudcon.git/
Public URL: http://fudcon-gomix.rhcloud.com/
Embedded:
None
ipostel
Framework: rack-1.1
Creation: 2011-08-23T21:55:38-04:00
UUID: 4ef0c99c6ff749d89d3362c8d81a6120
Git URL: ssh://4ef0c99c6ff749d89d3362c8d81a6120@ipostel-gomix.rhcloud.com/~/git/ipostel.git/
Public URL: http://ipostel-gomix.rhcloud.com/
Embedded:
None
rhc-tail-files¶
$ rhc-tail-files -a fudcon -f fudcon/logs/* -p budhUjvwn6
...
==> fudcon/logs/error_log-20110712-000000-EST <==
from /var/lib/libra/0b027ce8ffde4b7eb98e5bd63908ed21/fudcon/deploy/config/application.rb:7
from /var/lib/libra/0b027ce8ffde4b7eb98e5bd63908ed21/fudcon/deploy/config/environment.rb:2:in `require'
from /var/lib/libra/0b027ce8ffde4b7eb98e5bd63908ed21/fudcon/deploy/config/environment.rb:2
from config.ru:3:in `require'
from config.ru:3
from /var/lib/libra/0b027ce8ffde4b7eb98e5bd63908ed21/fudcon/deploy/vendor/bundle/ruby/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'
from /var/lib/libra/0b027ce8ffde4b7eb98e5bd63908ed21/fudcon/deploy/vendor/bundle/ruby/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'
from config.ru:1:in `new'
from config.ru:1
/var/lib/libra/0b027ce8ffde4b7eb98e5bd63908ed21/fudcon/deploy/config/environments/production.rb:51: warning: don't put space before argument parentheses
...
production.log: para que pueda tener ese log disponible con rhc-tail-files debe realizar el siguiente pequeño ajuste en config/environments/production.rb:
1paths.log="../logs/production.log"
$ rhc-tail-files -a fudcon -f fudcon/logs/production.log -p budhUjvwn6 Contacting https://openshift.redhat.com Attempting to tail files: fudcon/logs/production.log Use ctl + c to stop Started GET "/" for 41.208.172.156 at Thu Aug 25 02:27:26 -0400 2011 Processing by WelcomeController#index as HTML Redirected to https://cas.ipostel.gob.ve/login?service=http%3A%2F%2Ffudcon-gomix.rhcloud.com%2Fwelcome%2Findex Completed 302 Found in 2ms Started GET "/" for 61.135.249.108 at Thu Aug 25 04:40:38 -0400 2011 Processing by WelcomeController#index as HTML Redirected to https://cas.ipostel.gob.ve/login?service=http%3A%2F%2Ffudcon-gomix.rhcloud.com%2Fwelcome%2Findex Completed 302 Found in 2ms ...
rhc-domain-info¶
Ayuda en línea¶
$ rhc-domain-info -h Usage: /usr/bin/rhc-domain-info Display information about a user -l|--rhlogin rhlogin Red Hat login (RHN or OpenShift login with OpenShift Express access) (Default: ggomix) -p|--password password RHLogin password (optional, will prompt) -a|--apps List applications for rhlogin -i|--info Show user info -d|--debug Print Debug info -h|--help Show Usage info --config path Path of alternate config file --timeout # Timeout, in seconds, for connection
Ejemplo de uso¶
$ rhc-domain-info
Password: ****
Application Info
================
ruby18demo
Framework: ruby-1.8
Creation: 2012-02-24T17:30:59-05:00
UUID: e5f597d537d14ecfa037a8af4a9cc500
Git URL: ssh://e5f597d537d14ecfa037a8af4a9cc500@ruby18demo-gomix.rhcloud.com/~/git/ruby18demo.git/
Public URL: http://ruby18demo-gomix.rhcloud.com/
Embedded:
None
railsdemo
Framework: ruby-1.8
Creation: 2012-02-24T16:49:54-05:00
UUID: 57081cf672ed40598025e9323bad50d6
Git URL: ssh://57081cf672ed40598025e9323bad50d6@railsdemo-gomix.rhcloud.com/~/git/railsdemo.git/
Public URL: http://railsdemo-gomix.rhcloud.com/
Embedded:
None
