- Add note on deploying a CLI project

- Fix error when a project without dependencies (and lock file) is deployed
This commit is contained in:
Sander van der Burg 2017-08-17 22:03:30 +02:00
parent def3501b91
commit b12373a127
2 changed files with 42 additions and 20 deletions

View file

@ -1,6 +1,6 @@
composer2nix composer2nix
============ ============
`composer2nix` is a tool that can be used to generate [Nix](http://nixos.org) `composer2nix` is a tool that can be used to generate [Nix](http://nixos.org/nix)
expressions for PHP [composer](https://getcomposer.org) packages. expressions for PHP [composer](https://getcomposer.org) packages.
Nix integration makes it possible to use the Nix package manager (as opposed to Nix integration makes it possible to use the Nix package manager (as opposed to
@ -29,10 +29,10 @@ including its dependencies:
$ nix-build $ nix-build
An example use case scenario Deploying a web application project
============================ -----------------------------------
We can use `composer2nix` to automate the deployment of a web application as We can use `composer2nix` to automate the deployment of a web application project
part of a NixOS configuration. as part of a NixOS configuration.
For example, we can create the following trivial PHP web application For example, we can create the following trivial PHP web application
(`index.php`) that uses the [dompdf](http://dompdf.github.io/) library to (`index.php`) that uses the [dompdf](http://dompdf.github.io/) library to
@ -82,9 +82,11 @@ application and its dependencies.
We can use Nix to build a bundle of our web application including its We can use Nix to build a bundle of our web application including its
dependencies: dependencies:
```bash
$ nix-build $ nix-build
$ ls result/ $ ls result/
index.php vendor/ index.php vendor/
```
(As may be observed, the `vendor/` folder contains all dependency artifacts). (As may be observed, the `vendor/` folder contains all dependency artifacts).
@ -115,17 +117,32 @@ in
We can deploy the above NixOS configuration as follows: We can deploy the above NixOS configuration as follows:
$ nixos-rebuild switch ```bash
$ nixos-rebuild switch
```
If the above command succeeds, we have a running system with the Apache If the above command succeeds, we have a running system with the Apache
webserver serving our web application. webserver serving our web application.
Deploying a command-line utility project
----------------------------------------
In addition to web applications, we can also deploy command-line utility
projects implemented in PHP.
For example, for the `composer2nix` project, we can generate a CLI-specific
expression by adding the `--executable` parameter:
$ composer2nix --executable
We can install the `composer2nix` executable in our Nix profile by running:
$ nix-env -f default.nix -i
Limitations Limitations
=========== ===========
Currently, the state of this tool is that it is just a proof on concept Currently, the state of this tool is that it is just a proof on concept
implementation. As a result, it is lacking many features and probably buggy. implementation. For example, it does not support downloading from `fossil`
Most importantly, only the `path`, `zip`, `git`, and `hg` dependencies are repositories.
supported.
License License
======= =======

View file

@ -57,19 +57,24 @@ rec {
text = '' text = ''
#! ${php}/bin/php #! ${php}/bin/php
<?php <?php
$composerLockStr = file_get_contents($argv[1]); if(file_exists($argv[1]))
if($composerLockStr === false)
{ {
fwrite(STDERR, "Cannot open composer.lock contents\n"); $composerLockStr = file_get_contents($argv[1]);
exit(1);
if($composerLockStr === false)
{
fwrite(STDERR, "Cannot open composer.lock contents\n");
exit(1);
}
else
{
$config = json_decode($composerLockStr);
$packagesStr = json_encode($config->packages, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
print($packagesStr);
}
} }
else else
{ print("[]");
$config = json_decode($composerLockStr);
$packagesStr = json_encode($config->packages, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
print($packagesStr);
}
?> ?>
''; '';
}; };
@ -170,7 +175,7 @@ rec {
${stdenv.lib.optionalString (removeComposerArtifacts) '' ${stdenv.lib.optionalString (removeComposerArtifacts) ''
# Remove composer stuff # Remove composer stuff
rm composer.json composer.lock rm -f composer.json composer.lock
''} ''}
''; '';
}; };