Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced config leads to error #167

Closed
c33s opened this issue Apr 27, 2018 · 9 comments
Closed

Reduced config leads to error #167

c33s opened this issue Apr 27, 2018 · 9 comments
Milestone

Comments

@c33s
Copy link

c33s commented Apr 27, 2018

compactors:
   - Herrera\Box\Compactor\Json
   - Herrera\Box\Compactor\Php
compression: GZ
output: build/puppet-enc.phar
git-commit: git_commit
git-version: git_version
git-tag: git_tag
chmod: '0755'

->

{
    "compactors": [
        "Herrera\\Box\\Compactor\\Json",
        "Herrera\\Box\\Compactor\\Php"
    ],
    "compression": "GZ",
    "output": "build/puppet-enc.phar",
    "git-commit": "git_commit",
    "git-version": "git_version",
    "git-tag": "git_tag",
    "chmod": "0755"
}

->

 [ERROR] The configuration file is invalid.

In Assertion.php line 283:

  [_HumbugBox5adef95163555\Assert\InvalidArgumentException (102)]
  File "puppet-enc/index.php" was expected to exist.
@theofidry
Copy link
Member

Are you sure you are on the latest version? Otherwise make sure your bin file bin/puppet-enc is registered in the composer.json file:

{
  "bin": ["bin/puppet-enc"]
}

@c33s
Copy link
Author

c33s commented Apr 27, 2018

box version 3.0.0-alpha.3

adding the section to my composer.yml takes the process further. it finished compiling

The directory name is invalid.
* Building the PHAR "puppet-enc/build/puppet-enc.phar"
? Setting replacement values
  + @git_commit@: 5f620495beb07c9304e4bd88dafa11e45224b1c5
  + @git_tag@: 1.0.1
  + @git_version@: 1.0.1
? Registering compactors
  + KevinGH\Box\Compactor\Json
  + KevinGH\Box\Compactor\Php
? Adding main file: puppet-enc/bin/puppet-enc
? Adding requirements checker
? Adding binary files
    > No file found
? Adding files

The directory name is invalid. i see often, also on successful builds

building the phar with the reduced config leads to a broken phar now:

