- Add note on deploying a CLI project
- Fix error when a project without dependencies (and lock file) is deployed
This commit is contained in:
parent
def3501b91
commit
b12373a127
2 changed files with 42 additions and 20 deletions
35
README.md
35
README.md
|
@ -1,6 +1,6 @@
|
|||
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.
|
||||
|
||||
Nix integration makes it possible to use the Nix package manager (as opposed to
|
||||
|
@ -29,10 +29,10 @@ including its dependencies:
|
|||
|
||||
$ nix-build
|
||||
|
||||
An example use case scenario
|
||||
============================
|
||||
We can use `composer2nix` to automate the deployment of a web application as
|
||||
part of a NixOS configuration.
|
||||
Deploying a web application project
|
||||
-----------------------------------
|
||||
We can use `composer2nix` to automate the deployment of a web application project
|
||||
as part of a NixOS configuration.
|
||||
|
||||
For example, we can create the following trivial PHP web application
|
||||
(`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
|
||||
dependencies:
|
||||
|
||||
```bash
|
||||
$ nix-build
|
||||
$ ls result/
|
||||
index.php vendor/
|
||||
```
|
||||
|
||||
(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:
|
||||
|
||||
$ nixos-rebuild switch
|
||||
```bash
|
||||
$ nixos-rebuild switch
|
||||
```
|
||||
|
||||
If the above command succeeds, we have a running system with the Apache
|
||||
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
|
||||
===========
|
||||
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.
|
||||
Most importantly, only the `path`, `zip`, `git`, and `hg` dependencies are
|
||||
supported.
|
||||
implementation. For example, it does not support downloading from `fossil`
|
||||
repositories.
|
||||
|
||||
License
|
||||
=======
|
||||
|
|
|
@ -57,19 +57,24 @@ rec {
|
|||
text = ''
|
||||
#! ${php}/bin/php
|
||||
<?php
|
||||
$composerLockStr = file_get_contents($argv[1]);
|
||||
|
||||
if($composerLockStr === false)
|
||||
if(file_exists($argv[1]))
|
||||
{
|
||||
fwrite(STDERR, "Cannot open composer.lock contents\n");
|
||||
exit(1);
|
||||
$composerLockStr = file_get_contents($argv[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
|
||||
{
|
||||
$config = json_decode($composerLockStr);
|
||||
$packagesStr = json_encode($config->packages, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
print($packagesStr);
|
||||
}
|
||||
print("[]");
|
||||
?>
|
||||
'';
|
||||
};
|
||||
|
@ -170,7 +175,7 @@ rec {
|
|||
|
||||
${stdenv.lib.optionalString (removeComposerArtifacts) ''
|
||||
# Remove composer stuff
|
||||
rm composer.json composer.lock
|
||||
rm -f composer.json composer.lock
|
||||
''}
|
||||
'';
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue