Let's create a new application:
$ padrino g project hello-world-anynines-mysql -d activerecord -a mysql
create
create .gitignore
create config.ru
create config/apps.rb
create config/boot.rb
create public/favicon.ico
create public/images
create public/javascripts
create public/stylesheets
create tmp
create .components
create app
create app/app.rb
create app/controllers
create app/helpers
create app/views
create app/views/layouts
create Gemfile
create Rakefile
applying activerecord (orm)...
apply orms/activerecord
insert Gemfile
insert Gemfile
insert app/app.rb
create config/database.rb
skipping test component...
skipping mock component...
skipping script component...
applying slim (renderer)...
apply renderers/slim
insert Gemfile
skipping stylesheet component...
identical .components
force .components
force .components
=================================================================
hello-world-anynines-mysql is ready for development!
=================================================================
$ cd ./hello-world-anynines-mysql
$ bundle
=================================================================
After running bundle
to generate the Gemfile.lock
, you need to login:
$ cf login
target: https://api.de.a9s.eu
Email> [email protected]
Password> **********
Authenticating... OK
Now, we are ready to deploy our app:
$ cf push
Name> anynines-padrino-mysql
Instances> 1
1: 128M
2: 256M
3: 512M
4: 1G
Memory Limit> 256M
Creating anynines-padrino-mysql... OK
1: anynines-padrino-mysql
2: none
Subdomain> anynines-padrino-mysql
1: de.a9sapp.eu
2: none
Domain> de.a9sapp.eu
Creating route anynines-padrino-mysql.de.a9sapp.eu... OK
Binding anynines-padrino-mysql.de.a9sapp.eu to anynines-padrino-mysql... OK
Create services for application?> y
1: elasticsearch 0.20
2: mongodb 2.0
3: mysql 5.5
4: postgresql 9.1
5: rabbitmq 2.8
6: redis 2.2
7: swift 1.0
8: user-provided , via
What kind?> 3
Name?> mysql-e26e2
1: Pluto-free: Shared VM, shared DB: free plan
2: Venus-20: Shared: 2 GB Ram, 20 GB Storage
Which plan?> 1
Creating service mysql-e26e2... OK
Binding mysql-e26e2 to anynines-padrino-mysql... OK
Create another service?> n
Bind other services to application?> n
Save configuration?> y
Saving to manifest.yml... OK
Uploading anynines-padrino-mysql... OK
Preparing to start anynines-padrino-mysql... OK
-----> Downloaded app package (12K)
-----> Downloaded app package (12K)
-----> Using Ruby version: ruby-1.9.3
-----> Installing dependencies using Bundler version 1.3.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
tps://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Installing rake (10.1.1)
Installing i18n (0.6.9)
Installing minitest (4.7.5)
Installing multi_json (1.9.0)
Installing atomic (1.1.16)
Installing thread_safe (0.2.0)
Installing tzinfo (0.3.39)
Installing activesupport (4.0.4)
Installing builder (3.1.4)
Installing activemodel (4.0.4)
Installing activerecord-deprecated_finders (1.0.3)
Installing arel (4.0.2)
Installing activerecord (4.0.4)
Installing rack (1.5.2)
Installing url_mount (0.2.1)
Installing http_router (0.11.1)
Installing mime-types (1.25.1)
Installing polyglot (0.3.4)
Installing treetop (1.4.15)
Installing mail (2.5.4)
Installing moneta (0.7.20)
Installing mysql2 (0.3.15)
Installing rack-protection (1.5.2)
Installing tilt (1.4.1)
Installing sinatra (1.4.4)
Installing thor (0.17.0)
Installing padrino-core (0.12.0)
Installing padrino-helpers (0.12.0)
Installing padrino-admin (0.12.0)
Installing padrino-cache (0.12.0)
Using bundler (1.3.2)
Installing padrino-gen (0.12.0)
Installing padrino-mailer (0.12.0)
Installing padrino (0.12.0)
Installing temple (0.6.7)
Installing slim (2.0.2)
Your bundle is complete! It was installed into ./vendor/bundle
Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> WARNINGS:
You have not declared a Ruby version in your Gemfile.
To set your Ruby version add this line to your Gemfile:"
ruby '1.9.3'"
# See https://devcenter.heroku.com/articles/ruby-versions for more information."
tps://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Installing rake (10.1.1)
Installing i18n (0.6.9)
Installing minitest (4.7.5)
Installing multi_json (1.9.0)
Installing atomic (1.1.16)
Installing thread_safe (0.2.0)
Installing tzinfo (0.3.39)
Installing activesupport (4.0.4)
Installing builder (3.1.4)
Installing activemodel (4.0.4)
Installing activerecord-deprecated_finders (1.0.3)
Installing arel (4.0.2)
Installing activerecord (4.0.4)
Installing rack (1.5.2)
Installing url_mount (0.2.1)
Installing http_router (0.11.1)
Installing mime-types (1.25.1)
Installing polyglot (0.3.4)
Installing treetop (1.4.15)
Installing mail (2.5.4)
Installing moneta (0.7.20)
Installing mysql2 (0.3.15)
Installing rack-protection (1.5.2)
Installing tilt (1.4.1)
Installing sinatra (1.4.4)
Installing thor (0.17.0)
Installing padrino-core (0.12.0)
Installing padrino-helpers (0.12.0)
Installing padrino-admin (0.12.0)
Installing padrino-cache (0.12.0)
Using bundler (1.3.2)
Installing padrino-gen (0.12.0)
Installing padrino-mailer (0.12.0)
Installing padrino (0.12.0)
Installing temple (0.6.7)
Installing slim (2.0.2)
Your bundle is complete! It was installed into ./vendor/bundle
Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> WARNINGS:
You have not declared a Ruby version in your Gemfile.
To set your Ruby version add this line to your Gemfile:"
ruby '1.9.3'"
# See https://devcenter.heroku.com/articles/ruby-versions for more information."
Checking status of app 'anynines-padrino-mysql'...
0 of 1 instances running (1 starting)
1 of 1 instances running (1 running)
Push successful! App 'anynines-padrino-mysql' available at anynines-padrino-mysql.de.a9sapp.eu
Next, we need to find out the credentials for our database:
$ cf tunnel
1: mysql-e26e2
Which service instance?> 1
1: none
2: mysql
3: mysqldump
Which client would you like to start?> 2
Opening tunnel on port 10000... OK
Waiting for local tunnel to become available... OK
'mysql' execution failed; is it in your $PATH?
I need to install a proper mysql client with sudo apt-get install mysql-client-5.5
. Now we need to get the credentials
of the database:
$ cf tunnel
1: mysql-e26e2
Which service instance?> 1
1: none
2: mysql
3: mysqldump
Which client would you like to start?> 2
Opening tunnel on port 10000... OK
Waiting for local tunnel to become available... OK
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 523597
Server version: 5.5.29-rel29.4 Percona Server with XtraDB (GPL), Release rel29.4, Revision 401
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+-----------------------------------+
| Database |
+-----------------------------------+
| information_schema |
| d52372f354f604616a03cce4680a8e126 |
+-----------------------------------+
2 rows in set (0.30 sec)
mysql> exit
But what we really need are the credentials:
1: mysql-e26e2
Which service instance?> 1
1: none
2: mysql
3: mysqldump
Which client would you like to start?> 1
Opening tunnel on port 10000... OK
Service connection info:
username : utpQSWCohARgN
password : ps8YnASnVGJIS
name : d52372f354f604616a03cce4680a8e126
uri : mysql://utpQSWCohARgN:[email protected]:3307/d52372f354f604616a03cce4680a8e126
Open another shell to run command-line clients or
use a UI tool to connect using the displayed information.
Press Ctrl-C to exit...
And now edit config/database.rb
with the following settings:
ActiveRecord::Base.configurations[:production] = {
:adapter => 'mysql2',
:encoding => 'utf8',
:reconnect => true,
:database => 'd52372f354f604616a03cce4680a8e126',
:pool => 5,
:username => 'utpQSWCohARgN',
:password => 'ps8YnASnVGJIS',
:host => '10.12.0.6',
:socket => '/tmp/mysql.sock'
}
And run the migrations:
$ cf push --command "PADRINO_ENV=production bundle exec rake ar:migrate"
Using manifest file manifest.yml
Not applying manifest changes without --reset
Uploading anynines-padrino-mysql... OK
Changes:
command: '' -> 'PADRINO_ENV=production bundle exec rake ar:migrate'
Updating anynines-padrino-mysql... OK
Stopping anynines-padrino-mysql... OK
Preparing to start anynines-padrino-mysql... OK
-----> Downloaded app package (16K)
-----> Downloaded app buildpack cache (9.9M)
-----> Downloaded app package (16K)
-----> Downloaded app buildpack cache (9.9M)
r version 1.3.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
Using rake (10.1.1)
Using i18n (0.6.9)
Using minitest (4.7.5)
Using multi_json (1.9.0)
Using atomic (1.1.16)
Using thread_safe (0.2.0)
Using tzinfo (0.3.39)
Using activesupport (4.0.4)
Using builder (3.1.4)
Using activemodel (4.0.4)
Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.2)
Using activerecord (4.0.4)
Using rack (1.5.2)
Using url_mount (0.2.1)
Using http_router (0.11.1)
Using mime-types (1.25.1)
Using polyglot (0.3.4)
Using treetop (1.4.15)
Using mail (2.5.4)
Using moneta (0.7.20)
Using mysql2 (0.3.15)
Using rack-protection (1.5.2)
Using tilt (1.4.1)
Using sinatra (1.4.4)
Using thor (0.17.0)
Using padrino-core (0.12.0)
Using padrino-helpers (0.12.0)
Using padrino-admin (0.12.0)
Using padrino-cache (0.12.0)
Using bundler (1.3.2)
Using padrino-gen (0.12.0)
Using padrino-mailer (0.12.0)
Using padrino (0.12.0)
Using temple (0.6.7)
Using slim (2.0.2)
Your bundle is complete! It was installed into ./vendor/bundle
Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> WARNINGS:
You have not declared a Ruby version in your Gemfile.
To set your Ruby version add this line to your Gemfile:"
ruby '1.9.3'"
# See https://devcenter.heroku.com/articles/ruby-versions for more information."
-----> Uploading droplet (27M)
Checking status of app 'anynines-padrino-mysql'...
0 of 1 instances running (1 starting)
0 of 1 instances running (1 starting)
0 of 1 instances running (1 starting)
0 of 1 instances running (1 starting)
0 of 1 instances running (1 starting)
0 of 1 instances running (1 crashing)
Push unsuccessful.
TIP: The system will continue to attempt restarting all requested app instances that have crashed. Try 'cf app' to monitor app status. To troubleshoot crashes, try 'cf events' and 'cf crashlogs'.
You can find the code https://github.com/matthias-guenther/hello-world-padrino-anynines-mysql
Hey Matthias,
sorry for the delayed response.
This is what i did to make it work:
ActiveRecord::Base.configurations[:production] = {
:adapter => 'mysql2',
:encoding => 'utf8',
:reconnect => true,
:database => JSON.parse(ENV["VCAP_SERVICES"])["mysql-5.5"].first['credentials']['name'],
:pool => 5,
:username => JSON.parse(ENV["VCAP_SERVICES"])["mysql-5.5"].first['credentials']['username'],
:password => JSON.parse(ENV["VCAP_SERVICES"])["mysql-5.5"].first['credentials']['password'],
:host => JSON.parse(ENV["VCAP_SERVICES"])["mysql-5.5"].first['credentials']['hostname'],
:port => JSON.parse(ENV["VCAP_SERVICES"])["mysql-5.5"].first['credentials']['port']
}
cf push --command 'RACK_ENV=production bundle exec rake ar:migrate'
cf push --command 'RACK_ENV=production bundle exec padrino start -p $PORT -h $VCAP_APP_HOST'