From 5737dcecce81e29cd3f1c5eb4040b8cdff52d3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 30 Aug 2023 15:04:19 +0000 Subject: [PATCH 1/2] doc/user/packages/composer_repository: Example uses alpine image So specify the `image` to ensure proper docker image is used --- .../packages/composer_repository/index.md | 89 +++++-------------- 1 file changed, 24 insertions(+), 65 deletions(-) diff --git a/doc/user/packages/composer_repository/index.md b/doc/user/packages/composer_repository/index.md index 901fb74071750c..09eed24c960f81 100644 --- a/doc/user/packages/composer_repository/index.md +++ b/doc/user/packages/composer_repository/index.md @@ -1,10 +1,10 @@ --- stage: Package -group: Package -info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments +group: Package Registry +info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments --- -# Composer packages in the Package Registry **(FREE)** +# Composer packages in the Package Registry **(FREE ALL)** > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/15886) in GitLab 13.2. > - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/221259) from GitLab Premium to GitLab Free in 13.3. @@ -25,58 +25,7 @@ client uses, see the [Composer API documentation](../../../api/packages/composer Composer v2.0 is recommended. Composer v1.0 is supported, but it has lower performance when working in groups with very large numbers of packages. -## Create a Composer package - -If you do not have a Composer package, create one and check it in to -a repository. This example shows a GitLab repository, but the repository -can be any public or private repository. - -WARNING: -If you are using a GitLab repository, the project must have been created from -a group's namespace, rather than a user's namespace. Composer packages -[can't be published to projects created from a user's namespace](https://gitlab.com/gitlab-org/gitlab/-/issues/235467). - -1. Create a directory called `my-composer-package` and change to that directory: - - ```shell - mkdir my-composer-package && cd my-composer-package - ``` - -1. Run [`composer init`](https://getcomposer.org/doc/03-cli.md#init) and answer the prompts. - - For namespace, enter your unique [namespace](../../../user/group/index.md#namespaces), like your GitLab username or group name. - - A file called `composer.json` is created: - - ```json - { - "name": "/composer-test", - "description": "Library XY", - "type": "library", - "license": "GPL-3.0-only", - "authors": [ - { - "name": "John Doe", - "email": "john@example.com" - } - ], - "require": {} - } - ``` - -1. Run Git commands to tag the changes and push them to your repository: - - ```shell - git init - git add composer.json - git commit -m 'Composer package test' - git tag v1.0.0 - git remote add origin git@gitlab.example.com:/.git - git push --set-upstream origin main - git push origin v1.0.0 - ``` - -The package is now in your GitLab Package Registry. +Learn how to [build a Composer package](../workflows/build_packages.md#composer). ## Publish a Composer package by using the API @@ -89,7 +38,7 @@ Prerequisites: the [Composer specification](https://getcomposer.org/doc/04-schema.md#version). If the version is not valid, for example, it has three dots (`1.0.0.0`), an error (`Validation failed: Version is invalid`) occurs when you publish. -- A valid `composer.json` file. +- A valid `composer.json` file at the project root directory. - The Packages feature is enabled in a GitLab repository. - The project ID, which is on the project's home page. - One of the following token types: @@ -110,7 +59,7 @@ To publish the package with a personal access token: - `` is your personal access token. - `` is your project ID. - `` is the Git tag name of the version you want to publish. - To publish a branch, use `branch=` instead of `tag=`. + To publish a branch, use `branch=` instead of `tag=`. To publish the package with a deploy token: @@ -125,9 +74,9 @@ To publish the package with a deploy token: - `` is your deploy token - `` is your project ID. - `` is the Git tag name of the version you want to publish. - To publish a branch, use `branch=` instead of `tag=`. + To publish a branch, use `branch=` instead of `tag=`. -You can view the published package by going to **Packages & Registries > Package Registry** and +You can view the published package by going to **Deploy > Package Registry** and selecting the **Composer** tab. ## Publish a Composer package by using CI/CD @@ -141,21 +90,23 @@ You can publish a Composer package to the Package Registry as part of your CI/CD - deploy deploy: + image: alpine stage: deploy script: - apk add curl - 'curl --header "Job-Token: $CI_JOB_TOKEN" --data tag= "${CI_API_V4_URL}/projects/$CI_PROJECT_ID/packages/composer"' + environment: production ``` 1. Run the pipeline. -To view the published package, go to **Packages & Registries > Package Registry** and select the **Composer** tab. +To view the published package, go to **Deploy > Package Registry** and select the **Composer** tab. ### Use a CI/CD template A more detailed Composer CI/CD file is also available as a `.gitlab-ci.yml` template: -1. On the left sidebar, select **Project information**. +1. On the left sidebar, select **Project overview**. 1. Above the file list, select **Set up CI/CD**. If this button is not available, select **CI/CD Configuration** and then **Edit**. 1. From the **Apply a template** list, select **Composer**. @@ -192,7 +143,7 @@ To install a package: - Connect to the Package Registry for your group: ```shell - composer config repositories. composer https://gitlab.example.com/api/v4/group//-/packages/composer/ + composer config repositories. composer https://gitlab.example.com/api/v4/group//-/packages/composer/packages.json ``` - Set the required package version: @@ -209,7 +160,7 @@ To install a package: "repositories": { "": { "type": "composer", - "url": "https://gitlab.example.com/api/v4/group//-/packages/composer/" + "url": "https://gitlab.example.com/api/v4/group//-/packages/composer/packages.json" }, ... }, @@ -293,7 +244,7 @@ To install a package: { ... "repositories": [ - { "type": "composer", "url": "https://gitlab.example.com/api/v4/group//-/packages/composer/" } + { "type": "composer", "url": "https://gitlab.example.com/api/v4/group//-/packages/composer/packages.json" } ], "config": { ... @@ -358,7 +309,7 @@ used to access them: ### Caching -To improve performance, Composer caches files related to a package. Note that Composer doesn't remove data by +To improve performance, Composer caches files related to a package. Composer doesn't remove data by itself. The cache grows as new packages are installed. If you encounter issues, clear the cache with this command: @@ -374,6 +325,14 @@ If you committed your `composer.lock`, you could do a `composer install` in CI w In GitLab 14.10 and later, authorization is required for the [downloading a package archive](../../../api/packages/composer.md#download-a-package-archive) endpoint. If you encounter a credentials prompt when you are using `composer install`, follow the instructions in the [install a composer package](#install-a-composer-package) section to create an `auth.json` file. +### Publish fails with `The file composer.json was not found` + +You might see an error that says `The file composer.json was not found`. + +This issue occurs when [configuration requirements for publishing a package](#publish-a-composer-package-by-using-the-api) are not met. + +To resolve the error, commit a `composer.json` file to the project root directory. + ## Supported CLI commands The GitLab Composer repository supports the following Composer CLI commands: -- GitLab From 929b852448df58bfa0643b9ed32c6fdc44e373b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 1 Sep 2023 16:20:01 +0000 Subject: [PATCH 2/2] Update index.md --- doc/user/packages/composer_repository/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user/packages/composer_repository/index.md b/doc/user/packages/composer_repository/index.md index 09eed24c960f81..b2dac57afeff46 100644 --- a/doc/user/packages/composer_repository/index.md +++ b/doc/user/packages/composer_repository/index.md @@ -4,7 +4,7 @@ group: Package Registry info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments --- -# Composer packages in the Package Registry **(FREE ALL)** +# Composer packages in the Package Registry **(FREE ALL BETA)** > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/15886) in GitLab 13.2. > - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/221259) from GitLab Premium to GitLab Free in 13.3. -- GitLab