did you provide the migration utility with the private key file? The particular step is the only step that uses the private key file, and open : no such file or directory tells me there was a problem reading it.
If you set the private key file path, and you are using the drone-migrate docker image, also make sure you mount the private key file (using a docker volume) otherwise it cannot be accessed from inside the container.
Good point, I put the key inline at first as I’ve taken it from the drone config DRONE_STASH_CONSUMER_RSA_STRING='-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAK...'
Now I put the key in a file but it’s still the same. To make sure it’s correctly mounted in the container I start it from the built-in bash:
I think the next step would be to look at the code to triage further. If you see an issue please consider sending a pull request. Or a pull request to update the docs if they can be improved.
I managed to fix this issue - the code was using c.String("stash-private-key-file") which returned empty string. When changed to c.GlobalString(...) it works.
Here is the pull request: https://github.com/drone/drone-migrate/pull/14
However I’m still seeing some issues:
DEBU[0000] private key file: /home/ec2-user/private-key-file.pem
INFO[0000] updating repository metadata
ERRO[0000] failed to get remote repository error="%!v(PANIC=runtime error: index out of range)" owner=xyz repo=CCC/ami-ec2
ERRO[0000] failed to get remote repository error="Not Authorized" owner=abc repo=CCC/ami-ecs
...
INFO[0000] repository metadata update complete
Ok, fixed that PANIC too. Apparently all the URL paths in go-scm/scm/driver/stash/repo.go do not start with the leading / and that makes the requests fail. This helps:
index e4d4e37..3fb3852 100644
--- a/scm/driver/stash/repo.go
+++ b/scm/driver/stash/repo.go
@@ -99,7 +99,7 @@ type repositoryService struct {
// Find returns the repository by name.
func (s *repositoryService) Find(ctx context.Context, repo string) (*scm.Repository, *scm.Response, error) {
namespace, name := scm.Split(repo)
- path := fmt.Sprintf("rest/api/1.0/projects/%s/repos/%s", namespace, name)
+ path := fmt.Sprintf("/rest/api/1.0/projects/%s/repos/%s", namespace, name)
out := new(repository)
res, err := s.client.do(ctx, "GET", path, nil, out)
return convertRepository(out), res, err
It must be done across all the Sprintf() calls in the file. Maybe there is a better way to do that. Perhaps check in scm/driver/stash/stash.go -> do() whether the path starts with / and if not prefix it?
I won’t make a pull request for this as I don’t know what’s the right way to fix it.
Hmm, no leading slash in the path is required for me to use Drone successfully with Bitbucket Server. Note that github, gogs, gitea, etc do not use a leading slash either [1].
Perhaps check in scm/driver/stash/stash.go → do() whether the path starts with / and if not prefix it?
The code accounts for a slash in the path [2][3] when the client is created. If the base path is empty or does not finish with a trailing slash one is added. The base path (trailing slash) is joined with the endpoint path (no leading slash).
I did notice your scm server address includes /repos in the path which seems abnormal. Perhaps this should be removed?