Composer with private repos

I’m attempting to use a private repo in composer inside a travis build.
On my local install (docker) this works as expected.

Currently in my composer.json:

    "repositories": [
            "type": "vcs",
            "url": "[organisation]/[repo]"

I’ve attempted to follow the instructions within:

This includes adding:

  - echo -e "machine\n  login $GITHUB_TOKEN" > ~/.netrc

I call the composer install via:

  - travis_retry composer self-update
  - travis_retry composer install

(those variables are defined)

Failed to download [organisation]/[repo] from dist: The “[organisation]/[repo]/zipball/851ecba22de6d5f7e6c37c75dcbc713256bef319” file could not be downloaded (HTTP/1.1 404 Not Found)

I have attempted this various ways.

I’ve also attemped the following (which was suggested in another thread):

  - echo -e "machine\n  login $GITHUB_TOKEN" > ~/.netrc
  - git config --global credential.helper store
  - |
    git credential fill <<! | git credential approve

Which gets me:

Package operations: 105 installs, 0 updates, 0 removals
  - Downloading [organisation]/[repo] (dev-staging 851ecba)
    Failed to download [organisation]/[repo] from dist: The "[organisation]/[repo]/zipball/851ecba22de6d5f7e6c37c75dcbc713256bef319" file could not be downloaded (HTTP/1.1 404 Not Found)
    Now trying to download from source
  - Syncing [organisation]/[repo] (dev-staging 851ecba) into cache
  Failed to execute git clone --mirror -- '[organisation]/[repo].git' '/home/travis/.cache/composer/vcs/[organisation]-[repo].git/'                                                            
  Cloning into bare repository '/home/travis/.cache/composer/vcs/[organisation]-[repo].git'...                                         
  Permission denied (publickey).                                               
  fatal: Could not read from remote repository.                                
  Please make sure you have the correct access rights                          
  and the repository exists.    

While this looks like a permissions issue I can’t seem to solve it. I’ve tried several variations, including using my own valid token… but I am at my whit’s end on this. Does anyone have any ways to sort or debug this?


I’m thinking to try and reconstitute the private SSH key once running inside Travis, so maybe lets try making a bash script that reads something like:

echo -n $id_rsa_{00..30} >> ~/.ssh/id_rsa_base64
base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo -e "Host\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

You can obviously call the script whatever you want, for the sake of time I’m calling this

Now you can just add in your .travis.yml:

before_script: chmod u+x 

It’s an outside the box possible solution, but it could work. If it doesn’t please post back and I will get this working for you.

Montana Mendy
Travis CI Staff

Thanks for reviewing this Montana.
The above fix didn’t help. :frowning:

I will raise a ticket to try to get support, but I’m surprised that such a simple thing is an issue with travis.

Another thing that comes to mind,

If you want to push via SSH, Travis needs to have access to the encrypted or as some colloquially say the “private” part of the SSH key you originally generated.

I recommend you reading this:

Ok… This document is about using an SSH key (specifically with respect to encrypting it).

I am asking about

  • using github/packagist to install dependancies
  • using token authentication (as is used everywhere else in all systems, including the live/production server).

This explains (one of the many methods of) how to do this:

I’m following the methods explained in:

I’m unsure why the travis documentation doesn’t work. Are you able to help with this specifically?

Hey @elb98rm,

Gotcha, thank you for clarifying - let me look into this a bit more and I’ll get a fix to you.

If it will help, I can provide a link to a private repo/private travis build to assist you.

Just wanted to update this for the general public. After some help from the travis team, we found that there was a problem with a key.

However, there is to be a documentation update. Given a token named $GITHUB_TOKEN

  - composer config -g "$GITHUB_TOKEN"
  - echo -e "machine\n  login $GITHUB_TOKEN" > ~/.netrc

This correctly logs you in to github.