rake db:migrate runs in development AWS Beanstalk - mysql

I'm new to Beanstalk. I've created a Rails application and set the database production configuration to use the environment variables hopefully provided by AWS. I'm using Mysql (mysql2 gem), and want to use RDS and Passenger (I have no preference there).
On my development environment I can run the rails application with my local Mysql (it is just a basic application I've created for experimentation).
I have added the passenger gem to Gemfile and bundled, but I'm using WEBBrick in development still.
The only thing I did not do by the book is that I did not use 'eb' but rather tried from the console. My application/environment failed to run as while "rake db:migrate" it still thinks I wanted it to connect to the local Mysql (I guess from the logs that it is not aware of RACK_ENV and hence uses 'development').
Any tip? I can of course try next the 'eb', yet would prefer to work with the console.
Regards,
Oren

In Elastic Beanstalk (both the web console and the cli), you can pass environnement variables. If you pass the RAKE_ENV variable, you will change your environnement.
After that you still need to pass your database parameters (db password, name, ...) which should not be hardcoded into the code.

Have you tried to run
bin/rake db:migrate RAILS_ENV=development
?
I got the same issue and that worked for me.

I recommend you enter to EC2 instance through this command "eb ssh" (The first time you need specified you .pem file, if you have not one you can create in IAM services) and check your logs for more information about yours error.
If you have problems when you are uploading your code (eb deploy) you have the log in this file: "/var/log/eb-activity.log" (Remember this file is in your EC2 instance)
If you have a problems with your app, you can read the logs in this files: "/var/app/support/logs/production.log" or "/var/app/support/logs/passenger.log"
Other recommedations is install EB CLI version 3. for manage your eb instance
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html

I believed that Elastic Beanstalk will run 'rake db:migrate' by itself. Indeed it seems to try, but that is failing. I gave my bounty to 'Yahs Hef', even though I will only try this evening (UK). My disorientation with AWS caused me to forget this easy solution, of running the migration by myself. If this does not work by itself, I'll simplify the database configuration as possibile.

Related

Configure a Wildfly 10 MSQL datasource in OpenShift v3

I have an application currently working on my local Dev machine. It uses Wildfly 10, MySQL 5.7 and Hibernate. My application looks for the 'AppDS' datasource from within Wildfly.
I've created a Wildfly 10 container and a MySQL container on OpenShift V3. Typically, I would log into Wildfly and configure a datasource, but all that configuration is lost when a container restarts. I thought it would be a matter of finding my connection environment settings, and using the pre-configured database connections, but I can't find what the variables should be set to, and the default connections don't work without them.
I downloaded and read OpenShift for Developers, but they side-step the issue by creating a direct database connection, rather than going through a datasource.
exporting the environment variables failed because 'no matches for apps.openshift.io/, Kind=DeploymentConfig'. Is the book out of date? Are they not using deployment config to store environment variables?
I would appreciate it greatly if someone could point me in the right direction.
I have a project running locally on my machine that uses Wildfly 10, Mysql 5.7 and Hibernate. I found the documentation to be incomplete. After a few days of working with it, I have figured out how to deploy a simple J2EE project with this stack.
I am updating my question with the step-by-step I wish I'd had. I hope this saves someone some time in the future.
create new openshift user
create project dbtest
add MySQL to dbtest project:
The following service(s) have been created in your project: mysql:
Username: test
Password: test
Database Name: testdb
Connection URL: mysql://mysql:3306/
add Wildfly to the project:
oc login https://api.starter-us-west-1.openshift.com
oc project dbtest
oc status
scale current wildfly pod to 0. (you won't have enough CPU to run 3 pods, and redeploy tries to start a new one and hot swap them)
From left menu: Applications->Deployments->(dbtest)Wildfly10 pod->environment(tab)-> add:
MYSQL_DATABASE=testdb
MYSQL_DB_ENABLED=true
MYSQL_USER:test
MYSQL_PASSWORD: test
push wildfly pod back to 1.
use terminal in Wildfly to run ./add-user.sh
oc port-forward wildfly10-6-rkr58 :9990 (replace wildfly10-6-rkr58 with your pod name, found by clicking on the running pod [circle with a 1 in it] and noting the pod name in the upper left corner])
login to Wildfly from 127.0.0.1: and test the MySQLDS. It should now connect.
Go through the environment variables mentioned here to get a better understanding.

How to solve Update environment operation is complete, but with errors. For more information error in AWS Elasticbeanstalk

I am using AWS Elasticbeanstalk for my project.When I uploading new version app it is giving error
Update environment operation is complete, but with errors. For more information, see troubleshooting documentation
My IAM role has AWSElasticbeanstalkFullAccess
Then why I am getting this error.
Thank in advance
I had the same issue.
I did the following and it worked.
From Elastic Beanstalk environment page, I chose to Rebuild the environment (Actions > Rebuild Environment)
Deployed the new application version.
A number of things can result in this, including issues with .ebextensions files.
Troubleshooting tends to be iterative, since logs are frequently not created or inaccessible.
Things to try:
Roll back to a previous application version and verify any changes to .ebextensions are valid
Rebuild the environment (Actions -> Rebuild Envrionment) in the EB console. This frequently enables EBs log snapshot facility to recover such that you can get further insight into what might be amiss.
You can try digging what the error exactly was by getting the logs of the event in the 'eb-engine.log' file. In my case I got this error and follow one answer to solve it. You can try 'eb logs' command also to get detailed info.

Openshift - "Unable to connect to gear" when running: rhc show-app <app> --gear quota

I created an app called "world" following the instructions from:
https://blog.openshift.com/12-tips-for-hosting-wordpress-on-openshift/.
It's a hosted Wordpress blog, with PHP 5.4 scalable up to 1GB, with a Web Load Balancer and MySQL 5.5.
Everytime I try to check for the space used, I get the same error.
rhc show-app world --gears quota
Unable to connect to gear 54d48383fcf933f91f0000aa#54d48383fcf933f91f0000aa-laurapons.rhcloud.com
Unable to connect to gear 54d48383fcf933f91f0000a9#world-laurapons.rhcloud.com
Gear Cartridges Used Limit
------------------------ ------------------- ----- -----
54d48383fcf933f91f0000aa mysql-5.5 error 1 GB
54d48383fcf933f91f0000a9 haproxy-1.4 php-5.4 error 1 GB
I tried to restart the application (using restart and stop&start commands) but nothing seems to work.
I am also facing some other connection problems (probably related to the same issue):
I have the same problem when trying to clone the application with git clone:
ssh: connect to host world-laurapons.rhcloud.com port 22: Bad file number
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
And also with the rhc port-forward world
I copied the URL for git clone from the openshift online dashboard, and I can open the wordpress blog and see all the information, but somehow, I'm unable to access to the data.
I have already created a default Public Key and 2 authorisations (one to access through the browser and the other to access through RHC)...
What should I try?
How can I get the usage?
Do I need to set up anything else?
I am stuck... any suggestion?
Sounds like your SSH key is not working properly. Make sure you installed your keys and that they are working. Try running 'rhc setup'. If that still doesn't work try
ssh -vvv 54d48383fcf933f91f0000a9#world-laurapons.rhcloud.com
and look at the output.
You can also try using
ssh -i /path/to/your/ssh.key 54d48383fcf933f91f0000a9#world-laurapons.rhcloud.com
And see if that works (specifies what ssh key to use)
rhc with some ruby version will have issue with pageant (putty). I closed pageant, ran again rhc command then it worked.

"The forked VM terminated without properly saying goodbye" on EC2 with RDS

I'm running jenkins on an AWS EC2 server, accessing a mysql DB on AWS RDS.
When running mvn clean install locally it's all good, but when jenkins does it on the EC2 server i get this error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project plenty: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /var/lib/jenkins/jobs/Plenty-api/workspace/plenty && /usr/lib/jvm/java-7-oracle/jre/bin/java -XX:MaxPermSize=128m -jar /var/lib/jenkins/jobs/Plenty-api/workspace/plenty/target/surefire/surefirebooter9140193949835996613.jar /var/lib/jenkins/jobs/Plenty-api/workspace/plenty/target/surefire/surefire21120104041831905tmp /var/lib/jenkins/jobs/Plenty-api/workspace/plenty/target/surefire/surefire_08001606298289854825tmp
any ideas?
Oh yeah that one scales from EasyPeasyException (the call to System.exit(); by one of your testclasses) to the complete DeepShitException (I had it once locally, reinstalled the VM and everything was good afterwards).
If it is not one of your testclasses (or dependencies of those) calling a System.exit() you will have to find the dumps of the VM crash and add them to the question for further assistance (I unfortunately wont be able to handle whatever is stored in such dump files - but finding a solution is oftenly teamwork :)).
This is also documented in the plugins documentation: http://maven.apache.org/surefire/maven-surefire-plugin/faq.html#vm-termination

