|
| 1 | +--- |
| 2 | +date: "2021-07-20T00:00:00+00:00" |
| 3 | +title: "Composer Packages Repository" |
| 4 | +slug: "packages/composer" |
| 5 | +draft: false |
| 6 | +toc: false |
| 7 | +menu: |
| 8 | + sidebar: |
| 9 | + parent: "packages" |
| 10 | + name: "Composer" |
| 11 | + weight: 10 |
| 12 | + identifier: "composer" |
| 13 | +--- |
| 14 | + |
| 15 | +# Composer Packages Repository |
| 16 | + |
| 17 | +Publish [Composer](https://getcomposer.org/) packages for your user or organization. |
| 18 | + |
| 19 | +**Table of Contents** |
| 20 | + |
| 21 | +{{< toc >}} |
| 22 | + |
| 23 | +## Requirements |
| 24 | + |
| 25 | +To work with the Composer package registry, you can use [Composer](https://getcomposer.org/download/) to consume and a HTTP upload client like `curl` to publish packages. |
| 26 | + |
| 27 | +## Publish a package |
| 28 | + |
| 29 | +To publish a Composer package perform a HTTP PUT operation with the package content in the request body. |
| 30 | +The package content must be the zipped PHP project with the `composer.json` file. |
| 31 | +You cannot publish a package if a package of the same name and version already exists. You must delete the existing package first. |
| 32 | + |
| 33 | +``` |
| 34 | +PUT https://gitea.example.com/api/packages/{owner}/composer |
| 35 | +``` |
| 36 | + |
| 37 | +| Parameter | Description | |
| 38 | +| ---------- | ----------- | |
| 39 | +| `owner` | The owner of the package. | |
| 40 | + |
| 41 | +If the `composer.json` file does not contain a `version` property, you must provide it as a query parameter: |
| 42 | + |
| 43 | +``` |
| 44 | +PUT https://gitea.example.com/api/packages/{owner}/composer?version={x.y.z} |
| 45 | +``` |
| 46 | + |
| 47 | +Example request using HTTP Basic authentication: |
| 48 | + |
| 49 | +```shell |
| 50 | +curl --user your_username:your_password_or_token \ |
| 51 | + --upload-file path/to/project.zip \ |
| 52 | + https://gitea.example.com/api/packages/testuser/composer |
| 53 | +``` |
| 54 | + |
| 55 | +Or specify the package version as query parameter: |
| 56 | + |
| 57 | +```shell |
| 58 | +curl --user your_username:your_password_or_token \ |
| 59 | + --upload-file path/to/project.zip \ |
| 60 | + https://gitea.example.com/api/packages/testuser/composer?version=1.0.3 |
| 61 | +``` |
| 62 | + |
| 63 | +The server responds with the following HTTP Status codes. |
| 64 | + |
| 65 | +| HTTP Status Code | Meaning | |
| 66 | +| ----------------- | ------- | |
| 67 | +| `201 Created` | The package has been published. | |
| 68 | +| `400 Bad Request` | The package name and/or version are invalid or a package with the same name and version already exist. | |
| 69 | + |
| 70 | +## Configuring the package registry |
| 71 | + |
| 72 | +To register the package registry you need to add it to the Composer `config.json` file (which can usually be found under `<user-home-dir>/.composer/config.json`): |
| 73 | + |
| 74 | +```json |
| 75 | +{ |
| 76 | + "repositories": [{ |
| 77 | + "type": "composer", |
| 78 | + "url": "https://gitea.example.com/api/packages/{owner}/composer" |
| 79 | + } |
| 80 | + ] |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +To access the package registry using credentials, you must specify them in the `auth.json` file as follows: |
| 85 | + |
| 86 | +```json |
| 87 | +{ |
| 88 | + "http-basic": { |
| 89 | + "gitea.example.com": { |
| 90 | + "username": "{username}", |
| 91 | + "password": "{password}" |
| 92 | + } |
| 93 | + } |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +| Parameter | Description | |
| 98 | +| ---------- | ----------- | |
| 99 | +| `owner` | The owner of the package. | |
| 100 | +| `username` | Your Gitea username. | |
| 101 | +| `password` | Your Gitea password or a personal access token. | |
| 102 | + |
| 103 | +## Install a package |
| 104 | + |
| 105 | +To install a package from the package registry, execute the following command: |
| 106 | + |
| 107 | +```shell |
| 108 | +composer require {package_name} |
| 109 | +``` |
| 110 | + |
| 111 | +Optional you can specify the package version: |
| 112 | + |
| 113 | +```shell |
| 114 | +composer require {package_name}:{package_version} |
| 115 | +``` |
| 116 | + |
| 117 | +| Parameter | Description | |
| 118 | +| ----------------- | ----------- | |
| 119 | +| `package_name` | The package name. | |
| 120 | +| `package_version` | The package version. | |
0 commit comments