Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tdrozdowski opened this issue Apr 6, 2020 · 6 comments
Labels
C-question Category: Question

Comments

@tdrozdowski
Copy link

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?

@bmhenry
Copy link
Contributor

bmhenry commented Apr 6, 2020

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?

@tdrozdowski
Copy link
Author

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?

@bmhenry
Copy link
Contributor

bmhenry commented Apr 7, 2020

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

@tdrozdowski
Copy link
Author

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...

@bmhenry
Copy link
Contributor

bmhenry commented Apr 8, 2020

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://[email protected]/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.

@tdrozdowski
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: Question
Projects
None yet
Development

No branches or pull requests

3 participants