5

I've set up a satis repository on github to share some company internal packages across projects.

Now when I try to "depend" on the new repository, I tried this:

"repositories": [ {
    "type": "composer",
    "url": "https://raw.githubusercontent.com/[organisation]/satis/master/web/packages.json?token=[token-copied-from-url]"
} ]

and it works far enough that composer finds package.json, however, then it fails with:

[Composer\Downloader\TransportException]
  The "https://raw.githubusercontent.com/[organization]/satis/master/web/packages.json?token=[token-copied-from-url]/include/all$[some-json-file].json" file could not be downloaded (HTTP/1.1 404 Not Found)

which isn't surprising as the ?token part appears to generate an invalid url.

I can work around this by manually moving the contents of the included file into packages.json directly, but this is less than ideal, especially if satis decides to generate multiple files.

Another problem I assume this will cause is that I don't know much about the validity of the token. Perhaps it doesn't have a long lifetime and then satis will need to be regenerated regularly.

Is there a way I can get away with hosting my satis repo as "just" a github repo?

Letharion
  • 4,067
  • 7
  • 31
  • 42

2 Answers2

2

You can store your static Satis repository in a private GitHub repo, and then use GitHub's raw.githubusercontent.com domain to serve it over HTTPS. The slightly hacky part is ensuring that composer properly authenticates against the GitHub repo.

Push Satis repository to GitHub

Generate your Satis repository and push it to your private GitHub repo, lets's say https://github.com/your-org/your-satis-repo inside the output/ directory.

Prepare your projects' composer.json files

In your projects' composer.json files, add your Satis repo to the "repositories" section:

{
    "type": "composer",
    "url": "https://raw.githubusercontent.com/your-org/your-satis-repo/master/output"
}

Set up HTTP basic authentication

Finally, to make composer authenticate via HTTP basic auth against raw.githubusercontent.com you will need do add a new entry to the "http-basic" section in your local composer's auth.json:

{
    "http-basic": {
        "raw.githubusercontent.com": {
            "username": "GITHUB_USERNAME",
            "password": "GITHUB_TOKEN"
        }
    }
}

Caveats

  • We've found that raw.githubusercontent.com is cached, so it can take a few minutes before changes to your Satis repository are visible.
Ross Motley
  • 210
  • 3
  • 5
1

Initial testing suggests it can be done.

I think you need to remove packages.json from your repository URL and I suspect the ?token parameter. In theory you can pass the token via a header:

https://developer.github.com/v3/#authentication

I have not tested this however.

You can see a working test without authentication here:

To try it out:

git clone git@github.com:markchalloner/satishostcomposer.git
cd satishostcomposer
composer install

Should install vendor/markchalloner/satishostdemo

Example satis.json:

{
    "name": "Satis Host",
    "homepage": "https://raw.githubusercontent.com/markchalloner/satishost/master/web/",
    "archive": {
        "directory": "dist",
        "format": "tar",
        "prefix-url": "https://raw.githubusercontent.com/markchalloner/satishost/master/web/",
        "skip-dev": true
    },
    "repositories": [
        {
            "_comment": "Demo packages",
            "type": "package",
            "package": {
                "name": "markchalloner/satishostdemo",
                "version": "0.1.0",
                "dist": {
                    "type": "zip",
                    "url": "dist/demo.zip"
                }
            }
        }
    ],
    "require-all": true
}

Example composer.json (in your project):

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://raw.githubusercontent.com/markchalloner/satishost/master/web",
            "options":  {
                "http": {
                    "header": [
                        "API-TOKEN: YOUR-API-TOKEN"
                    ]
                }
            }
        }
    ],
    "require": {
        "markchalloner/satishostdemo": "0.1.0"
    },
    "minimum-stability": "dev"
}

Thanks

Mark C
  • 1,314
  • 1
  • 12
  • 19