2012-04-13 10:13:52 +00:00
|
|
|
<!--
|
2016-12-29 17:01:02 +00:00
|
|
|
tagline: Hosting and installing private Composer packages
|
2012-04-13 10:13:52 +00:00
|
|
|
-->
|
2012-08-29 20:30:47 +00:00
|
|
|
|
2016-12-29 17:01:02 +00:00
|
|
|
# Handling private packages
|
2012-03-23 19:58:12 +00:00
|
|
|
|
2016-12-29 17:01:02 +00:00
|
|
|
# Private Packagist
|
2014-09-10 15:05:11 +00:00
|
|
|
|
2016-12-29 17:01:02 +00:00
|
|
|
[Private Packagist](https://packagist.com) is a commercial package hosting product
|
2017-01-03 00:03:08 +00:00
|
|
|
offering professional support and web based management of private and public packages,
|
|
|
|
and granular access permissions. Private Packagist provides mirroring for packages' zip
|
2016-12-29 17:01:02 +00:00
|
|
|
files which makes installs faster and independent from third party systems - e.g.
|
2017-01-03 00:03:08 +00:00
|
|
|
you can deploy even if GitHub is down because your zip files are mirrored.
|
2014-09-10 15:05:11 +00:00
|
|
|
|
2017-01-03 00:03:08 +00:00
|
|
|
Private Packagist is available as a hosted SaaS solution or as an on-premise self-hosted
|
|
|
|
package, providing an easy interactive set up experience.
|
2016-12-29 17:01:02 +00:00
|
|
|
|
2017-01-03 00:03:08 +00:00
|
|
|
Some of Private Packagist's revenue is used to pay for Composer and Packagist.org
|
2017-03-01 08:13:04 +00:00
|
|
|
development and hosting so using it is a good way to support the maintenance of
|
2017-01-03 00:03:08 +00:00
|
|
|
these open source projects financially. You can find more information about how to
|
|
|
|
set up your own package archive on [Packagist.com](https://packagist.com).
|
2014-09-10 15:05:11 +00:00
|
|
|
|
|
|
|
# Satis
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
Satis on the other hand is open source but only a static `composer` repository
|
|
|
|
generator. It is a bit like an ultra-lightweight, static file-based version of
|
|
|
|
packagist and can be used to host the metadata of your company's private
|
|
|
|
packages, or your own. You can get it from
|
|
|
|
[GitHub](https://github.com/composer/satis) or install via CLI:
|
2016-11-21 07:18:24 +00:00
|
|
|
|
|
|
|
php composer.phar create-project composer/satis --stability=dev --keep-vcs
|
2012-03-23 19:58:12 +00:00
|
|
|
|
|
|
|
## Setup
|
|
|
|
|
|
|
|
For example let's assume you have a few packages you want to reuse across your
|
|
|
|
company but don't really want to open-source. You would first define a Satis
|
2015-03-27 18:01:16 +00:00
|
|
|
configuration: a json file with an arbitrary name that lists your curated
|
2013-02-22 14:48:43 +00:00
|
|
|
[repositories](../05-repositories.md).
|
2012-03-23 19:58:12 +00:00
|
|
|
|
|
|
|
Here is an example configuration, you see that it holds a few VCS repositories,
|
2012-04-19 17:55:56 +00:00
|
|
|
but those could be any types of [repositories](../05-repositories.md). Then it
|
|
|
|
uses `"require-all": true` which selects all versions of all packages in the
|
|
|
|
repositories you defined.
|
|
|
|
|
2013-03-13 09:59:02 +00:00
|
|
|
The default file Satis looks for is `satis.json` in the root of the repository.
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
2016-11-18 13:30:37 +00:00
|
|
|
"name": "My Repository",
|
|
|
|
"homepage": "http://packages.example.org",
|
|
|
|
"repositories": [
|
|
|
|
{ "type": "vcs", "url": "https://github.com/mycompany/privaterepo" },
|
|
|
|
{ "type": "vcs", "url": "http://svn.example.org/private/repo" },
|
|
|
|
{ "type": "vcs", "url": "https://github.com/mycompany/privaterepo2" }
|
|
|
|
],
|
|
|
|
"require-all": true
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-04-19 17:55:56 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
If you want to cherry pick which packages you want, you can list all the
|
|
|
|
packages you want to have in your satis repository inside the classic composer
|
|
|
|
`require` key, using a `"*"` constraint to make sure all versions are selected,
|
|
|
|
or another constraint if you want really specific versions.
|
2012-03-23 19:58:12 +00:00
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
2016-11-18 13:30:37 +00:00
|
|
|
"repositories": [
|
|
|
|
{ "type": "vcs", "url": "https://github.com/mycompany/privaterepo" },
|
|
|
|
{ "type": "vcs", "url": "http://svn.example.org/private/repo" },
|
|
|
|
{ "type": "vcs", "url": "https://github.com/mycompany/privaterepo2" }
|
|
|
|
],
|
|
|
|
"require": {
|
|
|
|
"company/package": "*",
|
|
|
|
"company/package2": "*",
|
|
|
|
"company/package3": "2.0.0"
|
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-03-23 19:58:12 +00:00
|
|
|
|
2016-11-21 07:18:24 +00:00
|
|
|
Once you've done this, you just run:
|
|
|
|
|
|
|
|
php bin/satis build <configuration file> <build dir>
|
2012-03-23 19:58:12 +00:00
|
|
|
|
|
|
|
When you ironed out that process, what you would typically do is run this
|
|
|
|
command as a cron job on a server. It would then update all your package info
|
|
|
|
much like Packagist does.
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
Note that if your private packages are hosted on GitHub, your server should
|
|
|
|
have an ssh key that gives it access to those packages, and then you should add
|
2012-03-23 19:58:12 +00:00
|
|
|
the `--no-interaction` (or `-n`) flag to the command to make sure it falls back
|
|
|
|
to ssh key authentication instead of prompting for a password. This is also a
|
|
|
|
good trick for continuous integration servers.
|
|
|
|
|
|
|
|
Set up a virtual-host that points to that `web/` directory, let's say it is
|
2016-11-18 13:30:37 +00:00
|
|
|
`packages.example.org`. Alternatively, with PHP >= 5.4.0, you can use the
|
|
|
|
built-in CLI server `php -S localhost:port -t satis-output-dir/` for a
|
|
|
|
temporary solution.
|
2012-03-23 19:58:12 +00:00
|
|
|
|
2015-12-03 10:37:06 +00:00
|
|
|
### Partial Updates
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
You can tell Satis to selectively update only particular packages or process
|
|
|
|
only a repository with a given URL. This cuts down the time it takes to rebuild
|
|
|
|
the `package.json` file and is helpful if you use (custom) webhooks to trigger
|
|
|
|
rebuilds whenever code is pushed into one of your repositories.
|
2015-12-03 10:37:06 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
To rebuild only particular packages, pass the package names on the command line
|
|
|
|
like so:
|
2016-11-21 07:18:24 +00:00
|
|
|
|
|
|
|
php bin/satis build satis.json web/ this/package that/other-package
|
2015-12-03 10:37:06 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
Note that this will still need to pull and scan all of your VCS repositories
|
|
|
|
because any VCS repository might contain (on any branch) one of the selected
|
|
|
|
packages.
|
2015-12-03 10:37:06 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
If you want to scan only a single repository and update all packages found in
|
|
|
|
it, pass the VCS repository URL as an optional argument:
|
2016-11-21 07:18:24 +00:00
|
|
|
|
|
|
|
php bin/satis build --repository-url https://only.my/repo.git satis.json web/
|
2015-12-03 10:37:06 +00:00
|
|
|
|
2012-03-23 19:58:12 +00:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
In your projects all you need to add now is your own composer repository using
|
2016-11-18 13:30:37 +00:00
|
|
|
the `packages.example.org` as URL, then you can require your private packages
|
|
|
|
and everything should work smoothly. You don't need to copy all your
|
|
|
|
repositories in every project anymore. Only that one unique repository that
|
|
|
|
will update itself.
|
2012-03-23 19:58:12 +00:00
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
2016-11-18 13:30:37 +00:00
|
|
|
"repositories": [ { "type": "composer", "url": "http://packages.example.org/" } ],
|
|
|
|
"require": {
|
|
|
|
"company/package": "1.2.0",
|
|
|
|
"company/package2": "1.5.2",
|
|
|
|
"company/package3": "dev-master"
|
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-10-03 18:32:00 +00:00
|
|
|
|
|
|
|
### Security
|
|
|
|
|
|
|
|
To secure your private repository you can host it over SSH or SSL using a client
|
|
|
|
certificate. In your project you can use the `options` parameter to specify the
|
|
|
|
connection options for the server.
|
|
|
|
|
|
|
|
Example using a custom repository using SSH (requires the SSH2 PECL extension):
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
2016-11-18 13:30:37 +00:00
|
|
|
"repositories": [{
|
|
|
|
"type": "composer",
|
|
|
|
"url": "ssh2.sftp://example.org",
|
|
|
|
"options": {
|
|
|
|
"ssh2": {
|
|
|
|
"username": "composer",
|
|
|
|
"pubkey_file": "/home/composer/.ssh/id_rsa.pub",
|
|
|
|
"privkey_file": "/home/composer/.ssh/id_rsa"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-10-03 18:32:00 +00:00
|
|
|
|
2016-11-21 07:18:24 +00:00
|
|
|
> **Tip:** See [ssh2 context options] for more information.
|
2013-04-13 16:24:03 +00:00
|
|
|
|
2012-10-03 18:32:00 +00:00
|
|
|
Example using HTTP over SSL using a client certificate:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
2016-11-18 13:30:37 +00:00
|
|
|
"repositories": [{
|
|
|
|
"type": "composer",
|
|
|
|
"url": "https://example.org",
|
|
|
|
"options": {
|
|
|
|
"ssl": {
|
|
|
|
"local_cert": "/home/composer/.ssl/composer.pem"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2013-03-30 20:21:14 +00:00
|
|
|
|
2016-11-21 07:18:24 +00:00
|
|
|
> **Tip:** See [ssl context options] for more information.
|
2013-04-13 16:24:03 +00:00
|
|
|
|
2015-03-27 18:01:16 +00:00
|
|
|
Example using a custom HTTP Header field for token authentication:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
2016-11-18 13:30:37 +00:00
|
|
|
"repositories": [{
|
|
|
|
"type": "composer",
|
|
|
|
"url": "https://example.org",
|
|
|
|
"options": {
|
|
|
|
"http": {
|
|
|
|
"header": [
|
|
|
|
"API-TOKEN: YOUR-API-TOKEN"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]
|
2015-03-27 18:01:16 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2015-03-20 14:23:24 +00:00
|
|
|
### Authentication
|
2014-08-21 09:17:08 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
When your private repositories are password protected, you can store the
|
|
|
|
authentication details permanently. The first time Composer needs to
|
|
|
|
authenticate against some domain it will prompt you for a username/password and
|
|
|
|
then you will be asked whether you want to store it.
|
2014-08-21 09:17:08 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
The storage can be done either globally in the `COMPOSER_HOME/auth.json` file
|
|
|
|
(`COMPOSER_HOME` defaults to `~/.composer` or `%APPDATA%/Composer` on Windows)
|
|
|
|
or also in the project directory directly sitting besides your composer.json.
|
2014-08-21 09:17:08 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
You can also configure these by hand using the config command if you need to
|
|
|
|
configure a production machine to be able to run non-interactive installs. For
|
|
|
|
example to enter credentials for example.org one could type:
|
2014-08-21 09:17:08 +00:00
|
|
|
|
|
|
|
composer config http-basic.example.org username password
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
That will store it in the current directory's auth.json, but if you want it
|
|
|
|
available globally you can use the `--global` (`-g`) flag.
|
2014-08-21 09:17:08 +00:00
|
|
|
|
2013-03-30 20:21:14 +00:00
|
|
|
### Downloads
|
|
|
|
|
2017-01-18 23:12:05 +00:00
|
|
|
When GitHub, GitLab or BitBucket repositories are mirrored on your local satis, the
|
2016-11-18 13:30:37 +00:00
|
|
|
build process will include the location of the downloads these platforms make
|
|
|
|
available. This means that the repository and your setup depend on the
|
|
|
|
availability of these services.
|
2013-03-30 20:21:14 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
At the same time, this implies that all code which is hosted somewhere else (on
|
|
|
|
another service or for example in Subversion) will not have downloads available
|
|
|
|
and thus installations usually take a lot longer.
|
2013-03-30 20:21:14 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
To enable your satis installation to create downloads for all (Git, Mercurial
|
|
|
|
and Subversion) your packages, add the following to your `satis.json`:
|
2013-03-30 20:21:14 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
``` json
|
2014-05-19 10:17:07 +00:00
|
|
|
{
|
2016-11-18 13:30:37 +00:00
|
|
|
"archive": {
|
|
|
|
"directory": "dist",
|
|
|
|
"format": "tar",
|
|
|
|
"prefix-url": "https://amazing.cdn.example.org",
|
|
|
|
"skip-dev": true
|
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2013-03-30 20:21:14 +00:00
|
|
|
|
|
|
|
#### Options explained
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
* `directory`: required, the location of the dist files (inside the
|
|
|
|
`output-dir`)
|
2013-03-30 20:48:18 +00:00
|
|
|
* `format`: optional, `zip` (default) or `tar`
|
2016-11-18 13:30:37 +00:00
|
|
|
* `prefix-url`: optional, location of the downloads, homepage (from
|
|
|
|
`satis.json`) followed by `directory` by default
|
|
|
|
* `skip-dev`: optional, `false` by default, when enabled (`true`) satis will
|
|
|
|
not create downloads for branches
|
|
|
|
* `absolute-directory`: optional, a _local_ directory where the dist files are
|
|
|
|
dumped instead of `output-dir`/`directory`
|
|
|
|
* `whitelist`: optional, if set as a list of package names, satis will only
|
|
|
|
dump the dist files of these packages
|
|
|
|
* `blacklist`: optional, if set as a list of package names, satis will not
|
|
|
|
dump the dist files of these packages
|
|
|
|
* `checksum`: optional, `true` by default, when disabled (`false`) satis will
|
|
|
|
not provide the sha1 checksum for the dist files
|
|
|
|
|
|
|
|
Once enabled, all downloads (include those from GitHub and BitBucket) will be
|
|
|
|
replaced with a _local_ version.
|
2013-03-30 20:21:14 +00:00
|
|
|
|
|
|
|
#### prefix-url
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
Prefixing the URL with another host is especially helpful if the downloads end
|
|
|
|
up in a private Amazon S3 bucket or on a CDN host. A CDN would drastically
|
|
|
|
improve download times and therefore package installation.
|
2013-03-30 20:21:14 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
Example: A `prefix-url` of `https://my-bucket.s3.amazonaws.com` (and
|
|
|
|
`directory` set to `dist`) creates download URLs which look like the following:
|
|
|
|
`https://my-bucket.s3.amazonaws.com/dist/vendor-package-version-ref.zip`.
|
2013-10-15 13:07:05 +00:00
|
|
|
|
2015-11-26 15:31:49 +00:00
|
|
|
### Web outputs
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
* `output-html`: optional, `true` by default, when disabled (`false`) satis
|
|
|
|
will not generate the `output-dir`/index.html page.
|
2016-11-21 07:18:24 +00:00
|
|
|
* `twig-template`: optional, a path to a personalized [Twig] template for
|
|
|
|
the `output-dir`/index.html page.
|
2015-11-26 15:31:49 +00:00
|
|
|
|
|
|
|
### Abandoned packages
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
To enable your satis installation to indicate that some packages are abandoned,
|
|
|
|
add the following to your `satis.json`:
|
2015-11-26 15:31:49 +00:00
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
2016-11-18 13:30:37 +00:00
|
|
|
"abandoned": {
|
|
|
|
"company/package": true,
|
|
|
|
"company/package2": "company/newpackage"
|
|
|
|
}
|
2015-11-26 15:31:49 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
The `true` value indicates that the package is truly abandoned while the
|
|
|
|
`"company/newpackage"` value specifies that the package is replaced by the
|
|
|
|
`company/newpackage` package.
|
2015-11-26 15:31:49 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
Note that all packages set as abandoned in their own `composer.json` file will
|
|
|
|
be marked abandoned as well.
|
2013-10-15 13:07:05 +00:00
|
|
|
|
|
|
|
### Resolving dependencies
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
It is possible to make satis automatically resolve and add all dependencies for
|
|
|
|
your projects. This can be used with the Downloads functionality to have a
|
|
|
|
complete local mirror of packages. Just add the following to your `satis.json`:
|
2013-10-15 13:07:05 +00:00
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
2016-11-18 13:30:37 +00:00
|
|
|
"require-dependencies": true,
|
|
|
|
"require-dev-dependencies": true
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2013-10-15 13:07:05 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
When searching for packages, satis will attempt to resolve all the required
|
|
|
|
packages from the listed repositories. Therefore, if you are requiring a
|
|
|
|
package from Packagist, you will need to define it in your `satis.json`.
|
2014-05-23 08:05:00 +00:00
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
Dev dependencies are packaged only if the `require-dev-dependencies` parameter
|
|
|
|
is set to true.
|
2015-11-27 08:30:04 +00:00
|
|
|
|
|
|
|
### Other options
|
|
|
|
|
2016-11-18 13:30:37 +00:00
|
|
|
* `providers`: optional, `false` by default, when enabled (`true`) each
|
|
|
|
package will be dumped into a separate include file which will be only
|
|
|
|
loaded by composer when the package is really required. Speeds up composer
|
|
|
|
handling for repositories with huge number of packages like f.i. packagist.
|
|
|
|
* `output-dir`: optional, defines where to output the repository files if not
|
|
|
|
provided as an argument when calling the `build` command.
|
|
|
|
* `config`: optional, lets you define all config options from composer, except
|
|
|
|
`archive-format` and `archive-dir` as the configuration is done through
|
2016-11-21 07:18:24 +00:00
|
|
|
[archive](#downloads) instead. See docs on [config schema] for more details.
|
2016-11-18 13:30:37 +00:00
|
|
|
* `notify-batch`: optional, specify a URL that will be called every time a
|
2016-11-21 07:18:24 +00:00
|
|
|
user installs a package. See [notify-batch].
|
|
|
|
|
|
|
|
|
2017-01-02 11:49:45 +00:00
|
|
|
[ssh2 context options]: https://secure.php.net/manual/en/wrappers.ssh2.php#refsect1-wrappers.ssh2-options
|
|
|
|
[ssl context options]: https://secure.php.net/manual/en/context.ssl.php
|
2016-11-21 07:18:24 +00:00
|
|
|
[Twig]: http://twig.sensiolabs.org/
|
2017-01-02 11:49:45 +00:00
|
|
|
[config schema]: https://getcomposer.org/doc/04-schema.md#config
|
2016-11-21 07:18:24 +00:00
|
|
|
[notify-batch]: https://getcomposer.org/doc/05-repositories.md#notify-batch
|