Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e32a0b7
feat: add Sonatype Nexus repository integration module
MAVRICK-1 Jul 29, 2025
e2d8aad
Update registry/mavrickrishi/modules/nexus/main.tf
MAVRICK-1 Jul 29, 2025
2a892ad
Update registry/mavrickrishi/modules/nexus/main.tf
MAVRICK-1 Jul 29, 2025
20e9a32
Update registry/mavrickrishi/modules/nexus/main.tf
MAVRICK-1 Jul 29, 2025
af94e5b
fix: apply code formatting
MAVRICK-1 Jul 29, 2025
db7afc8
fixed changes
MAVRICK-1 Jul 30, 2025
09905c3
Update registry/mavrickrishi/modules/nexus/README.md
MAVRICK-1 Jul 30, 2025
56f5990
Update registry/mavrickrishi/modules/nexus/main.tf
MAVRICK-1 Jul 30, 2025
3c890d0
Update registry/mavrickrishi/modules/nexus/main.tf
MAVRICK-1 Jul 30, 2025
88f8284
fix: update Nexus module configurations and README details
MAVRICK-1 Jul 30, 2025
f375e5f
feat: add support for Go package manager in Nexus module and update R…
MAVRICK-1 Jul 30, 2025
97d144b
feat: add test for configuring Go module proxy in Nexus module
MAVRICK-1 Jul 30, 2025
1bd0085
feat: Add Nexus Repository module and related configurations
MAVRICK-1 Jul 30, 2025
1b01b37
Merge branch 'main' into feat/nexus-repository-module
MAVRICK-1 Jul 30, 2025
5534564
Delete .icons/nexus.svg
MAVRICK-1 Jul 30, 2025
0854c5e
fix: remove false positive entries from typos.toml and adjust usernam…
MAVRICK-1 Jul 30, 2025
c520a19
fix: correct username entry for mavrickrishi in typos.toml
MAVRICK-1 Jul 30, 2025
f42da8f
Merge branch 'main' into feat/nexus-repository-module
MAVRICK-1 Aug 1, 2025
9f2fe38
Merge branch 'main' into feat/nexus-repository-module
MAVRICK-1 Aug 4, 2025
0a10b4d
Merge branch 'main' into feat/nexus-repository-module
MAVRICK-1 Aug 4, 2025
8de8da8
Merge branch 'main' into feat/nexus-repository-module
DevelopmentCats Aug 8, 2025
0fd038a
Merge branch 'main' into feat/nexus-repository-module
DevelopmentCats Aug 13, 2025
9f2f3a4
Update registry/mavrickrishi/modules/nexus-repository/README.md
MAVRICK-1 Aug 13, 2025
4a45f09
Merge branch 'main' into feat/nexus-repository-module
MAVRICK-1 Aug 26, 2025
3bdcac7
chore: remove trailing newline from README.md
MAVRICK-1 Aug 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed changes
  • Loading branch information
MAVRICK-1 committed Jul 30, 2025
commit db7afc85fbd89571dd1bc5809b434336eb7582dd
7 changes: 7 additions & 0 deletions .icons/nexus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions registry/mavrickrishi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
display_name: mavrickrishi
bio: Coder module contributor
github: MAVRICK-1
status: community
---

# mavrickrishi

This directory contains Coder modules and templates created by mavrickrishi.

## Modules

- [nexus](./modules/nexus/) - Configure package managers to use Sonatype Nexus Repository
41 changes: 10 additions & 31 deletions registry/mavrickrishi/modules/nexus/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
display_name: Sonatype Nexus Repository
description: Configure package managers to use Sonatype Nexus Repository for Maven, npm, PyPI, and Docker registries.
icon: ../../../../.icons/nexus.svg
icon: /.icons/nexus.svg
verified: true
tags: [integration, nexus, maven, npm, pypi, docker]
---

# Sonatype Nexus Repository

Configure package managers (Maven, npm, PyPI, Docker) to use Sonatype Nexus Repository with API token authentication.
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.

```tf
module "nexus" {
Expand All @@ -26,7 +26,14 @@ module "nexus" {
}
```

> Note: This module configures package managers but does not install them. You need to handle the installation of Maven, npm, Python pip, and Docker yourself.
## Requirements

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

> [!NOTE]
> This module configures package managers but does not install them. You need to handle the installation of Maven, npm, Python pip, and Docker yourself.

## Examples

