Laravel on AWS ElasticBeanstalk: running artisan migration command on deployment using .ebextensions in failing - laravel

I am deploying the Laravel application to the ElasticBeanstalk. I am running migration command using .ebextensions config on deployment.
I created a .extensions/01-migration.config file under the project root folder with the following content.
container_commands:
01_cd_html:
command: "cd /var/www/html"
02_php_artisan_migrate:
command: "php artisan migrate --force"
Then I deploy my application by running the following command.
eb deploy
Then I got the following error.
2020-07-13 11:51:59 INFO Environment update is starting.
2020-07-13 11:52:39 INFO Deploying new version to instance(s).
2020-07-13 11:52:49 ERROR [Instance: i-0a461ffb24bc26f52] Command failed on instance. An unexpected error has occurred [ErrorCode: 0000000001].
2020-07-13 11:52:49 INFO Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2020-07-13 11:52:49 ERROR Unsuccessful command execution on instance id(s) 'i-0a461ffb24bc26f52'. Aborting the operation.
2020-07-13 11:52:50 ERROR Failed to deploy application.
I could SSH into the server and run the command successfully. But it is just not working on deployment. What is wrong with my configuration and how can I fix it?

I solved the issue. I need to set the environment variables required by the commands in the option_settings. The command I am trying to run is migration command and it is using database credentials. So I specified the env variables for the database. That is weird, it should just work with ones specified in the ElasticBeanstalk console.

Related

Update AWS stack with CF template

