#Issues with private go modules, what is your recommendation ?

1 messages · Page 1 of 1 (latest)

plush bone
#

I was wondering what do you recommend when having to deal with private go modules because the few options i'm looking at right now feel cumbersome to use ( i might be missing some steps in my setup).

Context:

When running go mod tidy, my app is pulling dependencies from private repositories.
Currently my local environment is configure to use SSH keys thanks to the insteaf.of switcheroo in my git config.
I tried building a dagger pipeline forwarding my SSH_AUTH_SOCK but i ended up with the Host key verification failed.

Does dagger has a best practice to deal with this ? any guide perhaps ?

here is a snippet of my current pipeline, wondering if i'm doing every by the book:

// Build -- Run Go Build
func Build(container *dagger.Container, socketPath string, sshSocket *dagger.Socket) *dagger.Container{
  return container.WithWorkdir("/src").
    WithEnvVariable("GOPRIVATE","github.com/doppledankster/myprivaterepo").
    WithUnixSocket(socketPath, sshSocket).
    WithExec([]string{"git", "config", "--global", "url.ssh://git@github.com/doppledankster/myprivaterepo.insteadOf", "https://github.com/doppledankster/myprivaterepo"}).
    WithExec([]string{"go", "build", "-o", "./binary", "./cmd/app/main.go"})
}

Error message:

Host key verification failed.
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
plush bone
#

Btw i got it to run with an Access token, i'm just curious to understand if it's the best practice to do git config insteadOf etc...

Leaving my snippet here if someone needs help:

Build -- Run Go Build
func Build(container *dagger.Container, token *dagger.Secret) *dagger.Container{
  return container.WithWorkdir("/src").
    WithEnvVariable("GOPRIVATE","gitlab.com/doppledankster/myrepo").
    WithSecretVariable("ACCESS_TOKEN",token).
    WithExec([]string{"sh", "-c", "git config --global url.\"https://dagger:$ACCESS_TOKEN@gitlab.com/doppledankster/myrepo.insteadOf\" https://gitlab.com/doppledankster/myrepo"}).
    WithExec([]string{"go", "build", "-o", "./binary", "./cmd/app/main.go"})
}
zealous night
#

👋 the insteadOf should work. I can try to take a stab at this one

zealous night
#

👋 just managed to make it work, You were almsot there @plush bone. Only thing missing was the StrictHostKeyChecking config for git

#
    _, err = client.Pipeline("build").
        Container().
        From("golang:1.20").
        WithUnixSocket(sshAgentPath, client.Host().UnixSocket(sshAgentPath)).
        WithEnvVariable("SSH_AUTH_SOCK",sshAgentPath).
        WithDirectory("/app", hd).
    WithWorkdir("/app").
        WithExec([]string{"git", "config", "--global", `url.ssh://git@github.com/marcosnils/containers.insteadOf`, `https://github.com/marcosnils/containers`}).
        WithEnvVariable("GOPRIVATE", "github.com/marcosnils/containers").
        WithEnvVariable("GIT_SSH_COMMAND", "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=accept-new").
        WithExec([]string{"go", "build", "."}).
        Stdout(ctx)
    if err != nil {
        panic(err)
    }

^ that's my snippet

#

I'll open an issue to document this

#

related issue:

plush bone
#

Wow thank you so much. Actually learned about GIT_SSH_COMMAND thanks to you. Have a wonderful weekend