Saturday, March 5, 2022

[FIXED] Composer custom GitLab server dependencies

Issue

We have a company GitLab server behind a VPN. Packages in there are set as being public, but they are de facto "private" since you can't get to repository without authorizing on our VPN.

I made one repository which has dependency to other (on the same server).

Repo 1:

"name": "xxx/repo1",
"repositories": [
    {
        "type": "vcs",
        "url": "http://pvt/repo2"
    }
],
"require": {
    "xxx/repo2": "dev-master"
},

Repo 2:

"name": "xxx/repo2"

The issue I'm getting is when I try to use repo1 in one of my other services.

"name": "other/service",
"repositories": [
    {
        "type": "vcs",
        "url": "http://pvt/repo1"
    }
],
"require": {
    "xxx/repo1": "dev-master"
},
"minimum-stability": "dev",
"prefer-stable": true,

Doing a composer install like this just tells me that repo2 can't be found. I can solve it like this:

"name": "other/service",
"repositories": [
    {
        "type": "vcs",
        "url": "http://pvt/repo1"
    },
    {
        "type": "vcs",
        "url": "http://pvt/repo2"
    }
],
"require": {
    "xxx/repo1": "dev-master"
},

But this is far from ideal. If I have 10 services and all need repo1 to run, introducing a new dependency inside repo1 would require me to change 10 composer.json files.

Why doesn't this function the same way as with other dependencies, so that all required dependencies of the requested package are pulled automatically?

I tried adding this to config:

"config": {
    "gitlab-domains": [
        "pvt"
    ],
    "gitlab-token": {
        "pvt" : "---my-token---"
    }
},

But this did nothing basically.

I also tried replacing pvt with exact server IP, but nothing changed.

Is there a way to make this work?

Note: I do not want to use any external service like Private Packagist or Satis.


Solution

Is there a way to make this work?

The answer is "no" - see the official Composer's explanation: https://getcomposer.org/doc/faqs/why-can%27t-composer-load-repositories-recursively.md



Answered By - kuba

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.