#How to provide token when cloning private GitRepository
1 messages ยท Page 1 of 1 (latest)
Hi @quartz goblet,
What are your scripts written in? Go?
How are you pushing? go-git library? A call to a shell git command?
Currenty we have mixture of bash scripts and Python but we are going to rewrite them using Go. Propably gonna use go-git I thought that Dagger's GitRepository would help us here but not sure what's is purpose.
Was able to clone the repo using http://git:<token>@foo.gitlab.com so I'm able to clone the repo. I think for modifying and commiting changes I need to export the content from here to some container and do the needed operations there?
The GitRepository is mostly to clone the repo in your pipeline.
For pushing, you would have to be in another container and run some git command (and have the correct configuration to have the rights to push), or you export on the host and do it directly in the code via go-git. Thinking about it, it would be super nice to actually support easily a way that you could execute Go code from the dagger SDK directly in the pipeline without having to fall back to some CLI already available in the container.
The way to use go-git in a container would be to build your Go app that uses go-git with dagger, save that in an image, execute the build step from that image. I wonder if we could improve that boilerplate, that would be great.
If what I say doesn't make sense, just ping me again ๐
We have quite a few cases where one pipeline is editing another repository (ie. updating dependencies in a GitOps-configs etc.) and committing the code, sometimes to main and sometimes opening MR to target repository. Great if you can make this process bit less painful ๐
Hey there! I am currently working on this "push to another repo" part of our pipelines and having some issues.
Repository which I clone has submodules and if I clone it with setting KeepGitDir=true I get authentication errors because I use setup where I have the token in the GitURL.
For the push part I'm currently trying to do it so that I have Alpine-git container where I inject the cloned repository and then override the files and folders I want to update and then push the branch. I again need to override the origin url with url which has token.
@tardy loom pinging you as this is quite old thread already and don't know if you get some notification about this otherwise ๐
It seems it's actually our Gitlab that is returing with 500 when the submoudule installation happens ๐ค
info main #5 1.216 Submodule 'cue.mod/pkg/foobar.com' (https://xxxxx:xxxxx@gitlab.foobar.com/path/to/ok1.git) registered for path 'cue.mod/pkg/foobar.com'
info main #5 1.216 Submodule 'docs/shared-content' (https://xxxxx:xxxxx@gitlab.foobar.com/path/to/docs.git) registered for path 'docs/shared-content'
info main #5 1.219 Cloning into '/var/lib/dagger/runc-overlayfs/snapshots/snapshots/37/fs/cue.mod/pkg/foobar.com'...
info main #5 6.701 fatal: unable to access 'https://gitlab.foobar.com/path/to/ok1.git/': The requested URL returned error: 500
Is there a option to not install the submodules when cloning the parent repository?
When cloning using git cli the submodules aren't installed. I tried cloning the submodule repos with same token and it works.
Was able to do what I aimed with running all the scripts but it would be great if we could do this without writing this Golang-wrapper to what used to be a shell script ๐
ctr := docker.CreateFrom(ctx, client, shared.RegistryURL, shared.GitImage).
WithWorkdir(shared.WorkDIR).
WithExec([]string{"clone", git.URLWithToken(*repository), "."}).
WithExec([]string{"remote", "set-url", "origin", git.URLWithToken(*repository)}).
WithExec([]string{"config", "--global", "user.email", "\"foo@bar.com\""}).
WithExec([]string{"config", "--global", "user.name", "\"Git-robot\""}).
WithExec([]string{"checkout", *branch}).
WithDirectory(fmt.Sprintf("%s/%s", shared.WorkDIR, *target), sourceDir).
WithExec([]string{"add", *target}).
WithExec([]string{"status"}).
WithExec([]string{"commit", "-m", *msg}).
WithExec([]string{"push", "origin", *branch})
Could this be written as some library that could be reused by other packages? Until we have extensions, it would work only for Go SDK users. But that would be pretty nice?