Skip to content

Commit f375e5f

Browse files
committed
feat: add support for Go package manager in Nexus module and update README
1 parent 88f8284 commit f375e5f

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

registry/mavrickrishi/modules/nexus/README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tags: [integration, nexus-repository, maven, npm, pypi, docker]
88

99
# Sonatype Nexus Repository
1010

11-
Configure package managers (Maven, npm, PyPI, Docker) to use [Sonatype Nexus Repository](https://help.sonatype.com/en/sonatype-nexus-repository.html) with API token authentication. This module provides secure credential handling, multiple repository support per package manager, and flexible username configuration.
11+
Configure package managers (Maven, npm, Go, PyPI, Docker) to use [Sonatype Nexus Repository](https://help.sonatype.com/en/sonatype-nexus-repository.html) with API token authentication. This module provides secure credential handling, multiple repository support per package manager, and flexible username configuration.
1212

1313
```tf
1414
module "nexus" {
@@ -20,6 +20,7 @@ module "nexus" {
2020
package_managers = {
2121
maven = ["maven-public", "maven-releases"]
2222
npm = ["npm-public", "@scoped:npm-private"]
23+
go = ["go-public", "go-private"]
2324
pypi = ["pypi-public", "pypi-private"]
2425
docker = ["docker-public", "docker-private"]
2526
}
@@ -30,10 +31,10 @@ module "nexus" {
3031

3132
- Nexus Repository Manager 3.x
3233
- Valid API token or user credentials
33-
- Package managers installed on the workspace (Maven, npm, pip, Docker as needed)
34+
- Package managers installed on the workspace (Maven, npm, Go, pip, Docker as needed)
3435

3536
> [!NOTE]
36-
> This module configures package managers but does not install them. You need to handle the installation of Maven, npm, Python pip, and Docker yourself.
37+
> This module configures package managers but does not install them. You need to handle the installation of Maven, npm, Go, Python pip, and Docker yourself.
3738
3839
## Examples
3940

@@ -67,6 +68,21 @@ module "nexus" {
6768
}
6869
```
6970

71+
### Configure Go module proxy
72+
73+
```tf
74+
module "nexus" {
75+
source = "registry.coder.com/mavrickrishi/nexus/coder"
76+
version = "1.0.0"
77+
agent_id = coder_agent.example.id
78+
nexus_url = "https://nexus.example.com"
79+
nexus_password = var.nexus_api_token
80+
package_managers = {
81+
go = ["go-public", "go-private"]
82+
}
83+
}
84+
```
85+
7086
### Configure Python PyPI repositories
7187

7288
```tf
@@ -125,6 +141,7 @@ module "nexus" {
125141
package_managers = {
126142
maven = ["maven-public", "maven-releases"]
127143
npm = ["npm-public", "@company:npm-private"]
144+
go = ["go-public", "go-private"]
128145
pypi = ["pypi-public", "pypi-private"]
129146
docker = ["docker-public", "docker-private"]
130147
}

registry/mavrickrishi/modules/nexus/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,30 @@ variable "package_managers" {
3939
type = object({
4040
maven = optional(list(string), [])
4141
npm = optional(list(string), [])
42+
go = optional(list(string), [])
4243
pypi = optional(list(string), [])
4344
docker = optional(list(string), [])
4445
})
4546
default = {
4647
maven = []
4748
npm = []
49+
go = []
4850
pypi = []
4951
docker = []
5052
}
5153
description = <<-EOF
5254
Configuration for package managers. Each key maps to a list of Nexus repository names:
5355
- maven: List of Maven repository names
5456
- npm: List of npm repository names (supports scoped packages with "@scope:repo-name")
57+
- go: List of Go proxy repository names
5558
- pypi: List of PyPI repository names
5659
- docker: List of Docker registry names
5760
Unused package managers can be omitted.
5861
Example:
5962
{
6063
maven = ["maven-public", "maven-releases"]
6164
npm = ["npm-public", "@scoped:npm-private"]
65+
go = ["go-public", "go-private"]
6266
pypi = ["pypi-public", "pypi-private"]
6367
docker = ["docker-public", "docker-private"]
6468
}
@@ -87,6 +91,7 @@ locals {
8791
# Get first repository name or use default
8892
maven_repo = length(var.package_managers.maven) > 0 ? var.package_managers.maven[0] : "maven-public"
8993
npm_repo = length(var.package_managers.npm) > 0 ? var.package_managers.npm[0] : "npm-public"
94+
go_repo = length(var.package_managers.go) > 0 ? var.package_managers.go[0] : "go-public"
9095
pypi_repo = length(var.package_managers.pypi) > 0 ? var.package_managers.pypi[0] : "pypi-public"
9196

9297
npmrc = <<-EOF
@@ -110,6 +115,8 @@ resource "coder_script" "nexus" {
110115
MAVEN_REPO = local.maven_repo
111116
HAS_NPM = length(var.package_managers.npm) == 0 ? "" : "YES"
112117
NPMRC = local.npmrc
118+
HAS_GO = length(var.package_managers.go) == 0 ? "" : "YES"
119+
GO_REPO = local.go_repo
113120
HAS_PYPI = length(var.package_managers.pypi) == 0 ? "" : "YES"
114121
PYPI_REPO = local.pypi_repo
115122
HAS_DOCKER = length(var.package_managers.docker) == 0 ? "" : "YES"
@@ -118,3 +125,13 @@ resource "coder_script" "nexus" {
118125
run_on_start = true
119126
}
120127

128+
resource "coder_env" "goproxy" {
129+
count = length(var.package_managers.go) == 0 ? 0 : 1
130+
agent_id = var.agent_id
131+
name = "GOPROXY"
132+
value = join(",", [
133+
for repo in var.package_managers.go :
134+
"https://${local.username}:${var.nexus_password}@${local.nexus_host}/repository/${repo}"
135+
])
136+
}
137+

registry/mavrickrishi/modules/nexus/run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ else
5555
not_configured npm
5656
fi
5757

58+
# Configure Go
59+
if [ -n "${HAS_GO}" ]; then
60+
echo "🐹 Configuring Go..."
61+
# Go configuration is handled via GOPROXY environment variable
62+
# which is set by the Terraform configuration
63+
echo "Go proxy configured via GOPROXY environment variable"
64+
config_complete
65+
else
66+
not_configured go
67+
fi
68+
5869
# Configure pip
5970
if [ -n "${HAS_PYPI}" ]; then
6071
echo "🐍 Configuring pip..."

0 commit comments

Comments
 (0)