php build/puppet-enc.phar foo.example.com --env=prod --file=nodes.yaml.dist
��/�(��*J-)-�S��
��M�ϫ�q*�K�I�q+J�M-�/��η�J�I,.V��S�VO��Q�J�JScu�M������O���gJ�5 \u��N�0 �w���� � BUںiDbWN�Syz\(� q^ �� �Nd���<��`� (��[-ZO��Z^F4����0�< �
Warning: Invalid argument supplied for foreach() in phar://puppet-enc/build/puppet-enc.phar/src/Kernel.php on line 45

Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\LogicException: Container extension "framework" is not registered in phar://puppet-enc/build/puppet-enc.phar/vendor/symfony/dependency-injection/ContainerBuilder.php:200
Stack trace:
#0 phar://puppet-enc/build/puppet-enc.phar/vendor/symfony/dependency-injection/ContainerBuilder.php(417): Symfony\Component\DependencyInjection\ContainerBuilder->getExtension('framework')
#1 phar://puppet-enc/build/puppet-enc.phar/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php(66): Symfony\Component\DependencyInjection\ContainerBuilder->loadFromExtension('framework', Array)
#2 [internal function]: App\Kernel->Symfony\Bundle\FrameworkBundle\Kernel\{closure}(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#3 phar://puppet-enc/build/puppet-enc. in phar://puppet-enc/build/puppet-enc.phar/vendor/symfony/dependency-injection/ContainerBuilder.php on line 200

maybe related with symfony/symfony#26845
my config component is patched before i run compile but i wasn't able to get it to work compiling a simple symfony4 app with twig. i always ran into missing files (which should be there because of prewarming and adding the cache to the phar)

havn't tried it with this box 3.x will try it as soon as the small problems i currently have are fixed

@theofidry
Copy link
Member

The directory name is invalid. i see often, also on successful builds

If you have any info/reproducer about it that would be very helpful.

my config component is patched before i run compile but i wasn't able to get it to work compiling a simple symfony4 app with twig. i always ran into missing files (which should be there because of prewarming and adding the cache to the phar)

It is also possible that the default config doesn't cut it. It has been designed to infer as much info as possible from the composer.json but some frameworks like Symfony have more specific stuff, e.g. the var/cache. In those cases you may indeed need to fallback to a more explicit file declaration. Note however that you then don't benefit from the removing of useless CI/doc/test files (unless you do it yourself) but you do still benefit of the removal of the dev package files

@theofidry
Copy link
Member

Just thought of it, could it also be that the application is executed in the wrong environment? I.e. when booting inside the PHAR, it detects that the dumped container is outdated and tries to dump it again

@c33s
Copy link
Author

c33s commented Apr 28, 2018

don't think so.

env in the puppet-enc is hardcoded (if phar do not use env, if env is not set use prod)

if (!isset($_SERVER['APP_ENV']) && strlen(Phar::running()) == 0) {
    if (!class_exists(Dotenv::class)) {
        throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
    }
    (new Dotenv())->load(__DIR__.'/../.env');
}

$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'prod', true);

and this is my "makefile"

$this->_exec('composer install --optimize-autoloader');
$this->_exec('git apply patches/allow-config-loading-from-phar.patch');
$this->_exec('php bin/console cache:clear --env=prod');
$this->_exec('php bin/console cache:warmup --env=prod');
$this->_exec('php bin/console enc foo.example.com --env=prod --file=nodes.yaml.dist');
$this->_exec('box build --no-parallel -vvv');
$this->_exec('php build/puppet-enc.phar foo.example.com --env=prod --file=nodes.yaml.dist');

@jaapio
Copy link

jaapio commented May 1, 2018

I have exactly the same issue in phpdocumentor for some reason the files contain some of my source classes are missing. I have warmed my cache before building the phar

{
    "main": "bin/phpdoc",
    "output": "phpDocumentor.phar",
    "files": [
        "config/bundles.php",
        "VERSION"
    ],
    "directories-bin": [
        "data",
        "var/cache/prod"
    ],
    "git-version": "package_version",
    "chmod": "0755",
    "compression": "GZ",
    "compactors": [
        "Herrera\\Box\\Compactor\\Json",
        "Herrera\\Box\\Compactor\\Php"
    ]
}

Classes that are missing:

  • \phpDocumentor\Descriptor\Builder\Reflector\Tags\AuthorAssembler
  • \phpDocumentor\Descriptor\Tag\AuthorDescriptor

But other classes in the same namespace are in?

@theofidry
Copy link
Member

Oh I see. I think this is due to a feature of Box: it tries to be smart and exclude the useless files when you let Box pick up the files, see the code here. However I found out when trying to build the PHAR for PHP-CS-Fixer that it excludes too much files, like here AuthorAssembler.php because it has Author in the name.

I'll submit a patch for it ASAP, it's kinda ready but I would like to add more tests to ensure not too many files are excluded. I'll cc you in the PR so that you can check it in case you find some cases I might have missed

@jaapio
Copy link

jaapio commented May 1, 2018

I would be happy to help you out with a PR, however I'm not sure how to fix this in the right way.
This issue is kind of blocking for phpdocumentor at the moment. Is there a work around?

@theofidry
Copy link
Member

The most immediate workaround I think is to not let Box pick the files for you, so you would need to specify the file to includes using the directory and/or finder settings, see that doc entry for more info.

theofidry added a commit to theofidry/box that referenced this issue May 3, 2018
The finder configuration was wrongly excluding some legitimate files.

Closes box-project#167
theofidry added a commit that referenced this issue May 3, 2018
The finder configuration was wrongly excluding some legitimate files.

Closes #167
@theofidry theofidry added this to the 3.0.0 milestone May 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants