Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to precompile assets on AWS Elastic Beanstalk

2013-11-03 20:30:48,342 [INFO] (30173 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: /usr/bin/ruby1.9 /usr/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Command failed with status (): [/usr/bin/ruby1.9 /usr/bin/rake assets:prec...]

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
Rake task failed to run, skipping asset compilation.

How do I precompile assets on AWS Elastic Beanstalk ?

I am getting following error

like image 273
Hrishikesh Sardar Avatar asked Oct 03 '22 12:10

Hrishikesh Sardar


2 Answers

Precompilation of assets can be done at deployment time, and to do it, go to the root of your Rails project and create a .ebextensions directory with a .config file in it. You can specify precompilation there. I'm running a Rails app with Elastic Beanstalk and had problems with fonts not being shown. Here's my .ebextensions/ruby.config file:

packages:
  yum:
    git: []

container_commands:
  01_assets:
    command: RAILS_ENV=production bundle exec rake assets:precompile
    leader_only: true
like image 155
Jack Avatar answered Oct 13 '22 11:10

Jack


You can customise the system by running scripts before or after your application deployment. Basically, you need to create a .ebextensions directory in your source code and insert your commands and customisation steps in a YAML syntax.
The documentation explains the details.

Beware that these commands are run as 'root' with no environment variable setup. If you need variables like PATH or other, it is up to you to position them.

Here is a sample I wrote for an application which required a NodeJS module installation from the source.

packages:
   yum:
      gcc: []
      gcc-c++: []


container_commands:

   10_pre_install_sqlite3:
      command: "/opt/elasticbeanstalk/node-install/node-v0.10.21-linux-x64/bin/npm install [email protected] --build-from-source"
      cwd: "/tmp/deployment/application"
      env:
          HOME: "/root"
          PATH: "/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin"
like image 22
Sébastien Stormacq Avatar answered Oct 13 '22 10:10

Sébastien Stormacq