Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

php - Using Composer and Private Repository on GitHub using VCS on Build Server

My compsoser.json uses 2 private repositories from our Organisation Github Account and is as follows.

{
    "name": "API",
    "repositories": [
      {
        "type": "vcs",
        "url": "git@github.com/company/private.git"
      },
      {
        "type": "vcs",
        "url": "git@github.com/company/private2.git"
      }
    ],
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": ">2.1.3",
        "doctrine/mongodb-odm": "dev-master",
        "doctrine/doctrine-mongo-odm-module": "dev-master",
        "company/private": "dev-master",
        "company/private2": "dev-master"
    }
}

We've setup SSH keys and added them to the authorized keys on our staging server. When we run git clone it works perfectly and isn't asking for any credentials.

However, when we run composer update the fetching of the repositories fails because composer doesn't have access to the repositories.

Since this is ran in a non-interactive way as this is part of a build script we can't enter credentials and like to have this automated.

What can we do to let composer have access to our private repo's during the build?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I understand the question title specifically mentions using type 'vcs' but this is an alternate method of using private git repos to deploy a project as a package.

"repositories": [
  {
    "type": "package",
    "package": {
      "name": "company/private",
      "version": "0.1.0",
      "type": "package",
      "source": {
        "url": "git@github.com:/company/private.git",
        "type": "git",
        "reference": "master"
      }
    }
  }
],
"require": {
  "company/private": "*"
}

The limitation is that you must manually change the version number every time you deploy if you want the latest version. However, this is also its advantage.

Defining a repo in this way will allow you to pull a specific tagged version. In this case the commit with tag 0.1.0 will be pulled on composer update.

You will need to add the SSH keys of the server you are deploying to in your github account.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...