GithubHelp home page GithubHelp logo

Deploy on AWS Beanstalk about webpacker HOT 29 CLOSED

rails avatar rails commented on May 6, 2024 7
Deploy on AWS Beanstalk

from webpacker.

Comments (29)

damien-roche avatar damien-roche commented on May 6, 2024 20

Truly one of the most horrendous platforms. The solution: don't deploy to Beanstalk. Lost 2 days so far and not even precompiled assets.

from webpacker.

sealocal avatar sealocal commented on May 6, 2024 10

@hugodias This is the eb config I created.

.ebextensions/01_yarn.config:

files:
  # If this file is edited, it must be removed from EC2 instance prior to deploy.
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/09_yarn_install.sh" :
    mode: "000775"
    owner: root
    group: users
    content: |
      #!/usr/bin/env bash

      set -xe

      EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
      EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)

      echo "I am: `whoami`"
      echo "App user is $EB_APP_USER"

      # If yarn is not detected, install it.
      if which yarn; then
        echo "Skipping installation of yarn -- yarn already installed."
        echo "yarn --version: `yarn --version`"
      else
        echo "which yarn: `which yarn`"
        echo "Yarn is not installed and accessible."
        echo "Installing yarn..."
        # Consider that the EC2 instance is managed by AWS Elastic Beanstalk.
        # Changes made via SSH WILL BE LOST if the instance is replaced by auto-scaling.
        # QUESTION: Will this script be run on new instances that are created by auto-scaling?
        # QUESTION: Should installation be moved to a rake task?

        # Download the yarn repo
        sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
        # Confirm that it downloaded
        file /etc/yum.repos.d/yarn.repo

        # If node is not detected, install it.
        if [ `node --version` == 'v6.10.0' ]; then
          echo "Skipping installation of node -- node already installed."
          echo "node --version: `node --version`"
        else
          echo "Installing Node v6.10.0 ..."
          # Download the Node v6 setup script
          curl --location https://rpm.nodesource.com/setup_6.x > /home/ec2-user/node_install.sh
          # Confirm that it downloaded
          file /home/ec2-user/node_install.sh
          # Run the Node v6 setup script
          sudo bash /home/ec2-user/node_install.sh
          # Install nodejs
          sudo yum install -y nodejs
          node --version
          echo "... and finished installing Node v6.10.0"
        fi

        # install yarn
        sudo yum install -y yarn
        yarn --version

        echo "... and finished installing yarn."
      fi

      echo "Change directory to $EB_APP_STAGING_DIR"
      cd $EB_APP_STAGING_DIR

      # yarn install
      echo "Running yarn install."
      ./bin/yarn install

from webpacker.

gauravtiwari avatar gauravtiwari commented on May 6, 2024 9

@tetz2442 Guess you would need to tell rails to serve public files:

#Β in production.rb
config.public_file_server.enabled = true

from webpacker.

MSchmidt avatar MSchmidt commented on May 6, 2024 9

Since this was specifically about Elastic Beanstalk, you should actually set the RAILS_SERVE_STATIC_FILES environment variable.

eb setenv RAILS_SERVE_STATIC_FILES=enabled

from webpacker.

josephecombs avatar josephecombs commented on May 6, 2024 7

I actually made a mistake with that link - this is the full ebextensions file: https://github.com/shakacode/react_on_rails/blob/master/docs/additional-reading/elastic-beanstalk.md

from webpacker.

josephecombs avatar josephecombs commented on May 6, 2024 6

In case anyone else sees this, there is a good .ebextension listed here for resolving this issue:

https://github.com/shakacode/react_on_rails/blob/3269da94455813a4ebff49c6a95a623fdcc61713/docs/additional-reading/elastic-beanstalk.md

from webpacker.

sealocal avatar sealocal commented on May 6, 2024 3

@gauravtiwari @p0wl As it turns out, my problem was installing node as a dependency of yarn!

I used the .ebextensions files, but tweaked the yarn installation bash commands to install node with sudo, and it works!

Just leaving this here in case it helps someone else with AWS deployment.

from webpacker.

tetz2442 avatar tetz2442 commented on May 6, 2024 1

I'm also receiving 404s on webpack files when deploying to EB. From looking at the logs, it looks like webpacker is compiling just fine. Has anyone else run into this issue?

from webpacker.

tetz2442 avatar tetz2442 commented on May 6, 2024 1

@josephecombs I'm on rails 5.1. Everything is working fine, except for the webpack files. I reference files with <%= javascript_pack_tag 'editor' %>.

What's strange is the url it generates 404s, but if I add in /public before /packs like so /public/packs/editor-64ec86898e5722f4651f.js it works fine.

And this is only on EB, everything locally works fine.

from webpacker.

joshleichtung avatar joshleichtung commented on May 6, 2024 1

@tetz2442 I had the same issue. I think the problem is not with webpacker or rails, but with nginx static file serving settings. I fixed it by adding a location directive to the nginx config specifically mapping the /public/packs.

Here is the config file I added to the .ebextensions folder in the root of my app. Depending on how your Elastic Beanstalk instance is set up, you might need to make changes. Comments are in the file regarding important lines.

from webpacker.

tetz2442 avatar tetz2442 commented on May 6, 2024 1

