Sand Fox (Posts about composer)https://sandfox.me/tags/composer.xml2024-03-25T17:50:27ZAnton SmirnovNikolaInstalling Composer in Docker the 2020-s Wayhttps://sandfox.me/php/install-composer-in-docker-2.html2023-01-11T10:14:00+02:002023-01-11T10:14:00+02:00Anton Smirnov<p>While <a class="reference external" href="https://sandfox.me/php/install-composer-in-docker.html">the original way</a> is still valid, in Docker it's now easier to copy the Composer executable from its Docker image.</p>
<div class="code"><pre class="code docker"><a id="rest_code_db28e163bd9f424d955ae8b85d8794a8-1" name="rest_code_db28e163bd9f424d955ae8b85d8794a8-1" href="https://sandfox.me/php/install-composer-in-docker-2.html#rest_code_db28e163bd9f424d955ae8b85d8794a8-1"></a><span class="k">COPY</span><span class="w"> </span>--from<span class="o">=</span>composer:latest<span class="w"> </span>/usr/bin/composer<span class="w"> </span>/usr/local/bin/composer
</pre></div>
<p>or for PHP < 7.2.5</p>
<div class="code"><pre class="code docker"><a id="rest_code_f7347ac4431e47f4ae9d679e8c748f3a-1" name="rest_code_f7347ac4431e47f4ae9d679e8c748f3a-1" href="https://sandfox.me/php/install-composer-in-docker-2.html#rest_code_f7347ac4431e47f4ae9d679e8c748f3a-1"></a><span class="k">COPY</span><span class="w"> </span>--from<span class="o">=</span>composer:2.2<span class="w"> </span>/usr/bin/composer<span class="w"> </span>/usr/local/bin/composer
</pre></div>
<p>Please note that without the installer, dependencies won't be checked, so you also need to install git and/or zip,
and preferably optional dependencies like mbstring too.</p>
<p>Found accidentally <a class="reference external" href="https://stackoverflow.com/a/58694421">on the Stack Overflow</a>.
There is also <a class="reference external" href="https://stackoverflow.com/a/68600278">another interesting and underliked method</a> for the case
when you don't want to keep the composer executable and cache files in your image.</p>License Manager for Composerhttps://sandfox.me/php/composer-license-manager.html2022-06-22T02:12:00+03:002022-06-22T02:12:00+03:00Anton Smirnov<p>I found myself in a need to filter away some licenses for my dependencies (AGPL, I'm looking at you).
I've found a well known plugin for that: <a class="reference external" href="https://packagist.org/packages/metasyntactical/composer-plugin-license-check">metasyntactical/composer-plugin-license-check</a>.</p>
<p>The problem that I found with it is that it doesn't prevent you from installing blacklisted packages.
I mean it was designed to do that but fails on Composer 2.0+.</p>
<p>I started investigating for the ways to fix that but ended up with a feature complete plugin.
It also offers some more flexibility in the config.</p>
<p>Grab it here: <a class="reference external" href="https://sandfox.dev/php/composer-license-manager.html">https://sandfox.dev/php/composer-license-manager.html</a></p>Install Composer in Dockerhttps://sandfox.me/php/install-composer-in-docker.html2023-01-11T10:14:00+02:002020-04-02T11:26:00+03:00Anton Smirnov<div><aside class="admonition note">
<p class="admonition-title">Note</p>
<p>You can still use it to install Composer programmatically but for Docker there is <a class="reference external" href="https://sandfox.me/php/install-composer-in-docker-2.html">an easier way now</a></p>
</aside>
<p>Here is a small snippet adapted from the <a class="reference external" href="https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md">official instruction</a>:</p>
<div class="code"><pre class="code docker"><a id="rest_code_fd18ad11a27f41e781f79207354497c7-1" name="rest_code_fd18ad11a27f41e781f79207354497c7-1" href="https://sandfox.me/php/install-composer-in-docker.html#rest_code_fd18ad11a27f41e781f79207354497c7-1"></a><span class="k">RUN</span><span class="w"> </span>php<span class="w"> </span>-r<span class="w"> </span><span class="s2">"copy('https://composer.github.io/installer.sig', '/tmp/composer.sig');"</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="se">\</span>
<a id="rest_code_fd18ad11a27f41e781f79207354497c7-2" name="rest_code_fd18ad11a27f41e781f79207354497c7-2" href="https://sandfox.me/php/install-composer-in-docker.html#rest_code_fd18ad11a27f41e781f79207354497c7-2"></a><span class="w"> </span>php<span class="w"> </span>-r<span class="w"> </span><span class="s2">"copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');"</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="se">\</span>
<a id="rest_code_fd18ad11a27f41e781f79207354497c7-3" name="rest_code_fd18ad11a27f41e781f79207354497c7-3" href="https://sandfox.me/php/install-composer-in-docker.html#rest_code_fd18ad11a27f41e781f79207354497c7-3"></a><span class="w"> </span>php<span class="w"> </span>-r<span class="w"> </span><span class="s1">'$expected = file_get_contents("/tmp/composer.sig"); $actual = hash_file("sha384", "/tmp/composer-setup.php"); exit(intval(!hash_equals($expected, $actual)));'</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="se">\</span>
<a id="rest_code_fd18ad11a27f41e781f79207354497c7-4" name="rest_code_fd18ad11a27f41e781f79207354497c7-4" href="https://sandfox.me/php/install-composer-in-docker.html#rest_code_fd18ad11a27f41e781f79207354497c7-4"></a><span class="w"> </span>php<span class="w"> </span>/tmp/composer-setup.php<span class="w"> </span>--install-dir<span class="o">=</span>/usr/local/bin<span class="w"> </span>--filename<span class="o">=</span>composer<span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="se">\</span>
<a id="rest_code_fd18ad11a27f41e781f79207354497c7-5" name="rest_code_fd18ad11a27f41e781f79207354497c7-5" href="https://sandfox.me/php/install-composer-in-docker.html#rest_code_fd18ad11a27f41e781f79207354497c7-5"></a><span class="w"> </span>chmod<span class="w"> </span>+x<span class="w"> </span>/usr/local/bin/composer<span class="w"> </span><span class="o">&&</span><span class="w"> </span><span class="se">\</span>
<a id="rest_code_fd18ad11a27f41e781f79207354497c7-6" name="rest_code_fd18ad11a27f41e781f79207354497c7-6" href="https://sandfox.me/php/install-composer-in-docker.html#rest_code_fd18ad11a27f41e781f79207354497c7-6"></a><span class="w"> </span>rm<span class="w"> </span>/tmp/composer-setup.php<span class="w"> </span>/tmp/composer.sig
</pre></div>
<p>It doesn't require a script file, doesn't deal with environment variables, and doesn't depend on the shell.</p>
<p><a href="https://sandfox.me/php/install-composer-in-docker.html">Read more…</a> (1 min remaining to read)</p></div>Composer Yamlhttps://sandfox.me/php/composer-yaml.html2019-04-19T22:00:00+03:002019-04-19T22:00:00+03:00Anton Smirnov<p>My new library to allow composer to read config from YAML file.
There is some demand in comments for composer config but <a class="reference external" href="https://github.com/composer/composer/issues/440">the developers are not interested</a>
and most 3rd party attempts to solve it are limited to yaml2json converters.</p>
<p>I tried a slightly different approach.
There is a command in the composer itself that changes the way the config is read: <code class="docutils literal">composer global</code>.
During its execution it changes current working directory, resets composer state, and forces the composer
to read config from another directory.</p>
<p>What I tried to do:
I put yaml2json converter in place of <code class="docutils literal">global</code>'s directory changing code, and it seems it worked.
Of course, some things got broken like any command that tries to change composer.json will no longer have any effect,
however many people don't use them and it may be an acceptable tradeoff for using yml-based config.</p>
<p>You can find the project on my new dev website: <a class="reference external" href="https://sandfox.dev/php/composer-yaml.html">https://sandfox.dev/php/composer-yaml.html</a></p>Private Composer Repo with GitLab and Satishttps://sandfox.me/php/satis-gitlab.html2019-02-19T14:06:00+02:002018-03-09T16:44:00+02:00Anton Smirnov<div><p>You can easily create your own composer repository using Satis and GitLab.
I will use global <a class="reference external" href="https://gitlab.com">https://gitlab.com</a> but it should be most useful for private corporate GitLab installations.
You will need CI and Pages</p>
<p><a href="https://sandfox.me/php/satis-gitlab.html">Read more…</a> (1 min remaining to read)</p></div>Composer Vizhttps://sandfox.me/php/composer-viz.html2017-08-06T12:12:00+03:002017-08-06T12:12:00+03:00Anton Smirnov<p>A tool inspired by <a class="reference external" href="https://bundler.io/v1.3/bundle_viz.html"><code class="docutils literal">bundle viz</code> command</a>.</p>
<p>Just look at its selfie:</p>
<p><img alt="selfie" class="invert-when-dark" src="https://sandfox.me/images/php/composer-viz/selfie.svg" style="width: 100%;"></p>
<p>Get it on my dev site: <a class="reference external" href="https://sandfox.dev/php/composer-viz.html">https://sandfox.dev/php/composer-viz.html</a></p>