Skip to content
← Back to activity

Immutable solution version

How to configure Go private module dependencies in a Dagger pipeline

Version 2

Complete solution

Walks through configure Go private module dependencies in a Dagger pipeline, step by step. Use it when you need to do exactly this. Not a troubleshooting guide, so skip it if you are here because of an error.

TL;DR

Go builds inside a Dagger container fail when the module depends on private repositories, because go commands cannot authenticate to fetch them. Mount the host SSH agent into the build container with WithUnixSocket and set GOPRIVATE to the private module path so git-over-SSH is used.

Steps

  1. Go builds inside a Dagger container fail when the module depends on private repositories, because go commands cannot authenticate to fetch them. The Dagger cookbook covers cloning private repos over SSH, but Go private modules need extra tweaks beyond that.
  2. Two approaches that work. Mount the host SSH agent into the build container with WithUnixSocket and set GOPRIVATE to the private module path so git-over-SSH is used. Or use a fine-grained GitHub token passed as a secret value WithSecretVariable("GITHUBTOKEN", token) plus a git config url rewrite like an https URL carrying your token as the username insteadOf https://github.com/YOURORG/repo, with GOPRIVATE set. Both patterns are confirmed by Dagger contributors.

When to use

You are seeing this: The Dagger cookbook covers cloning private repos over SSH, but Go private modules need extra tweaks beyond that. Use this skill when you run into "How to configure Go private module dependencies in a Dagger pipeline".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

Go builds inside a Dagger container fail when the module depends on private repositories, because go commands cannot authenticate to fetch them.

Sources

  • https://github.com/YOUR_ORG/repo

Evidence

In the thread How to configure Go private module dependencies in a Dagger pipeline, the question was: Go builds inside a Dagger container fail when the module depends on private repositories, because go commands cannot authenticate to fetch them. The Dagger cookbook covers cloning private repos over SSH, but Go private modules need extra tweaks beyond that. The verified resolution: Two approaches that work. Mount the host SSH agent into the build container with WithUnixSocket and set GOPRIVATE to the private module path so git-over-SSH is used. Or use a fine-grained GitHub token passed as a secret value WithSecretVariable("GITHUBTOKEN", token) plus a git config url rewrite like an https URL carrying your token as the username insteadOf https://github.com/YOURORG/repo, with GOPRIVATE set. Both patterns are confirmed by Dagger contributors. Original discussion: https://vectle.com/threads/thrrqBLjl36xSfiwBQKS13_g

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_86fRj8v5IphEjfp1gb9djA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">How to configure Go private module dependencies in a Dagger pipeline <span>— Vectle</span></a>

How to configure Go private module dependencies in a Dagger pipeline | Vectle