-
Notifications
You must be signed in to change notification settings - Fork 0
docs: add Private Modules howto page #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| --- | ||
| layout: default | ||
| title: "Private Modules" | ||
| parent: "How To" | ||
| description: "Configure Go private modules for GitHub and GitLab private repositories in ColdBrew services" | ||
| --- | ||
| ## Table of contents | ||
| {: .no_toc .text-delta } | ||
|
|
||
| 1. TOC | ||
| {:toc} | ||
|
|
||
| ## Overview | ||
|
|
||
| When your service depends on private Go modules (e.g., shared libraries in a private GitHub org or GitLab group), Go needs two things: | ||
|
|
||
| 1. **GOPRIVATE** — tells `go` to skip the public module proxy and fetch directly from the source | ||
| 2. **Authentication** — credentials to access private repositories | ||
|
|
||
| ColdBrew's cookiecutter template pre-configures GOPRIVATE from the `goprivate` variable you set during project creation (defaults to `source_path/*`). You just need to set up authentication. | ||
|
|
||
| ## Local Development | ||
|
|
||
| ### Option 1: SSH key (recommended) | ||
|
|
||
| If you already have SSH access to your repos: | ||
|
|
||
| ```bash | ||
| git config --global url."git@github.com:".insteadOf "https://github.com/" | ||
| # Or for GitLab: | ||
| git config --global url."git@gitlab.com:".insteadOf "https://gitlab.com/" | ||
| ``` | ||
|
|
||
| ### Option 2: Personal access token via .netrc | ||
|
|
||
| ```bash | ||
| # GitHub | ||
| echo "machine github.com login x-access-token password YOUR_PAT" >> ~/.netrc | ||
|
|
||
| # GitLab (needs read_api scope) | ||
| echo "machine gitlab.com login your-username password YOUR_PAT" >> ~/.netrc | ||
| ``` | ||
|
|
||
| ### Option 3: GOAUTH (Go 1.24+) | ||
|
|
||
| ```bash | ||
| export GOAUTH=netrc | ||
| ``` | ||
|
|
||
| This tells Go to use `.netrc` for authentication during module resolution. | ||
|
ankurs marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## Docker Builds | ||
|
|
||
| The generated `Dockerfile` includes GOPRIVATE as a build arg. For authentication, uncomment one of the options in the Dockerfile: | ||
|
|
||
| ### Personal access token | ||
|
|
||
| ```bash | ||
| docker build --build-arg GITHUB_TOKEN=your_pat . | ||
| ``` | ||
|
|
||
| The Dockerfile has a commented-out section that uses this arg to create a `.netrc` file in the build stage. | ||
|
ankurs marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### SSH agent forwarding | ||
|
|
||
| For SSH-based auth during Docker builds, use BuildKit: | ||
|
|
||
| ```bash | ||
| DOCKER_BUILDKIT=1 docker build --ssh default . | ||
| ``` | ||
|
|
||
| Add to your Dockerfile build stage: | ||
|
|
||
| ```dockerfile | ||
| RUN --mount=type=ssh git config --global url."git@github.com:".insteadOf "https://github.com/" | ||
| ``` | ||
|
|
||
| ## GitHub Actions | ||
|
|
||
| The generated workflow includes GOPRIVATE in the `env` section. For authentication, uncomment the private modules step and add a `GO_PRIVATE_TOKEN` secret to your repo: | ||
|
|
||
| 1. Create a [GitHub PAT](https://github.com/settings/tokens) with `repo` scope | ||
| 2. Add it as a repository secret named `GO_PRIVATE_TOKEN` | ||
| 3. Uncomment the "Configure private modules" step in `.github/workflows/go.yml` | ||
|
|
||
| ## GitLab CI | ||
|
|
||
| The generated `.gitlab-ci.yml` includes GOPRIVATE in the variables. For authentication, uncomment the `.netrc` line in `before_script`: | ||
|
|
||
| ```yaml | ||
| before_script: | ||
| - mkdir -p .go/pkg/mod | ||
| - echo "machine gitlab.com login gitlab-ci-token password ${CI_JOB_TOKEN}" > ~/.netrc | ||
| ``` | ||
|
|
||
| `CI_JOB_TOKEN` is automatically available in GitLab CI — no manual token setup needed. | ||
|
|
||
| ### GitLab nested subgroups | ||
|
|
||
| GitLab projects nested more than one level deep (e.g., `gitlab.com/org/group/subgroup/repo`) require special handling because Go's module discovery makes unauthenticated HTTP requests to determine the repository path. | ||
|
|
||
| For Go 1.24+, use GOAUTH: | ||
|
|
||
| ```yaml | ||
| variables: | ||
| GOAUTH: "netrc" | ||
| ``` | ||
|
|
||
| For older Go versions, set `GONOSUMCHECK` and `GONOSUMDB` alongside GOPRIVATE. | ||
|
ankurs marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## Troubleshooting | ||
|
|
||
| | Error | Cause | Fix | | ||
| |-------|-------|-----| | ||
| | `410 Gone` | Module proxy can't access private repo | Ensure GOPRIVATE is set correctly | | ||
| | `404 Not Found` | Git can't authenticate | Check `.netrc` or SSH config | | ||
| | `remote: HTTP Basic: Access denied` | Token expired or wrong scope | Regenerate PAT with `repo` (GitHub) or `read_api` (GitLab) scope | | ||
|
ankurs marked this conversation as resolved.
Outdated
|
||
| | `could not read Username` | Git prompting for credentials in non-interactive mode | Add `.netrc` or SSH config — don't rely on interactive auth in CI/Docker | | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.