toys/nexus-tools
anjingyu 63930a3d9b chore: migrate 2024-04-14 23:20:38 +08:00
..
nexus_tools chore: migrate 2024-04-14 23:20:38 +08:00
.gitignore chore: migrate 2024-04-14 23:20:38 +08:00
Jenkinsfile chore: migrate 2024-04-14 23:20:38 +08:00
README.md chore: migrate 2024-04-14 23:20:38 +08:00
pyproject.toml chore: migrate 2024-04-14 23:20:38 +08:00
setup.py chore: migrate 2024-04-14 23:20:38 +08:00

README.md

Nexus Tools

This is a cross-platform command-line tool based on Python3 ONLY, used to upload local files or directories to the raw repository of Nexus server.

Most functions of this command line tool can be implemented by curl directly.

Installation

Now, you can only use our repository in NavInfo internal network.

Append an extra source repository(maintained by NavInfo Simulation Team) to your pip configuration file:

For bash on Linux or macOS:

# Append extra-index-url and trusted-host
sudo python3 -m pip config set global.extra-index-url "http://ip:port/repository/pypi-hosted/simple"
sudo python3 -m pip config set global.trusted-host "ip"

# If you have already append more than one extra-index-url or trusted-host,
# please get them and append our repository
sudo python3 -m pip config set global.extra-index-url "$(python3 -m pip config get global.extra-index-url) http://ip:port/repository/pypi-hosted/simple"
sudo python3 -m pip config set global.trusted-host "$(python3 -m pip config set global.trusted-host) ip"

For powershell on Windows(maybe you need to open a powershell with Administrator permission):

# Append extra-index-url and trusted-host
pip config set global.extra-index-url "http://ip:port/repository/pypi-hosted/simple"
pip config set global.trusted-host "ip"

# If you have already append more than one extra-index-url or trusted-host,
# please get them and append our repository
pip config set global.extra-index-url "$(pip config get global.extra-index-url) http://ip:port/repository/pypi-hosted/simple"
pip config set global.trusted-host "$(pip config get global.trusted-host) ip"

Now, you can download this package via pip:

For bash on Linux or macOS:

# Install into the system path is recommended
sudo -H python3 -m pip install -U nexus-tools

For powershell on Windows(maybe you need to open a powershell with Administrator permission):

pip install -U nexus-tools

Also you can install it manually:

For bash on Linux or macOS:

# Install into the system path is recommended
# sudo -H python3 ./setup.py install
sudo python3 ./setup.py bdist_wheel
sudo -H python3 -m pip install dist/*.whl

For powershell on Windows(maybe you need to open a powershell with Administrator permission):

# Build wheel package is recommended, you can also run install directly
# python .\setup.py install
python .\setup.py bdist_wheel
pip install .\dist\nexus_tools-1.1.0-py3-none-any.whl

Usage

This tool can not delete repository, group or files, you can only overwrite then via upload to the same path.

Command Line Tool

Use the following commands to check the help message and version:

# Show the help message
upload-to-nexus -h

# Show the version information
upload-to-nexus -v

Environment variable NEXUS_UPLOADER_REPO is the default base URL of repository if it exists, and environment variable NEXUS_UPLOADER_USER is the default authorization information if it exists, please set this variable with format 'user:password'.

Upload files and ignore the directory structure:

# Here I assume you have defined environment variable NEXUS_UPLOADER_REPO and NEXUS_UPLOADER_USER
upload-to-nexus -i -f file1.tar.gz dir/file2.tar.gz dir2/dir3/file2.tar.gz README.md index.html -g mygroup

you can also keep the directory structure of each file by removing -i option:

upload-to-nexus -f file1.tar.gz dir/file2.tar.gz dir2/dir3/file2.tar.gz README.md index.html -g mygroup

specify the service base URL via -s and specify user via -u, they have higher priority than environment variables, but environment variables are more friendly for CI/CD just like Jenkins.

Only HTTP protocol is supported now.

# Specify the service base URL, the script will process the tail slash correctly
upload-to-nexus -d mysite -g mygroup -u user:passwd -s http://myip:myport/repository/site

If you just want to see what will happen for your command line, you can use --dry-run, it will only output equivalent curl commands, but never do the actions really.

upload-to-nexus --dry-run -d mysite -g mygroup -u user:passwd -s http://myip:myport/repository/site

Jenkins

Define the environment variables in Jenkins, and then use this script in Jenkinsfile, here is an example, build the website and upload and host it on Nexus:

site_dir = 'site'
group = 'mysite'

pipeline {

    agent {
        label 'linux'
    }

    stages {
        stage('Build') {
            when { anyOf { branch 'master'; buildingTag() } }
            steps {
                sh """
                python3 -m mkdocs build
                """
            }
        }

        stage('Deploy to Nexus') {
            when { anyOf { branch 'master'; buildingTag() } }
            steps {
                sh """
                upload-to-nexus -d ${site_dir} -g ${group}
                """
            }
            post {
                always {
                    archiveArtifacts artifacts: "site/**/*", fingerprint: true
                }
            }
        }
    }
}