Can't clone private gogs repository in 1.0.0-rc.4: No such device or address

#1

Hello! I’ve been wanting to upgrade to 1.0.0-rc.4 and tried to change everything accordingly like adding DRONE_GIT_USERNAME and DRONE_GIT_PASSWORD with a set of credentials I created for drone in Gogs and toggling DRONE_GIT_ALWAYS_AUTH=true. I’m still getting this however:

Initialized empty Git repository in /drone/src/.git/
+ git fetch origin +refs/heads/master:
fatal: could not read Username for 'https://git.mydomain.com': No such device or address 

Maybe it’s something related to using HTTPS instead of SSH, which I’m avoiding since Gogs recommends using HTTPS when using its docker image.

Previously, I used drone 0.6.x, and it did work, but I’m not looking forward into downgrading.

I looked into the sqlite database and saw that the repository wasn’t marked as private, so I did it manually (updating the row to have repo_private = 1 and repo_visilibity = private) but still no luck. I may be missing some environment variable, I currently have these set:

DRONE_SERVER_PROTO=https
DRONE_SERVER_HOST=ci.mydomain.com
DRONE_GOGS_SERVER=https://git.mydomain.com
DRONE_RUNNER_CAPACITY=2
DRONE_GIT_ALWAYS_AUTH=true
DRONE_GIT_USERNAME=drone
DRONE_GIT_PASSWORD=hunter2

I’m also running it on single-machine, I don’t know if running a drone-runner instead would work.

Ah, and gogs is 0.11.79, I updated it to the latest, just in case.

0 Likes

#3

Have you searched the existing threads for this error?
https://discourse.drone.io/search?q=No%20such%20device%20or%20address

0 Likes

#4

Yes, I have, this was probably the most helpful: Another 'could not read username' when cloning question: Gogs/Drone, and indeed, the repository was marked as public when it should’ve been marked as private.

However, some things have changed especially on the environment variables front, and I’m afraid some of it no longer applies (like the DRONE_GOGS_PRIVATE_MODE doesn’t seem to exist anymore for example).

0 Likes

#5

Private mode was deprecated in favor of DRONE_GIT_ALWAYS_AUTH=true

When always auth is true it will instruct Drone to always clone the repository with credentials, regardless of whether or not the repository is private.

0 Likes

#6

Very interesting. I have that toggled in my environment variables:

But it seems like it doesn’t even attempt to login using my provided credentials DRONE_GIT_USERNAME and DRONE_GIT_PASSWORD in Gogs (hence this error). I’m thinking that what causes this problem is my single machine setup :confused: .

Update: The same happens if I have one agent, so unrelated I guess.

0 Likes

#7

could not read Username for ‘https://git.mydomain.com’: No such device or address

Please read this Stackoverflow post: https://stackoverflow.com/questions/22147574/fatal-could-not-read-username-for-https-github-com-no-such-file-or-directo#answer-46066702

You will notice that Git will return this error under a variety of circumstances, which may not have anything to do with the actual username or password.

It is more likely that Drone simply cannot reach your Gogs server because you are using custom Docker networks and Docker internal DNS, and the clone container is running on a completely separate Docker network.

You should be able to test all of this manually:

kind: pipeline
name: default

clone:
  disable: true

steps:
- name: custom_clone
  image: docker:git
  commands:
  - git clone https://username:password@git.mydomain.com/foo/bar.git
0 Likes

#8

And case closed, looks like gogs didn’t set the password correctly for the account I created. If someone else wants to debug this, I recommend setting up your .drone.yml like this:

clone:
  disable: true

steps:
  - name: clone
    image: docker:git
    commands:
      - echo $DRONE_REPO_PRIVATE
      - cat /root/.netrc
      - git clone $DRONE_GIT_HTTP_URL
1 Like

#9

Yea, the error message is quite worthless, but thanks for the help anyway!

0 Likes

#10

How could I handle this circumstance?Change Docker networks?

0 Likes

#11

You can use this command to check if the git username and password are returned correctly:

curl -i -H ‘X-Drone-Token: YOUR_RPC_SECRET’ -H ‘content-type: application/json’ -X POST -d ‘{“Repo”: YOUR_REPO_ID}’ YOUR_SERVER_PROTO://YOUR_DRONE_HOST/rpc/v1/netrc

0 Likes