Once I followed @gauravtiwari advice and told rails to serve public files, the pack files didn't 404 anymore

from webpacker.

ajsharp avatar ajsharp commented on May 6, 2024 1

I'd recently upgraded to rails 5.1, and I was getting this error message the Command "webpack" not found error message while building assets on elastic beanstalk. The issue for me was I had fsevents in my devDependencies, and for some reason that was breaking the build on AWS. I removed that from my dependencies and the build succeeded. Unfortunately that error message seems to be a catch-all, because webpack was installed on the system.

from webpacker.

pyrabbit avatar pyrabbit commented on May 6, 2024 1

I am not sure how relevant this is but I had to change the last line of .ebextensions/01_yarn.config: from ./bin/yarn install to yarn install. I noticed I didn't have a yarn binary in my applications bin folder and after running which yarn on my EC2 instance it was pointing at /usr/local/bin/yarn

from webpacker.

p0wl avatar p0wl commented on May 6, 2024

In my opinion yarn is a prerequisite for using webpacker (like nodejs), so you should install it in your app setup (e.g. dockerfile).

Otherwise, webpacker would have to detect how to install yarn on your system (which package manager to use, ...).

from webpacker.

sealocal avatar sealocal commented on May 6, 2024

I do not expect webpacker to implement installation of yarn, but just hoping that others who are looking to solve deployment with the same parameters will chime in here. I'll close the issue.

I'm not familiar with Docker, but I will take a look. Thanks!

from webpacker.

p0wl avatar p0wl commented on May 6, 2024

You can customize your elastic beanstalk app via .ebextensions, maybe http://stackoverflow.com/questions/41657226/customize-aws-elasticbeanstalk-nodejs-install-use-yarn helps =)

from webpacker.

sealocal avatar sealocal commented on May 6, 2024

Thank you, that is correct, but I have used and tweaked that script many times with no success.

from webpacker.

gauravtiwari avatar gauravtiwari commented on May 6, 2024

Great πŸ‘

from webpacker.

hugodias avatar hugodias commented on May 6, 2024

@sealocal can you share your .ebextensions file?

from webpacker.

sealocal avatar sealocal commented on May 6, 2024

@josephecombs Thanks for circling back to post that. I looked many times for something that used the command key - I will test out that approach on my setup when I have the opportunity.

from webpacker.

MatthiasRMS avatar MatthiasRMS commented on May 6, 2024

@sealocal @josephecombs I've tried both of your yarn config file, and it seems to work fine to install it. However, I still get a 404 when the app tries to fetch the packs. It looks like webpack-dev-server didn't start, so it doesn't serves the JS files to the app.
How did you start webpack-dev-server on elastic beanstalk ?

Thanks

from webpacker.

sealocal avatar sealocal commented on May 6, 2024

@MatthiasRMS webpack-dev-server is intended for use in development - it watches for changes in the javascript that you're building with webpack - e.g., if you change a line of code in a component. (see https://github.com/rails/webpacker#development).

If your'e seeing a 404 for a request to a pack, then your pack doesn't exist. It hasn't been successfully compiled via the webpack binstub. Check the activity logs just after you deploy.

from webpacker.

josephecombs avatar josephecombs commented on May 6, 2024

Are you on rails 5.1 @tetz2442? Are other assets being served fine? If so this seems like maybe a path reference issue, can you try referring to the packs in erb as, for example <%= stylesheet_pack_tag 'vendor_pack' %>

from webpacker.

sealocal avatar sealocal commented on May 6, 2024

It could be worth verifying that the pack is in the public directory, and double-check your choice to serve static assets from Rails.

from webpacker.

januszm avatar januszm commented on May 6, 2024

RAILS_SERVE_STATIC_FILES is absolutely not a solution in production environments, looks like your HTTP (nginx) server does not know about the location /packs. Default configuration includes the public assets location only.

Unfortunately, as usual with Elastic Beanstalk, you have to wait for platform updates, and before that happens, you can always use your own custom configuration using the .ebextensions

from webpacker.

ctrlaltdylan avatar ctrlaltdylan commented on May 6, 2024

I've been using EB with Rails & Webpacker for some time now, but it appears that my packs size has gotten to the point where it throttles the CPU on every deploy.

I'm going to look into Docker usage instead of .ebextensions, as well as having the CI handle the asset build process. It's just too much for even a t2-medium sitting at 5% CPU usage before deployment.

from webpacker.

rkiller avatar rkiller commented on May 6, 2024

@ctrlaltdylan I'm seeing the same but my pack size is not even that large. Deploying on a t2.medium is timing out the deployment process but ultimately deploys correctly...

from webpacker.

ctrlaltdylan avatar ctrlaltdylan commented on May 6, 2024

@rkiller since I wrote this comment I've switched to my CI handling the assets compilation & webpacking. That particular step still fails from time to time on a docker container, but at least it's not causing downtime on the EBS app.

from webpacker.

Shalashtein avatar Shalashtein commented on May 6, 2024

Since this was specifically about Elastic Beanstalk, you should actually set the RAILS_SERVE_STATIC_FILES environment variable.

eb setenv RAILS_SERVE_STATIC_FILES=enabled

I had it set to 'true', it didn't work till I set it to 'enabled'

from webpacker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.