Hirevo / alexandrie

An alternative crate registry, implemented in Rust.

Home Page:https://hirevo.github.io/alexandrie/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] - Anyone Successful with Index hosted on private GitLab repo?

tdrozdowski opened this issue · comments

Been trying to get Alexandrie setup using a Gitlab private index - and am confused on the configuration I'd need.

I adjusted the Dockerfile to do an ssh-keyscan of gitlab.com - and that helped get me a bit further. Noticed that Gitlab locked down the master branch, so I set that as 'unprotected' - so in theory I can push to it. But wondering if there's anything else I need to setup so that this will work as expected.

Anyone have any luck going down this path?

I wouldn't expect any particular difficulties using a private GitLab repo. What issues are you seeing? Can you share any config files, and the command you're using to run the docker image?

Just trying with a very simple local setup. Config.json is:

{
  "dl": "http://localhost:3000/api/v1/crates",
  "api": "http://localhost:3000/",
  "allowed-registries": ["https://github.com/rust-lang/crates.io-index"]
}

Server starts up (via docker) and I can get to the UI just fine - naturally everything is empty as the registry is.

My .cargo/config is:

[registries.my-registry]
index = "http://localhost:3000"

What I'm running into is when following directions, I try to search my registry - I get errors:

➜  ~ cargo search --registry my-registry foo   
    Updating `http://localhost:3000/` index
warning: spurious network error (2 tries remaining): unexpected HTTP status code: 404; class=Net (12)
warning: spurious network error (1 tries remaining): unexpected HTTP status code: 404; class=Net (12)
error: failed to update registry `http://localhost:3000/`

Caused by:
  failed to fetch `http://localhost:3000/`

Caused by:
  unexpected HTTP status code: 404; class=Net (12)

Would this be expected until I publish something? Or do I have something misconfigured?

One of the least straightforward parts of the way the cargo registry index key works is that you need to actually point it at a git repo containing the index, rather than at the website itself. The index then points to the api of the site.

So if you're hosting an index on gitlab at https://gitlab.com/username/crate-index:

~/.cargo/config:

[registries.my-registry]
index = "https://gitlab.com/username/crate-index"

You'll then also want to add that index url to your allowed-registries list.

I think everything else looks correct.

If you want to test without a remote index, change both the registry index and the index in alexandrie.toml to a local file path, e.g. file:///home/user/alexandrie/crate-index

Yeah, so doing that results in:

➜  ~ cargo search --registry my-registry foo
    Updating `https://gitlab.com/tdroz73/test-crate-registry` index
error: failed to update registry `https://gitlab.com/tdroz73/test-crate-registry`

Caused by:
  failed to fetch `https://gitlab.com/tdroz73/test-crate-registry`

Caused by:
  failed to authenticate when downloading repository
attempted to find username/password via git's `credential.helper` support, but failed

Caused by:
  failed to acquire username/password from local configuration

Its forcing git into basic auth vs ssh. Using the ssh url for the index also does not work.

Does cargo assume that the index is public??

Thanks for your help - I'm from JVM-land and sort of expected this to work like a Maven repo, which it doesn't...

Glad to help. This definitely seemed weird, so I tried it out myself to confirm the weirdness...

To get it working, I ended up having to use a somewhat modified SSH url. I thought I recalled having an issue like this a while ago, I think it might be a weird cargo thing.

~/.cargo/config

[registries.test]
index = "ssh://git@gitlab.com/bmhenry/test-registry.git"

Note two key differences from copy/pasting the SSH url from gitlab's clone button: I had to add ssh:// to the front, and change the the : after gitlab.com to a /

I set my git remote to the same: git remote set-url origin <SSH url>

Now that I think about it more, I think I recall this being a libgit2 requirement? I was trying to use private repos as cargo dependencies a year or so ago, and to use SSH I think I had to do the same URL changing. Kinda annoying. Another way may be to force Alexandrie to use the git cli backend, and the same for cargo.

Thanks - that was very helpful! I had to also force Cargo to use the CLI via setting the env var CARGO_NET_GIT_FETCH_WITH_CLI=true

Then it all worked!

Thx again for your help - this should be in the documentation. Maybe I'll submit a PR for that - I also have a potential PR to alter the Dockerfile to use an Arg to specify the git host so it will properly ssh-keyscan.