4
votes

I have a problem with Symfony assets on heroku (official php buildpack). My code is based on Symfony 2.5 with new 3.0 folder structure, and it's using one local js and css file (the rest is loaded via cdn). Those files are loaded exactly as described here: http://symfony.com/doc/current/cookbook/assetic/asset_management.html.

On dev environment everything is ok, but when i change env to prod then i need to do assetic:dump to force symfony dump my assets files into web/css|js folders. I made test on my local machine (switching env to prod) and everything is ok. The problem is with heroku, and its ephemeral filesystem:

When I try to run assetic:dump --env=prod by composer post-install-cmd, then deploy finish with successs, but every request ends up with:

AH01071: Got error 'PHP message: PHP Fatal error: Uncaught exception
'InvalidArgumentException' with message 
'The file "/tmp/build_012d99e7-a14a-4626-afec-3ded3d4baeec/app/config/routing.yml"

When i deploy app without assetic:dump then of course my local css and js files are not available :/

Maybe there is some other script hook i can use to dump my assets?

Any ideas? Anyone succeded with assetic:dump on heroku and official php buildpack?

1

1 Answers

2
votes

PHP and Symfony support has been revamped a lot in the last months, check out these links:

What's most important:

Set an environment variable for SYMFONY_ENV

The value of SYMFONY_ENV is used to define the environment for CLI commands. So you don't have to fiddle about something like --env=prod in you custom commands. Composer hooks from composer.json (like post-install-cmd) are automatically executed with the defined environment. Please note: Set it to something different than dev. A dev environment may not work well on Heroku because Composer's dev dependencies (require-dev) are not installed. This is due to the --no-dev flag during the composer install on Heroku. For example, in the Symfony Standard Edition) the SensioGeneratorBundle never gets installed (if you do not move it to the require key in composer.json) and the dev environment won't work.

Error on /tmp path

The mentioned error should have been fixed with https://github.com/symfony/symfony/pull/12784. See also https://github.com/heroku/heroku-buildpack-php/issues/64.

Custom commands during deployment

Custom commands like assetic:dump can be placed in composer.json's script section under the compile key:

{
    "scripts": {
        "compile": [
          "app/console assetic:dump"
        ]
    }
}

See also https://devcenter.heroku.com/articles/php-support#custom-compile-step. Environment is taken from the above mentioned SYMFONY_ENV environment variable.