Migrate from Sonatype Nexus Repository
This page moves the files in your Nexus Repository 3 repositories to CloudRepo and repoints your builds, with Nexus left running until your builds pass against CloudRepo. It copies files and nothing else: your users, permissions and every other piece of data that is not a file stay in Nexus. For hosted Maven, PyPI and Docker repositories (Docker from version 0.6.0), one command does steps 3 and 4 and checks every file: every Maven file, every wheel and sdist of a PyPI repository, every tag of a Docker repository, and every version of each npm package with its dist-tags.
- List what you have and decide where each repository goes.
- Create the repositories in CloudRepo.
- Export the files from Nexus.
- Import them into CloudRepo.
- Repoint your builds.
- Check, then cut over.
1. List what you have
Section titled “1. List what you have”You need a CloudRepo organization. No account yet? Start free trial. 14 days free. No credit card required.
List your repositories with the Nexus REST API. It returns the repositories your authenticated user has browse permission to access. Pass curl a Nexus user credential that can read them through a netrc file, as in step 3.
curl --netrc-file ~/.nexus.netrc --silent --fail \ "https://nexus.example.com/service/rest/v1/repositories" | jq -r '.[] | [.name, .format, .type] | @tsv'Then decide where each one goes. The left column uses the format and type names that Sonatype’s repositories API returns:
| In Nexus | In CloudRepo |
|---|---|
Hosted repository, format maven2, npm, pypi or docker |
A repository of that format. Its files are what you export and import. |
| Proxy repository | A proxy repository, if the upstream is one CloudRepo offers. Nothing to export: a proxy fills itself from the upstream. |
| Group repository | No copy. Sonatype describes a repository group as the aggregated content of multiple proxy and hosted repositories under one URL, so you move those. Point builds at the CloudRepo repositories directly. For Maven, Docker, PyPI, npm and Go (PyPI, npm and Go in early access), a group repository can serve several repositories under one address. |
Hosted repository, format raw |
A Maven repository: CloudRepo has no raw type, and a Maven repository serves any file at any path. From version 0.8.0, cloudrepo-migrate nexus3 moves it into one when --repo names it, every file at the same path. |
Proxy repository, format go or yum |
A Go or yum proxy repository, in early access, if the upstream is one CloudRepo offers. |
| Any other format | No CloudRepo repository for it. CloudRepo hosts Maven, Python, npm and Docker, and proxies Go and yum in early access. |
This page covers Nexus Repository 3, whose REST API the commands use. For its hosted Maven, PyPI and Docker repositories (Docker from version 0.6.0), and for its hosted npm repositories every version of each package with its dist-tags, one command moves them. For Nexus 2, one command moves the hosted Maven repositories and every version of each npm package with its dist-tags. For another Nexus version, export the files by any means that keeps each repository’s directory layout, then continue at step 4. Leaving JFrog Artifactory? One command moves its local Maven repositories.
2. Create the repositories
Section titled “2. Create the repositories”For each hosted repository, create a repository of the same format in CloudRepo. Give it the name your builds already use if you can, so a URL only changes in one place. See Creating a repository. Then add users who need access. Create a repository token with Download and publish packages for the import, and Download packages tokens for builds that only pull. Nexus roles do not copy: you set each user’s access when you add them to CloudRepo.
3. Export the files
Section titled “3. Export the files”Give your Nexus credential to curl through a netrc file, so it is on no command line.
machine nexus.example.comlogin nexus-userpassword NEXUS_PASSWORDKeep the file readable by you alone (chmod 600 ~/.nexus.netrc). Then, for each hosted repository, page through its assets with the assets API and download each one into a directory named for the repository. Per Sonatype’s pagination page, each response includes a continuationToken while more items remain; pass it back as continuationToken= on the same query for the next page, and stop when the token is null:
HOST=https://nexus.example.comREPO=maven-releases( NEXT="" : > "$REPO.txt" while :; do more=() [ -n "$NEXT" ] && more=(--data-urlencode "continuationToken=$NEXT") page=$(curl --netrc-file ~/.nexus.netrc --silent --show-error --fail --get --data-urlencode "repository=$REPO" \ "${more[@]}" "$HOST/service/rest/v1/assets") \ || { echo "FAILED: could not list $REPO" >&2; exit 1; } printf '%s' "$page" | jq -r '.items[] | [.path, .downloadUrl] | @tsv' >> "$REPO.txt" \ || { echo "FAILED: could not read the list of $REPO" >&2; exit 1; } NEXT=$(printf '%s' "$page" | jq -r '.continuationToken // empty') [ -n "$NEXT" ] || break done : > "$REPO.failed.txt" failed=0 while IFS=$'\t' read -r asset_path url; do curl --netrc-file ~/.nexus.netrc --silent --show-error --fail --create-dirs \ --output "export/$REPO/$asset_path" "$url" \ || { echo "FAILED: $asset_path" >&2; echo "$asset_path" >> "$REPO.failed.txt"; rm -f "export/$REPO/$asset_path"; failed=$((failed + 1)); } done < "$REPO.txt" total=$(wc -l < "$REPO.txt" | tr -d ' ') if [ "$failed" -gt 0 ]; then echo "$failed of $total assets could not be fetched; their paths are in $REPO.failed.txt" >&2 exit 1 fi echo "Exported $total assets from $REPO")Expected: export/<repository>/ holds every asset the assets API listed, saved at the path it
gives that asset. The loop prints each asset it could not fetch, writes those paths to <repository>.failed.txt, and exits with a non-zero status if any failed or if the list could not be read. For a Maven repository that is the Maven layout CloudRepo takes as it is. The
import loops look under ./export for npm tarballs (.tgz), Python
wheels (.whl) and source distributions (.tar.gz), wherever they sit.
Docker images
Section titled “Docker images”From version 0.6.0, cloudrepo-migrate nexus3 moves a hosted Docker repository on Nexus 3 to CloudRepo with no export:
every tag, its manifest and every layer, as Docker images on
its page explains.
- What moves. Hosted Docker repositories. Every layer is checked against the digest its manifest names and uploaded by that digest. Every manifest is read back from CloudRepo and compared by digest.
- What is skipped. A Docker proxy repository, as
proxy ofits remote: create a proxy repository in CloudRepo instead. A Docker group repository, as agroup repository: move the repositories it groups. - The token.
CLOUDREPO_TOKENmust be a CloudRepo repository token with Download and publish packages on the target Docker repository. There is no username to set.
Create the Docker repository in CloudRepo, put the credentials in the environment as NEXUS_USERNAME,
NEXUS_PASSWORD and CLOUDREPO_TOKEN, and use your Nexus repository’s name for docker-hosted. A dry run lists what
would move and uploads nothing:
cloudrepo-migrate nexus3 \ --nexus-url https://nexus.example.com \ --org your-org \ --repo docker-hosted \ --dry-runWhen the list looks right, run it for real:
cloudrepo-migrate nexus3 \ --nexus-url https://nexus.example.com \ --org your-org \ --repo docker-hosted \ --report-json report.jsonIf you would rather copy images yourself, list the ones you want to keep as name:tag lines in images.txt. The import then copies each image with the Docker CLI.
4. Import the files
Section titled “4. Import the files”Import artifacts into CloudRepo has one loop for each format. Run it for each repository, then check the bytes arrived. You can run a loop again after a failure, and what a second run skips and what it replaces depends on the format: see Running a loop again.
5. Repoint your builds
Section titled “5. Repoint your builds”In each build, replace the Nexus URL and credential with the CloudRepo repository’s URL and a repository token. The page for your build tool shows the file to change:
Pull Maven artifacts and Publish Maven artifacts:
~/.m2/settings.xml holds the credential, and pom.xml holds the repository URL.
Pull Gradle dependencies and
Publish Gradle artifacts: ~/.gradle/gradle.properties holds the
credential, and your build script holds the repository URL.
Pull npm packages and Publish npm packages: ~/.npmrc
holds the registry and the token.
Pull Python packages and
Publish Python packages: pip.conf or PIP_INDEX_URL, and ~/.pypirc or
TWINE_* for uploads.
Pull Docker images and Push Docker images:
docker login takes your CloudRepo host, and image names carry /repositories/<repository>/.
The username for every client except npm is the email address of the account that created the token, and the password is the token. In CI, store the token in the CI system’s secret store and expose it as an environment variable, as the pages above show; do not write it into a script or a committed file.
A lockfile holds URLs too. Change every Nexus and Artifactory URL in your builds, lockfiles included
maps each Nexus URL to its CloudRepo URL, finds every one in your repositories and regenerates package-lock.json,
yarn.lock, poetry.lock and uv.lock.
A script can call Nexus too. If one calls the Nexus REST API to fetch the latest version of an artifact or to upload a file, REST calls in your scripts after Nexus or Artifactory shows the call to run against CloudRepo in its place, and the calls that have none.
6. Check, then cut over
Section titled “6. Check, then cut over”Do this in order, and leave Nexus running until the last step:
- Build against CloudRepo, with Nexus still up. Point one project at CloudRepo and run its full build,
then the projects that depend on it. A
401,403or404has the same causes as when you publish by hand: see “When a Client Answers 401, 403 or 404” on Repository tokens. - Publish one new version to CloudRepo from CI and install it from a second machine.
- Switch every build that still names Nexus, and every CI job’s secret, to CloudRepo.
- Stop publishing to Nexus. From now on a new version exists in CloudRepo only.
- Keep an export of Nexus until you are sure nothing reads it. Step 3 of this page is that export.
Webhooks, if you used any, are not copied. CloudRepo’s are in Webhooks, and Move Artifactory and Nexus webhooks to CloudRepo maps each Nexus event and payload field to them.
If you are stuck, email support@cloudrepo.io with your organization name, the repositories involved, the command you ran and the error it printed.