Hope everyone is keeping safe!
I have a Ruby on Rails application hosted on AWS Beanstalk. I am using CloudFormation template, to update any stack for e.g., Ruby version, Linux Platform upgrade etc.
I was trying to upgrade, Linux box to 2.11.7 and Ruby to 2.6.6 and then ElasticSearch to 7.4
I was doing these changes in CloudFormation YML template and then I ran aws cloudformation update-stack command to apply these changes.
While the changes took time, I accidentally clicked on Rebuild Environment from Web AWS Console as a result, all the previously configured settings like SQS, Load balancer etc., were replaced by new settings.
Now, whenever I am trying to execute the update-stack command, it fails with below errors:
2020-06-09 15:25:44 UTC+0530
WARN
Environment health has transitioned from Info to Degraded. Command failed on all instances.
Incorrect application version found on all instances. Expected version "code-pipeline-xxxxxxxxxx" (deployment 2377). Application update failed 40 seconds ago and took 79 seconds.
2020-06-09 15:25:03 UTC+0530
INFO
The environment was reverted to the previous configuration setting.
2020-06-09 15:24:44 UTC+0530
INFO
Environment health has transitioned from Ok to Info. Application update in progress on 1 instance. 0 out of 1 instance completed (running for 39 seconds).
2020-06-09 15:24:30 UTC+0530
ERROR
During an aborted deployment, some instances may have deployed the new application version.
To ensure all instances are running the same version, re-deploy the appropriate application version.
2020-06-09 15:24:30 UTC+0530
ERROR
Failed to deploy application.
2020-06-09 15:24:30 UTC+0530
ERROR
Unsuccessful command execution on instance id(s) 'i-xxxxxxxxxx'. Aborting the operation.
2020-06-09 15:24:30 UTC+0530
INFO
Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2020-06-09 15:24:30 UTC+0530
ERROR
[Instance: i-xxxxxxxxxx] Command failed on instance. Return code: 18 Output: (TRUNCATED)...g: the running version of Bundler (1.16.0) is older than the version that created the lockfile (1.17.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. Your Ruby version is 2.6.6, but your Gemfile specified 2.6.5. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
2020-06-09 15:24:19 UTC+0530
INFO
Deploying new version to instance(s).
2020-06-09 15:23:45 UTC+0530
INFO
Updating environment developWeb's configuration settings.
2020-06-09 15:23:36 UTC+0530
INFO
Environment update is starting.
I can confirm that I have Ruby-2.6.6 set. I am not sure from where it is picking up the old version of Ruby?
Is there any way I can fix this? OR forcefully apply template changes?
Any help on this would be highly appreciated.
[UPDATE]: When I try to connect to ElasticSearch from Rails console, I get:
Faraday::ConnectionFailed: Failed to open TCP connection to old-elasticsearch-host-name.es.amazonaws.com:80 (Hostname not known: old-elasticsearch-host-name.es.amazonaws.com)
from /opt/rubies/ruby-2.6.6/lib/ruby/2.6.0/net/http.rb:949:in `rescue in block in connect'
Caused by SocketError: Failed to open TCP connection to old-elasticsearch-host-name.es.amazonaws.com:80 (Hostname not known: old-elasticsearch-host-name.es.amazonaws.com)
from /opt/rubies/ruby-2.6.6/lib/ruby/2.6.0/net/http.rb:949:in `rescue in block in connect'
Caused by Resolv::ResolvError: no address for old-elasticsearch-host-name.es.amazonaws.com
from /opt/rubies/ruby-2.6.6/lib/ruby/2.6.0/resolv.rb:94:in `getaddress'
The new URL of elasticsearch instance is different but it is still picking up the old URL from ELASTICSEARCH_HOST ENV variable.
Information from my CF template:
I can now provide info as per request. please tag me to see what I have in CF template
This was a config issue.
Whenever I was running aws update-stack command, it was going to s3 and pulling the zip (of the source code) code and in Gemfile of that zip code ruby version was set to 2.6.5.
So, I'd uploaded the fresh copy of the source code and then executed the update-stack command and it worked

Laravel AWS Elastic Beanslack deployment error- Out of memory error

I deployed my Application in AWS Elastic Beanslack. Intially I deployed my application directly in Aws console. After configuring all the things. I zipped my code and upload it in a console. At that time its working perfect.
But now I tried to deploy with cli, its shows error. I put eb deploy command
Creating application version archive "app-xxxxxxxxx".
Uploading: [##################################################] 100% Done...
2020-03-14 18:51:49 INFO Environment update is starting.
2020-03-14 18:51:55 INFO Deploying new version to instance(s).
2020-03-14 18:52:22 ERROR [Instance: i-xxxxxxxxx] Command failed on instance. Return code: 255 Output: (TRUNCATED)...ar/src/Composer/DependencyResolver/GenericRule.php on line 36
Fatal error: Out of memory (allocated 809508864) (tried to allocate 8192 bytes) in phar:///opt/elasticbeanstalk/support/composer.phar/src/Composer/DependencyResolver/GenericRule.php on line 36.
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_composer_install.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
2020-03-14 18:52:22 INFO Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2020-03-14 18:52:22 ERROR Unsuccessful command execution on instance id(s) 'i-xxxxxxxxx'. Aborting the operation.
2020-03-14 18:52:23 ERROR Failed to deploy application.
From Internet I tried these all these things
1) I extended memory in php.ini but still its not working
2) I created ebextensions folder and do some configurations but thats also not working
My guess was Initially I deployed manually, so at that time I zipped with vendor folder also. Now when I tried with cli it wont take vendor folder. Instead of its by using composer install
So I think I'm facing this issues due to these things
Please let us know, If any other thing I want to do
This is a configuration inside de ElasticBeanstalk Environment.
To increase de memory limit:
Access the Elastic Beanstalk section
Open to your environment
Go to Configuration , then Software
Find the Memory limit field. The default value is 1024M.
Update the value to what you want
Apply the change
Redeploy your application
When deploy with ElasticBeanstalk (ELB) we should check Environment. With memory_limit, you can config this in Software tab (Configuration)
Follow:
Access the ELB
Open to your environment
Go to Configuration , then Software tab
Find the Memory limit field.
Change the value for what you want
Redeploy

Issue while running npm run sonar

I am using sonar for analysis of nodejs code but when I run npm run sonar I get this error
Error occurred during initialization of VM
Failure when starting JFR on_vm_start
when when I run the command with my root user it works fine.What could be the reason for same?

Karate-Jenkins- ERROR com.intuit.karate - . getting this error only when i run from jenkins

iam running my karate code from Jenkins. where ia, getting below error.
ERROR com.intuit.karate - evaluation of 'karate-config.js' failed: javascript function call failed: ReferenceError: "karate" is not defined .
karate config file keeps on running.
iam using mvn test command to run the job.. even I have tried in Jenkins machine and mvn command works. only in through Jenkins iam getting issue.
Try to upgrade java version in Jenkins server.

OpenWhisk build failure in local vagrant

Attempting to build my local openwhisk instance using the provided VagrantFile. I am using the ephemeral CouchDB container as my datasource.
During ant clean build deploy I get the following exceptions:
BUILD FAILED
/home/vagrant/openwhisk/build.xml:55: The following error occurred while executing this line:
/home/vagrant/openwhisk/build.xml:99: exec returned: 5
Further up the logs I see the following repeated under the installCatalog.sh section:
[exec] error: The supplied authentication is invalid
I've verified that the couchdb credentials in my cloudant-local.env are correct by executing some test curl commands. Not sure what other authentication credentials it could be complaining about. Any ideas?
http://dumptext.com/6QDOWNE3
When you use an ephemeral Couch instance, you need to start it after ant clean build and before deploy. Further, every time you start the container, you have to run the script tools/db/createImmortalDBs.sh to initialize the authentication store.
ant clean build
tools/db/couchdb/start-couchdb-box.sh ...
tools/db/createImmortalDBs.sh
ant deploy
BTW, Did you mean couchdb-local.env?

Resources