#Recommended way to git push

1 messages ยท Page 1 of 1 (latest)

celest jewel
#

I'd like to use dagger to make automated changes to a git repo

  1. clone repo & checkout branch
  2. mount to a container with tools and do things
  3. commit changes, push to code host, open pr

Is the easiest thing to do, to do the git operations in the tools container, mounting in any needed code host secrets? (rather than relying on daggers git function, which only seems to support the clone step)

Opening a PR is probably API based work, so tools container & creds anyway

muted sun
#

yep, seems like the right approach

#

if this is for github you can use the gh client for that if it supports the API operation you're looking for

celest jewel
#

I need to support the big 3 at a minimum

vast wave
#

@muted sun just curious, when you say gh client, is this part of the dagger sdk or you're referring to something else? i couldn't find a link to documentation in it.

muted sun
proven ferry
#

Hi, @muted sun I'm trying to do git operations in order to save some changes like a new version but I have some issues.

#

I'm able to git clone with the dagger api using the unix socket

#

Then I'm doing somes changes in files and I'm trying to push it but this part doesnt work

#

for this part I'm creating a container with git and openssh client, mounting the socket

#

but I have this error:

#

xxxxx@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

#

I can do git operations when I'm testing with docker directly: docker run -ti --rm -v $SSH_AUTH_SOCK:$SSH_AUTH_SOCK -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK alpine:3.18

#

from my container using docker I'm able to pull and push

#

do you have an idea what I'm missing ?

#

in another part I'm doing that:

#

iacRepo = c.
Git(
opt.Repo.Repo,
dagger.GitOpts{KeepGitDir: true},
).
Branch(opt.Repo.Branch).
Tree(
dagger.GitRefTreeOpts{
SSHAuthSocket: dag.Host().UnixSocket(os.Getenv("SSH_AUTH_SOCK")),
},
)

#

and it's working so the ssh agent is working correctly I think

proven ferry
#

I did another test in the container running this command: WithExec([]string{"ssh", "-T", "git@github.com"}) and I have the expected output so the ssh agent forwarding is working but I don't know why the git fetch try to use ssh key

muted sun
#

@proven ferry seems like it worked for me

31: exec apk --no-cache add git openssh-client CACHED
31: exec apk --no-cache add git openssh-client CACHED

36: copy / /opt DONE
36: copy / /opt DONE

34: exec git push origin foo
34: [2.22s] remote: 
34: [2.22s] remote: Create a pull request for 'foo' on GitHub by visiting:        
34: [2.22s] remote:      https://github.com/marcosnils/rooster/pull/new/foo        
34: [2.22s] remote: 
34: [2.22s] To github.com:marcosnils/rooster.git
34: [2.22s]  * [new branch]      foo -> foo
34: exec git push origin foo DONE
#

are you sure your git repository has the git:// remote format?

proven ferry
#

I just recheck the .git/config and this one has ssh://git@github.com/... I just tried to replace the ssh by git I have another error (fatal: unable to look up xxxxx@github.com (port 9418) (Name does not resolve)) now but I guess I have to work around this config file

#

The git repository folder come from the git api of dagger, there is an option in order to have the right file content or I haveto do some sed or something else ?

muted sun
#

@proven ferry ping me tomorrow and we can jump into a quick #911305510882513037 session to check it out together

muted sun
#

btw this has been fixed in main by @acoustic wyvern ๐ŸŽ‰ ๐Ÿ™Œ

#

there's going to be an engine release very likely this week

proven ferry
#

ok thank you for the update and for the time to help me ๐Ÿ™‚

muted sun
#

๐Ÿ‘‹ closing this one