Thanks ☒ . Between episode prep and recording, this one did take quite a while. Mostly it was waiting for AWS to do its stuff, fixing and then waiting for AWS to do its stuff.
FYI to all, if you want to set up a swapfile, because you're using a small instance and not much RAM is available, you can create one when the VM is getting provisioned. I actually prefer to have a small swapfile in the event that my VM runs out of RAM, this would keep it from crashing. It is bad practice to rely on swap since it slows things down and is just overall bad practice, but it is much better than having the VM crash and die due to Out of Memory issues.
According to eb-engine.logs It seems like I don't have yarn. But when I do yarn --version on my machine it show:
$ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
Upon doing rails assets:precompile
rails assets:precompile
Traceback (most recent call last):
4: from /home/pop/.rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:22:in `<main>'
3: from /home/pop/.rvm/gems/ruby-2.7.2/bin/ruby_executable_hooks:22:in `eval'
2: from /home/pop/.rvm/gems/ruby-2.7.2/bin/yarn:23:in `<main>'
1: from /home/pop/.rvm/gems/ruby-2.7.2/gems/bundler-2.2.11/lib/bundler/rubygems_integration.rb:390:in `block in replace_bin_path'
/home/pop/.rvm/gems/ruby-2.7.2/gems/bundler-2.2.11/lib/bundler/rubygems_integration.rb:362:in `block in replace_bin_path': can't find executable yarn for gem yarn. yarn is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
Exiting!
What could be the problem? As is it not letting me deploy?
☒ Try running the yarn commands manually in the EC2 instance. I'm also a bit confused. What is this pop user? Are you trying to do this within Beanstalk's EC2 instance or on your local host machine?
☒ Your rails ver is 6.1.3 and my rails app is 5.2.0. By setting Rails_SKIP_MIGRATION = true I no more get asset precompile error. Also, it doesn't show root behind config folder . I'm a IAM user is that an issue?
or.
-sh-4.2$ cd .bundle/
-sh-4.2$ ls
config
-sh-4.2$ ls -lh
total 4.0K
-rw-r--r-- 1 webapp webapp 94 Mar 3 07:58 config
-sh-4.2$ cat config
---
BUNDLE_DEPLOYMENT: "true"
BUNDLE_PATH: "vendor/bundle"
BUNDLE_WITHOUT: "test:development"
-sh-4.2$
$ node -v
v14.16.0
$ yarn -v
1.22.5
$ rails assets:precompile
Warning: the running version of Bundler (2.1.4) is older than the version that created the lockfile (2.2.11). We suggest you to upgrade to the version that created the lockfile by running `gem install bundler:2.2.11`.
Compiling...
Compilation failed:
yarn run v1.22.5
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command "webpack" not found.
Thank you for the support man! I have resolved the assets issue. Now Iam just stuck on db part. Some help on this one would be highly appreciated thanks in advance.
[rake tasks]. Stop running the command. Error: running rake task db:migrate failed with error command bundle exec rake db:migrate failed with error Command /bin/su webapp -c bundle exec rake db:migrate failed with error exit status 1. Stderr:rake aborted! PG::ConnectionBad: could not translate host name "xxxxxxxxxxxxxxxxxxx1.rds.amazonaws.com:5432" to address: Name or service not known
☒ I haven't looked much into this, but with AL2, my guess would be to use the Procfile to declare the service to run. I would probably also look at running the Worker environment type instead of a Web worker. The rest of the config should be pretty similar
Hi David, thanks for the work you do with this platform.
- Bundle is not working for me. I have created .bundle/config but it is not being recognized as any change i make to it doesn't show in the terminal for me to commit. bash: rails: command not found" what i got when I do rails -v
- Also how can I fix the virtual memory exhausted: Cannot allocate memory
☒ That is a pretty annoying error. You can enable Swap memory on the VM which will prevent things from crashing. This will create a 4GB Swapfile and enable it.
Side note: People say that enabling Swap in production is horrible and bad practices. My take is that it's bad practice to have your app "randomly" crash and take down the site. Have proper monitoring in place for when you're approaching OOM and hitting swap and address the issues, but don't let the server crash.
☒ Do you have any kind of configurations for web_console? You may want to wrap those in a conditional block
unless Rails.env.production?
On one of your screenshots, it looks like it's getting referenced somewhere, but when beanstalk does the deployments, it's excluding the development and test gems.
It also looks like at one point the bundler gem isn't installed when it's trying to do something. In the same place where you created the swap, also add a line for bundler.
☒ I haven't tried deploying separate EC2 instances in the same environment but running different commands (rails app and then another set of instances running sidekiq). My thought is that this would go against their best practices as it could eventually lead to some issues with the load balancer. The health checks that occur will test to see if a EC2 instance is healthy or not and this could end up causing your background workers to die often.
You're probably best off creating a separate worker environment but use the same database. In these cases where you have two different environments for the same application, I would create the database separately from Beanstalk and make the appropriate routings.
For deploying to these two different environments, I would create a bin/deploy function. That way, you have one command that will deploy to both environments.
Hi David, This video was so helpful. I am still struggling though, as I'm deploying sidekiq and running into issues. Could you do a video on that or even share in the comments what way you set it up to run on your own instance.
What issues are you experiencing with Sidekiq? ☒ ? What does your infrastructure look like? I actually cheated a bit with my instance and actually run Sidekiq on the web servers. It's not best practices, but it works. If you were to separate out the sidekiq from the web servers, you'd create a separate application within your environment.
These update tips were fantastic, but they took a lot of work and a lot!
Thanks for your effort
What could be the problem? As is it not letting me deploy?
Also, it doesn't show root behind config folder . I'm a IAM user is that an issue?
PG::ConnectionBad: could not translate host name "xxxxxxxxxxxxxxxxxxx1.rds.amazonaws.com:5432" to address: Name or service not known
Some of your videos have black, flickering cuts (I think when you cut over to corrected code version) which are really annoying.
Thanks, Sven
- Bundle is not working for me. I have created .bundle/config but it is not being recognized as any change i make to it doesn't show in the terminal for me to commit.
bash: rails: command not found" what i got when I do rails -v
- Also how can I fix the virtual memory exhausted: Cannot allocate memory
Side note: People say that enabling Swap in production is horrible and bad practices. My take is that it's bad practice to have your app "randomly" crash and take down the site. Have proper monitoring in place for when you're approaching OOM and hitting swap and address the issues, but don't let the server crash.
I want to run sidekiq on separate ec2 instance but in the same environment as web , then what can we do for this?
On one of your screenshots, it looks like it's getting referenced somewhere, but when beanstalk does the deployments, it's excluding the development and test gems.
It also looks like at one point the bundler gem isn't installed when it's trying to do something. In the same place where you created the swap, also add a line for bundler.
You're probably best off creating a separate worker environment but use the same database. In these cases where you have two different environments for the same application, I would create the database separately from Beanstalk and make the appropriate routings.
For deploying to these two different environments, I would create a bin/deploy function. That way, you have one command that will deploy to both environments.
For connecting to a RDS database outside of the beanstalk network
https://www.driftingruby.com/episodes/aws-security-groups-and-deploying-rails-6-to-beanstalk
For creating bin functions
https://www.driftingruby.com/episodes/bin-functions
You'd need to set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in the runner's environment variables. Hope this helps!
This video was so helpful.
I am still struggling though, as I'm deploying sidekiq and running into issues. Could you do a video on that or even share in the comments what way you set it up to run on your own instance.
Thanks,
Gerard
This is my setup:
RAILS_TEST_KEY: ${{ secrets.RAILS_TEST_KEY }}
Do I need to have this in my environments/test.rb for this to work?
config.require_test_key = true