From 9c1019771239a5c28c9b5c42befeb23a12ac1228 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Mon, 9 Dec 2024 08:40:24 +0000 Subject: [PATCH] use the nexus api to create the npm repositories --- README.md | 2 +- provision/provision-nexus.sh | 83 +++++++++++++++++++ .../src/main/groovy/provision.groovy | 9 -- 3 files changed, 84 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3a3f921..1ca5837 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ This will: * Configure Nexus through the API. * Create the `adhoc-package` repository. * Create the `apt-hosted` repository. + * Create the `npm-group`, `npm-hosted` and `npmjs.org-proxy` repositories. * Configure the NuGet `nuget-hosted` repository to accept pushing with an API key. * Configure Nexus through Groovy scripts. - * Create the `npm-group`, `npm-hosted` and `npmjs.org-proxy` repositories. * Create the `chocolatey-group`, `chocolatey-hosted` and `chocolatey.org-proxy` repositories. * Create the `powershell-group`, `powershell-hosted` and `powershellgallery.com-proxy` repositories. * Schedule a task to remove the old snapshots from the `maven-snapshots` repository. diff --git a/provision/provision-nexus.sh b/provision/provision-nexus.sh index 4a3d8e3..0c47cc1 100644 --- a/provision/provision-nexus.sh +++ b/provision/provision-nexus.sh @@ -219,6 +219,89 @@ http \ } } EOF + + +# create the npm-hosted npm repository. +# see https://help.sonatype.com/display/NXRM3/Node+Packaged+Modules+and+npm+Registries +http \ + --check-status \ + --auth "$api_auth" \ + POST \ + https://$nexus_domain/service/rest/v1/repositories/npm/hosted \ + <<'EOF' +{ + "name": "npm-hosted", + "online": true, + "storage": { + "blobStoreName": "default", + "strictContentTypeValidation": true, + "writePolicy": "allow_once" + }, + "component": { + "proprietaryComponents": true + } +} +EOF + + +# create the npmjs.org-proxy npm proxy repository. +# see https://help.sonatype.com/display/NXRM3/Node+Packaged+Modules+and+npm+Registries +http \ + --check-status \ + --auth "$api_auth" \ + POST \ + https://$nexus_domain/service/rest/v1/repositories/npm/proxy \ + <<'EOF' +{ + "name": "npmjs.org-proxy", + "online": true, + "storage": { + "blobStoreName": "default", + "strictContentTypeValidation": true, + "writePolicy": "allow_once" + }, + "proxy": { + "remoteUrl": "https://registry.npmjs.org", + "contentMaxAge": 1440, + "metadataMaxAge": 1440 + }, + "negativeCache": { + "enabled": true, + "timeToLive": 1440 + }, + "httpClient": { + "blocked": false, + "autoBlock": true + } +} +EOF + + +# create the npm-group npm group repository. +# see https://help.sonatype.com/display/NXRM3/Node+Packaged+Modules+and+npm+Registries +http \ + --check-status \ + --auth "$api_auth" \ + POST \ + https://$nexus_domain/service/rest/v1/repositories/npm/group \ + <<'EOF' +{ + "name": "npm-group", + "online": true, + "storage": { + "blobStoreName": "default", + "strictContentTypeValidation": true + }, + "group": { + "memberNames": [ + "npm-hosted", + "npmjs.org-proxy" + ] + } +} +EOF + + # create the pypi-hosted repository. http \ --check-status \ diff --git a/provision/provision-nexus/src/main/groovy/provision.groovy b/provision/provision-nexus/src/main/groovy/provision.groovy index b25ca4c..37bcb7c 100644 --- a/provision/provision-nexus/src/main/groovy/provision.groovy +++ b/provision/provision-nexus/src/main/groovy/provision.groovy @@ -26,15 +26,6 @@ capabilityRegistry.all.findAll {it.context().type().toString().startsWith("Outre //]) -// create a npm repository backed by the default blob store. -repository.createNpmHosted("npm-hosted", "default", true, WritePolicy.ALLOW_ONCE) -// create a npm proxy repository backed by the default blob store. -// see https://help.sonatype.com/display/NXRM3/Node+Packaged+Modules+and+npm+Registries -repository.createNpmProxy("npmjs.org-proxy", "https://registry.npmjs.org", "default") -// create a npm group repository that merges the npm-host and npmjs.org-proxy together. -repository.createNpmGroup("npm-group", ["npm-hosted", "npmjs.org-proxy"], "default") - - // modify the default nuget-hosted repository for not allowing re-deployments. config = repository.repositoryManager.get("nuget-hosted").configuration.copy() config.attributes.storage.writePolicy = WritePolicy.ALLOW_ONCE