1. 程式人生 > >使用 satis 搭建 composer 本地倉庫

使用 satis 搭建 composer 本地倉庫

eat pes con arc server per http code pro

環境

  • windows
  • nginx
  • php
  • composer

安裝

拉取 satis 項目包,並拉取項目依賴

composer create-project composer/satis --stability=dev

cd satis

composer install

配置

修改 satis/config.json 文件,文件內容如下


{
    "name": "composer 本地倉庫",
    "homepage": "http://packages.example.org", // 訪問域名
    "repositories": [// 要拉取包的倉庫地址
        { "type": "vcs", "url": "https://github.com/test-lin/db.git" },
        { "type": "vcs", "url": "https://github.com/test-lin/queue.git" },
        { "type": "vcs", "url": "https://github.com/test-lin/cache.git" },
        { "type": "vcs", "url": "http://192.168.6.251:3000/php/xjwSpider.git" }
    ],
    "require": { // 要拉取到本地的包文件 註:不會包含包的依賴
        "test-lin/db": "*",
        "test-lin/queue": "*",
        "test-lin/cache": "*",
        "php/xjwSpider": "*"
    },
    "archive": {
        "directory": "dist",
        "format": "tar",
        "prefix-url": "http://packages.example.org" // * 這個參數是當前項目的域名,作用是以zip壓縮包的方式直接下載包文件
    }
}

拉取包到本地倉庫

web/ 是本地倉庫訪問地址。

php bin/satis build config.json web/

如果需要定時更新,則需要配置定時任務去定時更新

設置本地倉庫

nginx 設置虛擬主機



server {
    listen 80;
    server_name packages.example.org;
    root /var/www/satis/web;
    index index.php index.html;

    location ~* \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
    }
}

使用本地倉庫中的包

composer.json 文件中添加以下 json 拉取,即可獲取本地庫了.

如果本地倉庫不存在且有網絡會去網絡中獲取。repositories 參數可以設置多個



{
  "repositories": [{
    "type": "composer",
    "url": "http://packages.example.org"
  }]
}

FQA

1. github 的包需要配置 token


Could not fetch https://api.github.com/repos/test-lin/db/git/refs/heads?per_page=100, please create a GitHub OAuth token to go over the API rate limit
Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+packages.example.org+2018-06-28+0310
to retrieve a token. It will be stored in "/home/vagrant/.config/composer/auth.json" for future use by Composer.

解決方法:

訪問命令行中提示的 https://github.com/settings/t...

復制 token description 文本框中內容

拉到頁底 點擊 generate token

在命令行中粘貼復制內容確認限可

2. 私有包,拉取不了

解決方法:

本地生成 ssh key ,配置到要拉取項目的平臺即可,免密拉取了



ssh-keygen -t rsa

cat ~/.ssh/id_rsa.pub

以 gogs 為例

技術分享圖片

3. composer 不支持 http


Your configuration does not allow connections to http://192.168.6.251:3000/php/xjwSpider.git. See https://getcomposer.org/doc/06-config.md#secure-http for details.

解決方法:

composer config -g secure-http false

4. 拉取的包 composer.json 配置有誤


[Composer\Repository\InvalidRepositoryException]
No valid composer.json was found in any branch or tag of http://192.168.6.251:3000/php/xjwSpider.git, could not load a package from it.

解決方法:

  1. 確保項目根部有 composer.json
  2. composer.json 裏需要設置 name

原文地址:https://segmentfault.com/a/1190000016523278

使用 satis 搭建 composer 本地倉庫