rcoproc PRO said over 2 years ago on Deploying to Amazon Linux 2 :
David Congratulations ..
These update tips were fantastic, but they took a lot of work and a lot!

David Kimura PRO said over 2 years ago on Deploying to Amazon Linux 2 :
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.

Marco De Rossi said over 2 years ago on Deploying to Amazon Linux 2 :
Nice Video. This is just too complicated just to deploy a rails app. I Hope Amazon makes this process simple just like Heroku.
Thanks for your effort 

David Kimura PRO said over 2 years ago on Deploying to Amazon Linux 2 :
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.

# .ebextensions/swap.config
commands:
  000_swap:
    ignoreErrors: true
    test: test ! -f /swapfile
    command: dd if=/dev/zero of=/swapfile bs=1M count=4096 && mkswap /swapfile && swapon /swapfile


bonapa1856 said over 2 years ago on Deploying to Amazon Linux 2 :
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?

David Kimura PRO said over 2 years ago on Deploying to Amazon Linux 2 :
  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?

sudo curl --silent --location https://rpm.nodesource.com/setup_14.x | sudo bash -
sudo yum -y install nodejs

sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
sudo yum -y install yarn




bonapa1856 said over 2 years ago on Deploying to Amazon Linux 2 :
  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$ 

David Kimura PRO said over 2 years ago on Deploying to Amazon Linux 2 :
WIthin the EC2 instance, what do you get when you run yarn -v?

bonapa1856 said over 2 years ago on Deploying to Amazon Linux 2 :
  Ya Yarn is there.

[ec2-user@ip-172-31-28-237 ~]$ yarn -v
1.22.5

David Kimura PRO said over 2 years ago on Deploying to Amazon Linux 2 :
When you run the below, what returns?
RAILS_ENV=production bundle exec rake assets:precompile


bonapa1856 said over 2 years ago on Deploying to Amazon Linux 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.


David Kimura PRO said over 2 years ago on Deploying to Amazon Linux 2 :
Try running yarn install to see what happens

bonapa1856 said over 2 years ago on Deploying to Amazon Linux 2 :
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




David Kimura PRO said over 2 years ago on Deploying to Amazon Linux 2 :
  Try without the :5432. I know in the episode, I had it showed, but did end up removing it.

sreuter PRO said about 2 years ago on Deploying to Amazon Linux 2 :
I would like to see another player for your casts. Your's is really bad with AirPlay screen mirroring :-(

Some of your videos have black, flickering cuts (I think when you cut over to corrected code version) which are really annoying.

Thanks, Sven

David Kimura PRO said about 2 years ago on Deploying to Amazon Linux 2 :
  I'll see if I can add in an AirPlay button. Is that sufficient? I'd imagine that screen mirroring may not always be the best experience.

stevepsharpe PRO said about 2 years ago on Deploying to Amazon Linux 2 :
  Do you have any guides/videos or pointers of how to run Sidekiq in it's own beanstalk env, separate from the main web app?

David Kimura PRO said about 2 years ago on Deploying to Amazon Linux 2 :
  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 

stevepsharpe PRO said about 2 years ago on Deploying to Amazon Linux 2 :
I'll check it out, thanks   

RANDY CAIQUO said about 2 years ago on Deploying to Amazon Linux 2 :
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





David Kimura PRO said about 2 years ago on Deploying to Amazon Linux 2 :
  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. 

# .ebextensions/swap.config
commands:
  000_swap:
    ignoreErrors: true
    test: test ! -f /swapfile
    command: dd if=/dev/zero of=/swapfile bs=1M count=4096 && mkswap /swapfile && swapon /swapfile

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.

Lakshya Gupta said about 2 years ago on Deploying to Amazon Linux 2 :
Hi David

I want to run sidekiq on separate ec2 instance but in the same environment as web , then what can we do for this?

RANDY CAIQUO said about 2 years ago on Deploying to Amazon Linux 2 :
David, thanks for the quick response, the Swap work! 
But still having issues with bundler and been trying a lot of suggested solutions but can't get it to work. Not sure if the .bundle is working

We have been using ruby -2.6.6 and AWA platform ruby -2.6 but upgraded app to ruby 2.7.3 and deploying to a new AWS environment with ruby 2.7 Linux 2


David Kimura PRO said about 2 years ago on Deploying to Amazon Linux 2 :
  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.

commands:
  000_swap:
    ignoreErrors: true
    test: test ! -f /swapfile
    command: dd if=/dev/zero of=/swapfile bs=1M count=4096 && mkswap /swapfile && swapon /swapfile
  000_bundler:
    ignoreErrors: true
    command: gem install bundler -v 2.2.16

David Kimura PRO said about 2 years ago on Deploying to Amazon Linux 2 :
  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.

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

jose.esmerino said over 1 year ago on Deploying to Amazon Linux 2 :
 Hi, is it on way, as you know, deploy from gitlab to beanstalk?

David Kimura PRO said over 1 year ago on Deploying to Amazon Linux 2 :
  jose.esmerino Here's what I use in my gitlab-ci.yml file for deploying from the gitlab runner to a production Elastic Beanstalk environment.

You'd need to set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in the runner's environment variables. Hope this helps!

stages:
  - production

production:
  image: python:latest
  variables:
    DEBIAN_FRONTEND: noninteractive
    AWS_DEFAULT_REGION: "REGION" # <= CHANGE ME
    EB_APP_NAME: "APPNAME" # <= CHANGE ME
    EB_APP_ENV: "ENVNAME" # <= CHANGE ME
  stage: production
  when: manual
  before_script:
    - apt update
    - apt install curl awscli -y
    - pip install awsebcli --upgrade --user
    - export PATH=~/.local/bin:$PATH
  script:
    - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
    - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
    # - export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID <= if aws config set doesn't work
    # - export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
    - eb deploy YOUR_APP_HERE --timeout 30  # <= CHANGE ME
  only:
    - main

gerard.donnelly said over 1 year ago on Deploying to Amazon Linux 2 :
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. 

Thanks, 

Gerard

David Kimura PRO said over 1 year ago on Deploying to Amazon Linux 2 :
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.

brian PRO said 9 months ago on Deploying to Amazon Linux 2 :
Quick question on using different environment credentials. I am using GitHub Actions with my Test key, but GitHub can't find it?

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


Login to Comment