rails deploy - database not uploading

I'm working on my first rails app deploy and the database data from my local computer doesn't seem to be getting loaded into the database on the server when I deploy with capistrano. I'm not clear as to whether capistrano takes care of this or not. I have also tried running 'rake db:schema:load' from the /current release directory. Here's the log of what happens when I try to load the app (on the remote webserver) in a browser.
Started GET "/" for XX.XX.XX.XX at 2012-04-04 13:26:46 -0700
Processing by PagesController#home as HTML
Completed 500 Internal Server Error in 3ms
ActiveRecord::StatementInvalid (Mysql::Error: Table 'project.users' doesn't exist: SHOW FIELDS FROM `users`):
app/models/user.rb:61:in `authenticate_with_salt'
app/helpers/sessions_helper.rb:50:in `user_from_remember_token'
app/helpers/sessions_helper.rb:13:in `current_user'
app/helpers/sessions_helper.rb:17:in `signed_in?'
app/controllers/pages_controller.rb:5:in `home'
So the problem seems to be that the app loads, but the DB isn't populated with tables and data.
I'm sure I'm missing a relatively basic detail of the deployment process, but thus far it escapes me... Any help would be mucho appreciated! Thanks.
What does your Capfile look like?
Neither Rails nor Capistrano will copy data from your development environment to your deployment environment—db:migrate:* and db:schema:* only handle database structure. Before using rake db:schema:load make sure your development environment migrations have been run and your latest db/schema.rb is checked in to your repo.
If you want certain data to be in your database upon deployment look in db/seeds.rb. There are also many gems for seeding database data.