Expand Down Expand Up @@ -123,31 +130,3 @@ module "nexus" {
}
}
```

## Parameters

- `nexus_url` (required): The base URL of your Nexus repository manager
- `nexus_password` (required): API token or password for authentication (sensitive)
- `nexus_username` (optional): Custom username (defaults to Coder username)
- `username_field` (optional): Field to use for username ("username" or "email", defaults to "username")
- `package_managers` (required): Configuration for package managers:
- `maven`: List of Maven repository names
- `npm`: List of npm repository names (supports scoped packages with "@scope:repo-name")
- `pypi`: List of PyPI repository names
- `docker`: List of Docker registry names

## Features

- ✅ Maven repository configuration with settings.xml
- ✅ npm configuration with .npmrc (including scoped packages)
- ✅ Python pip configuration with pip.conf
- ✅ Docker registry authentication
- ✅ Secure credential handling
- ✅ Multiple repository support per package manager
- ✅ Flexible username configuration

## Requirements

- Nexus Repository Manager 3.x
- Valid API token or user credentials
- Package managers installed on the workspace (Maven, npm, pip, Docker as needed)
152 changes: 40 additions & 112 deletions registry/mavrickrishi/modules/nexus/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = ">= 0.23"
version = ">= 2.5"
}
}
}

variable "nexus_url" {
type = string
description = "Nexus repository URL. e.g. https://nexus.example.com"
description = "The base URL of your Nexus repository manager (e.g. https://nexus.example.com)"
validation {
condition = can(regex("^(https|http)://", var.nexus_url))
error_message = "nexus_url must be a valid URL starting with either 'https://' or 'http://'"
Expand All @@ -20,13 +20,13 @@ variable "nexus_url" {

variable "nexus_username" {
type = string
description = "Username for Nexus authentication"
description = "Custom username for Nexus authentication. If not provided, defaults to the Coder username based on the username_field setting"
default = null
}

variable "nexus_password" {
type = string
description = "Password or API token for Nexus authentication"
description = "API token or password for Nexus authentication. This value is sensitive and should be stored securely"
sensitive = true
}

Expand All @@ -49,8 +49,13 @@ variable "package_managers" {
docker = []
}
description = <<-EOF
A map of package manager names to their respective Nexus repositories. Unused package managers can be omitted.
For example:
Configuration for package managers. Each key maps to a list of Nexus repository names:
- maven: List of Maven repository names
- npm: List of npm repository names (supports scoped packages with "@scope:repo-name")
- pypi: List of PyPI repository names
- docker: List of Docker registry names
Unused package managers can be omitted.
Example:
{
maven = ["maven-public", "maven-releases"]
npm = ["npm-public", "@scoped:npm-private"]
Expand All @@ -62,7 +67,7 @@ variable "package_managers" {

variable "username_field" {
type = string
description = "The field to use for the username. Default 'username'."
description = "Field to use for username (\"username\" or \"email\"). Defaults to \"username\". Only used when nexus_username is not provided"
default = "username"
validation {
condition = can(regex("^(email|username)$", var.username_field))
Expand All @@ -78,115 +83,38 @@ locals {
nexus_host = regex("^https?://([^:/]+)", var.nexus_url)
}

locals {
# Get first repository name or use default
maven_repo = length(var.package_managers.maven) > 0 ? var.package_managers.maven[0] : "maven-public"
npm_repo = length(var.package_managers.npm) > 0 ? var.package_managers.npm[0] : "npm-public"
pypi_repo = length(var.package_managers.pypi) > 0 ? var.package_managers.pypi[0] : "pypi-public"

npmrc = <<-EOF
registry=${var.nexus_url}/repository/${local.npm_repo}/
//${local.nexus_host}/repository/${local.npm_repo}/:username=${local.username}
//${local.nexus_host}/repository/${local.npm_repo}/:_password=${base64encode(var.nexus_password)}
//${local.nexus_host}/repository/${local.npm_repo}/:always-auth=true
EOF
}

resource "coder_script" "nexus" {
agent_id = var.agent_id
display_name = "nexus"
icon = "/icon/nexus.svg"
script = <<-EOT
#!/usr/bin/env bash

not_configured() {
type=$1
echo "🤔 no $type repository is set, skipping $type configuration."
}

config_complete() {
echo "🥳 Configuration complete!"
}

echo "🚀 Configuring Nexus repository access..."

# Configure Maven
if [ ${length(var.package_managers.maven)} -gt 0 ]; then
echo "☕ Configuring Maven..."
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
<servers>
<server>
<id>nexus</id>
<username>${local.username}</username>
<password>${var.nexus_password}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-mirror</id>
<mirrorOf>*</mirrorOf>
<url>${var.nexus_url}/repository/${try(element(var.package_managers.maven, 0), "maven-public")}</url>
</mirror>
</mirrors>
</settings>
EOF
config_complete
else
not_configured maven
fi

# Configure npm
if [ ${length(var.package_managers.npm)} -gt 0 ]; then
echo "📦 Configuring npm..."
cat > ~/.npmrc << 'EOF'
registry=${var.nexus_url}/repository/${try(element(var.package_managers.npm, 0), "npm-public")}/
//${local.nexus_host}/repository/${try(element(var.package_managers.npm, 0), "npm-public")}/:username=${local.username}
//${local.nexus_host}/repository/${try(element(var.package_managers.npm, 0), "npm-public")}/:_password=${base64encode(var.nexus_password)}
//${local.nexus_host}/repository/${try(element(var.package_managers.npm, 0), "npm-public")}/:always-auth=true
EOF
config_complete
else
not_configured npm
fi

# Configure pip
if [ ${length(var.package_managers.pypi)} -gt 0 ]; then
echo "🐍 Configuring pip..."
mkdir -p ~/.pip
# Create .netrc file for secure credential storage
cat > ~/.netrc << EOF
machine ${local.nexus_host}
login ${local.username}
password ${var.nexus_password}
EOF
chmod 600 ~/.netrc

# Update pip.conf to use index-url without embedded credentials
cat > ~/.pip/pip.conf << 'EOF'
[global]
index-url = https://${local.nexus_host}/repository/${try(element(var.package_managers.pypi, 0), "pypi-public")}/simple
EOF
config_complete
else
not_configured pypi
fi

# Configure Docker
if [ ${length(var.package_managers.docker)} -gt 0 ]; then
if command -v docker > /dev/null 2>&1; then
echo "🐳 Configuring Docker credentials..."
mkdir -p ~/.docker
%{for repo in var.package_managers.docker~}
echo -n "${var.nexus_password}" | docker login "${local.nexus_host}" --username "${local.username}" --password-stdin
%{endfor~}
config_complete
else
echo "🤔 Docker is not installed, skipping Docker configuration."
fi
else
not_configured docker
fi

echo "✅ Nexus repository configuration completed!"
EOT
script = templatefile("${path.module}/run.sh", {
NEXUS_URL = var.nexus_url
NEXUS_HOST = local.nexus_host[1]
NEXUS_USERNAME = local.username
NEXUS_PASSWORD = var.nexus_password
HAS_MAVEN = length(var.package_managers.maven) == 0 ? "" : "YES"
MAVEN_REPO = local.maven_repo
HAS_NPM = length(var.package_managers.npm) == 0 ? "" : "YES"
NPMRC = local.npmrc
HAS_PYPI = length(var.package_managers.pypi) == 0 ? "" : "YES"
PYPI_REPO = local.pypi_repo
HAS_DOCKER = length(var.package_managers.docker) == 0 ? "" : "YES"
REGISTER_DOCKER = join("\n ", formatlist("register_docker \"%s\"", var.package_managers.docker))
})
run_on_start = true
}

output "nexus_url" {
description = "The Nexus repository URL"
value = var.nexus_url
}

output "username" {
description = "The username used for Nexus authentication"
value = local.username
}
94 changes: 94 additions & 0 deletions registry/mavrickrishi/modules/nexus/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env bash

not_configured() {
type=$1
echo "🤔 no $type repository is set, skipping $type configuration."
}

config_complete() {
echo "🥳 Configuration complete!"
}

register_docker() {
repo=$1
echo -n "${NEXUS_PASSWORD}" | docker login "${NEXUS_HOST}" --username "${NEXUS_USERNAME}" --password-stdin
}

echo "🚀 Configuring Nexus repository access..."

# Configure Maven
if [ -n "${HAS_MAVEN}" ]; then
echo "☕ Configuring Maven..."
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
<servers>
<server>
<id>nexus</id>
<username>${NEXUS_USERNAME}</username>
<password>${NEXUS_PASSWORD}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-mirror</id>
<mirrorOf>*</mirrorOf>
<url>${NEXUS_URL}/repository/${MAVEN_REPO}</url>
</mirror>
</mirrors>
</settings>
EOF
config_complete
else
not_configured maven
fi

# Configure npm
if [ -n "${HAS_NPM}" ]; then
echo "📦 Configuring npm..."
cat > ~/.npmrc << 'EOF'
${NPMRC}
EOF
config_complete
else
not_configured npm
fi

# Configure pip
if [ -n "${HAS_PYPI}" ]; then
echo "🐍 Configuring pip..."
mkdir -p ~/.pip
# Create .netrc file for secure credential storage
cat > ~/.netrc << EOF
machine ${NEXUS_HOST}
login ${NEXUS_USERNAME}
password ${NEXUS_PASSWORD}
EOF
chmod 600 ~/.netrc

# Update pip.conf to use index-url without embedded credentials
cat > ~/.pip/pip.conf << 'EOF'
[global]
index-url = https://${NEXUS_HOST}/repository/${PYPI_REPO}/simple
EOF
config_complete
else
not_configured pypi
fi

# Configure Docker
if [ -n "${HAS_DOCKER}" ]; then
if command -v docker > /dev/null 2>&1; then
echo "🐳 Configuring Docker credentials..."
mkdir -p ~/.docker
${REGISTER_DOCKER}
config_complete
else
echo "🤔 Docker is not installed, skipping Docker configuration."
fi
else
not_configured docker
fi

echo "✅ Nexus repository configuration completed!"
Loading