Help Center> CodeArts Artifact> User Guide> Self-hosted Repo (New Version)> Uploading and Downloading Private Components
Updated on 2023-12-19 GMT+08:00

Uploading and Downloading Private Components

Uploading a Maven Component

  • The client tool is Maven. Ensure that the JDK and Maven have been installed.
    1. Download the settings.xml file from a self-hosted repo page and replace the downloaded configuration file with the new one or modify the settings.xml file of Maven as prompted.

    2. Run the following command to upload a component on the client:

      Run the following commands in the directory where the uploaded POM file is located:

      mvn deploy:deploy-file -DgroupId={groupId} -DartifactId={artifactId} -Dversion={version} -Dpackaging=jar -Dfile={file_path} -DpomFile={pom_path} -Durl={url} -DrepositoryId={repositoryId} -s {settings_path} -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true
      • Description
        • DgroupId: uploaded group ID
        • DartifactId: uploaded artifact ID
        • Dversion: version of the uploaded file
        • Dpackaging: type of the package to be uploaded, such as JAR, ZIP, and WAR
        • Dfile: path of the uploaded entity file
        • DpomFile: path of the entity POM file to be uploaded. (For a release version, if this parameter does not exist, the system automatically generates a POM file. If there are special requirements for the POM file, specify this parameter.)
        • The values of DgroupId, DartifactId, and Dversion in the POM file must be the same as those outside the POM file. Otherwise, error 409 is reported.
        • Select either DpomFile or one of DgroupId, DartifactId, and Dversion.
        • Durl: path for uploading files to the repository.
        • DrepositoryId: ID corresponding to the username and password configured in Settings, as shown in the following figure.

Downloading a Maven Component

  • The client tool is Maven. Ensure that the JDK and Maven have been installed.

    1. Download the settings.xml file from a self-hosted repo page and replace the downloaded configuration file with the new one or modify the settings.xml file of Maven as prompted.

    2. Run the following commands to download the client:
    mvn dependency:get -DremoteRepositories={repo_url} -DgroupId={groupId} -DartifactId={artifactId} -Dversion={version} -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true

Uploading an npm Component

  • The client tool is npm. Ensure that node.js (or io.js) and npm have been installed.

    1. Download the NPMRC file from the self-hosted repo page and save the downloaded NPMRC file as a .npmrc file.

    2. Copy the file to the user directory. In Linux, the path is ~/.npmrc (C:\Users\<UserName>\.npmrc).

    3. Go to the npm project directory (where the package.json file is stored), open the package.json file, and add the path information entered during repository creation to the value of the name field.

    4. Run the following commands to upload the npm component to the repository:
    npm config set strict-ssl false
    npm publish

Downloading an npm Component

  • The client tool is npm. Ensure that node.js (or io.js) and npm have been installed.

    1. Download the NPMRC file from the self-hosted repo page and save the downloaded NPMRC file as a .npmrc file.

    2. Copy the file to the user directory. In Linux, the path is ~/.npmrc. In Windows, the path is C:\Users\<UserName>\.npmrc.

    3. Go to the npm project directory (where the package.json file is stored) and run the following commands to download the npm dependent component:
    npm config set strict-ssl false
    npm install ––verbose

Uploading a PyPI Component

  • The client tools are python and twine. Ensure that python and twine have been installed.

    1. Download the PYPIRC file from the self-hosted repo page and save the downloaded PYPIRC file as a .pypirc file.

    2. Copy the file to the user directory. In Linux, the path is ~/.pypirc. In Windows, the path is C:\Users\<UserName>\.pypirc.

    3. Go to the Python project directory and run the following command to compress the Python project into a .whl package:
    python setup.py bdist_wheel
    4. Run the following command to upload the file to the repository:
    python -m twine upload -r pypi dist/*

    If a certificate error is reported during the upload, run the following command (use git bash in Windows) to set environment variables to skip certificate verification:

    export CURL_CA_BUNDLE=""

    The environment variables will be cleared after you log in to the server again, switch to another user, or open the bash window again. Add the environment variables before each upload.

Downloading a PyPI Component

  • The client tools are python and pip. Ensure that python and pip have been installed.

    1. Download the pip.ini file from the self-hosted repo page and copy the file to the user directory. In Linux, the path is ~/.pip/pip.conf (C:\Users\<UserName>\pip\pip.ini on Windows)

    2. Run the following command to install Python:
    pip install {package name}

Uploading and Downloading a Go Component

The client tool is Go. Ensure that V1.13 or a later version has been installed and the project is a Go module project.

  • Go Modules packaging mode and package upload

    This section describes how to build and upload Go components through Go module packaging. The username and password used in the following steps can be obtained from the downloaded configuration file for the Go repository.

    Perform the following steps:

    1. Create a source folder in the working directory.
      mkdir -p {module}@{version}
    2. Copy the code source to the source folder.
      cp -rf . {module}@{version}
    3. Compress the component into a ZIP package.
      zip -D -r [package name] [package root directory]
    4. Upload the component ZIP package and the go.mod file to the self-hosted repo.
      curl -k -u {{username}}:{{password}} -X PUT {{repoUrl}}/{filePath} -T {{localFile}}

      The component directory varies according to the package version. The version can be:

      • Versions earlier than v2.0: The directory is the same as the path of the go.mod file. No special directory structure is required.
      • v2.0 or later:
        • If the first line in the go.mod file ends with /vX, the directory must contain /vX. For example, if the version is v2.0.1, the directory must contain v2.
        • If the first line in the go.mod file does not end with /vN, the directory remains unchanged and the name of the file to be uploaded must contain +incompatible.

        Here are a few versions.

    Versions earlier than v2.0

    The go.mod file is used as an example.

    1. Create a source folder in the working directory.

      The value of module is example.com/demo and that of version is 1.0.0. The command is as follows:

      mkdir -p ~/example.com/demo@v1.0.0
    2. Copy the code source to the source folder.

      The command is as follows (with the same parameter values as the previous command):

      cp -rf . ~/example.com/demo@v1.0.0/
    3. Compress the component into a ZIP package.

      Run the following command to go to the upper-level directory of the root directory where the ZIP package is located:

      cd ~

      Then, use the zip command to compress the code into a component package. In this command, the package root directory is example.com and the package name is v1.0.0.zip. The command is as follows:

      zip -D -r v1.0.0.zip  example.com/
    4. Upload the component ZIP package and the go.mod file to the self-hosted repo.

      Parameters username, password, and repoUrl can be obtained from the configuration file of the self-hosted repo.

      • For the ZIP package, the value of filePath is example.com/demo/@v/v1.0.0.zip and that of localFile is v1.0.0.zip.
      • For the go.mod file, the value of filePath is example.com/demo/@v/v1.0.0.mod and that of localFile is example.com/demo@v1.0.0/go.mod.

      The command is as follows (replace username, password, and repoUrl with the actual values):

      curl -k -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v1.0.0.zip -T v1.0.0.zip
      curl -k -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v1.0.0.mod -T example.com/demo@v1.0.0/go.mod

  • v2.0 and later, with the first line in the go.mod file ends with /vX.

    The go.mod file is used as an example.

    1. Create a source folder in the working directory.

      The value of module is example.com/demo/v2 and that of version is 2.0.0. The command is as follows:

      mkdir -p ~/example.com/demo/v2@v2.0.0
    2. Copy the code source to the source folder.
      The command is as follows (with the same parameter values as the previous command):
      cp -rf . ~/example.com/demo/v2@v2.0.0/
    3. Compress the component into a ZIP package.

      Run the following command to go to the upper-level directory of the root directory where the ZIP package is located:

      cd ~

      Then, use the zip command to compress the code into a component package. In this command, the package root directory is example.com and the package name is v2.0.0.zip. The command is as follows:

      zip -D -r v2.0.0.zip  example.com/
    4. Upload the component ZIP package and the go.mod file to the self-hosted repo.

      Parameters username, password, and repoUrl can be obtained from the configuration file of the self-hosted repo.

      • For the ZIP package, the value of filePath is example.com/demo/v2/@v/v2.0.0.zip and that of localFile is v2.0.0.zip.
      • For the go.mod file, the value of filePath is example.com/demo/v2/@v/v2.0.0.mod and that of localFile is example.com/demo/v2@v2.0.0/go.mod.

      The command is as follows (replace username, password, and repoUrl with the actual values):

      curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/v2/@v/v2.0.0.zip -T v2.0.0.zip
      curl -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/v2/@v/v2.0.0.mod -T example.com/demo/v2@v2.0.0/go.mod
  • v2.0 and later, with the first line in the go.mod file does not end with /vX.

    The go.mod file is used as an example.

    1. Create a source folder in the working directory.

      The value of module is example.com/demo and that of version is 3.0.0. The command is as follows:

      mkdir -p ~/example.com/demo@v3.0.0+incompatible
    2. Copy the code source to the source folder.

      The command is as follows (with the same parameter values as the previous command):

      cp -rf . ~/example.com/demo@v3.0.0+incompatible/
    3. Compress the component into a ZIP package.

      Run the following command to go to the upper-level directory of the root directory where the ZIP package is located:

      cd ~

      Then, use the zip command to compress the code into a component package. In this command, the package root directory is example.com and the package name is v3.0.0.zip. The command is as follows:

      zip -D -r v3.0.0.zip  example.com/
    4. Upload the component ZIP package and the go.mod file to the self-hosted repo.

      Parameters username, password, and repoUrl can be obtained from the configuration file of the self-hosted repo.

      • For the ZIP package, the value of filePath is example.com/demo/@v/v3.0.0+incompatible.zip and that of localFile is v3.0.0.zip.
      • For the go.mod file, the value of filePath is example.com/demo/@v/v3.0.0+incompatible.mod and that of localFile is example.com/demo@v3.0.0+incompatible/go.mod.

      The command is as follows (replace username, password, and repoUrl with the actual values):

      curl -k -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v3.0.0+incompatible.zip -T v3.0.0.zip
      curl -k -u {{username}}:{{password}} -X PUT {{repoUrl}}/example.com/demo/@v/v3.0.0+incompatible.mod -T example.com/demo@v3.0.0+incompatible/go.mod
      • Download the Go component using the Go client.

        Certificate verification cannot be ignored on the Go client. You need to add the domain name certificate corresponding to the self-hosted repo to the local certificate trustlist and perform the following steps to add the trust certificate list:

        1. Export a certificate.
          openssl s_client -connect {host}:443 -showcerts </dev/null 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' |openssl x509 -outform PEM >mycertfile.pem
          openssl x509 -outform der -in mycertfile.pem -out mycertfile.crt

          mycertfile.pem and mycertfile.crt are the downloaded certificates.

        2. Add the certificate to the root certificate trust list.

        3. Run the go commands to download the dependency package.
          ##1. Packages of versions earlier than v2.0
          go get -v <moudlename>
          ##2. v2.0 and later versions
          ##a. The ZIP package contains go.mod and the path ends with /vN.
          go get -v {{moduleName}}/vN@{{version}}
          ##b. The ZIP package does not contain go.mod or the first line in go.mod does not end with /vN.
          go get -v {moduleName}}@{{version}}+incompatible

Uploading and Downloading an RPM Component

Use the Linux OS and yum tool. Ensure that the Linux OS is used and yum has been installed.

  • Releasing a Component to a Self-Hosted RPM Repo
  1. Check whether the yum tool is installed in Linux.

    On the Linux host, run the following command:
    rpm -qa yum

    If the following information is displayed, yum has been installed on the server:

  2. Log in to the CodeArts homepage and access the self-hosted repo for RPM. Click Tutorial on the right of the page.
  3. In the displayed dialog box, click Download Configuration File.

  4. On the Linux host, run the following commands to upload an RPM component:

    curl -k -u {{user}}:{{password}} -X PUT https://{{repoUrl}}/{{component}}/{{version}}/ -T {{localFile}}

    In this command, user, password, and repoUrl can be obtained from the RPM upload command in the configuration file downloaded in the previous step.

    • user: character string before the colon (:) between curl -u and -X
    • password: character string after the colon (:) between curl -u and -X
    • repoUrl: character string between https:// and /{{component}}

      component, version, and localFile can be obtained from the RPM component. The hello-0.17.2-54.x86_64.rpm component is used as an example.

      • component: software name, for example, hello.
      • version: software version, for example, 0.17.2.
      • localFile: RPM component, for example, hello-0.17.2-54.x86_64.rpm.

        The following figure shows the complete command.

        After the command is successfully executed, go to the self-hosted repo and find the uploaded RPM component.

Obtaining a Dependency from a Self-hosted RPM Repo

The following section uses the RPM private component released in Releasing a Component to a Self-hosted RPM Repo as an example to describe how to obtain dependency packages from the self-hosted RPM repo.

  1. Download the configuration file of the self-hosted RPM repo by referring to 2 and 3 of the released RPM component.
  2. Open the configuration file, replace all {{component}} in the file with the value of {{component}} (hello in this file) used for uploading the RPM file, delete the RPM upload command, and save the file.
  3. Save the modified configuration file to the /etc/yum.repos.d/ directory on the Linux host.

  4. Run the following command to download the RPM component: Replace hello with the actual value of component.

    yum install hello

Uploading a Conan Component

Conan is a package manager for C and C++ developers. It applies to all operating systems, such as Windows, Linux, OSX, FreeBSD, and Solaris.

Prerequisites

  • You have installed the Conan client.
  • The Conan repository has been created in the self-hosted repo.
  1. Select the corresponding Conan repository from the self-hosted repo page and click Tutorial to download the configuration file.

    You can replace local Conan configurations with the obtained configuration file (the path is ~/.conan/remotes.json in Linux or C:\Users\<UserName>\.conan\remotes.json in Windows).

  2. Copy and run the following commands on the configuration page to add the self-hosted repo to the local Conan client:

    conan remote add Conan {repository_url} 
    conan user {user_name} -p={repo_password} -r=Conan

    Run the following command to check whether the remote repository has been configured on the Conan client:

    conan remote list

  3. Upload all software packages to the remote repository. In the example, my_local_server is an example remote repository. You can replace it with your own repository.

    $ conan upload hello/0.1@demo/testing --all -r=my_local_server 

  4. View the software packages that have been uploaded to the remote repository.

    $ conan search hello/0.1@demo/testing -r=my_local_server

Downloading a Conan Component

  1. Select the corresponding Conan repository from the self-hosted repo page and click Tutorial to download the configuration file.

    You can replace local Conan configurations with the obtained configuration file (the path is ~/.conan/remotes.json in Linux or C:\Users\<UserName>\.conan\remotes.json in Windows).

  2. Run the following commands to download the Conan dependency package from the remote repository.

    $ conan install ${package_name}/${package_version}@${package_username}/${channel} -r=cloud_artifact

  3. Run the following command to view the downloaded Conan software package.

    $ conan search "*"

  4. Run the following command to remove the software package from the local cache.

    $ conan remove ${package_name}/${package_version}@${package_username}/${channel}

Uploading a NuGet Component

Ensure that you have installed the NuGet.

  1. Select the corresponding NuGet repository from the self-hosted repo page and click Tutorial to download the configuration file NuGet.txt.

  2. Open the downloaded configuration file and run the following commands to add the source:

    ##----------------------NuGet add source----------------------##
    nuget sources add -name {repo_name} -source {repo_url} -username {user_name} -password {repo_password}

  3. Run the following commands to upload the package. Replace <PATH_TO_FILE> with the path of the file to be uploaded and run the upload statement. (If a configuration source exists, use the configured source name as the parameter following -source.)

    ##----------------------NuGet Download----------------------##
    nuget push <PATH_TO_FILE> -source <SOURCE_NAME>

Uploading a .NET Component

Ensure that you have installed .NET.

You can use the .NET client only after you have added the trusted server certificate.

  • To obtain the Windows trust certificate, perform the following steps:

    1. Export the server certificate.

    openssl s_client -connect {host}:443 -showcerts </dev/null 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' |openssl x509 -outform PEM >mycertfile.pem
    openssl x509 -outform der -in mycertfile.pem -out mycertfile.crt

    mycertfile.pem and mycertfile.crt are the downloaded certificates.

    2. In Windows, you need to use PowerShell to add the certificate trust.

    Add a certificate

    Import-Certificate -FilePath "mycertfile.crt" -CertStoreLocation cert:\CurrentUser\Root
  1. Select the corresponding NuGet repository from the self-hosted repo page and click Tutorial to download the configuration file dotnet.txt.

  2. Open the configuration file, find the command under dotnet add source, and add the source.

    ##----------------------dotnet add source----------------------##
    dotnet nuget add source {repo_url} add -n {repo_name} -u {user_name} -p {repo_password}

  3. Find the statement under dotnet upload, replace <PATH_TO_FILE> with the path of the file to be uploaded, and run the upload statement.

    ##----------------------dotnet upload----------------------##
    dotnet nuget push <PATH_TO_FILE> -s {repo_name}

Downloading a NuGet Component

Ensure that you have installed the NuGet.

  1. Select the corresponding NuGet repository from the self-hosted repo page and click Tutorial to download the configuration file NuGet.txt.

  2. Open the configuration file, find the command under NuGet add source, and add the source.

    ##----------------------NuGet add source----------------------##
    nuget sources add -name {repo_name} -source{repo_url} -username {user_name} -password {repo_password}

  3. Open the configuration file, find the statement under NuGet Download, replace <PACKAGE> with the name of the component to be downloaded, and run the download statement. (If a configuration source exists, use the configured source name as the parameter following -source.)

    ##----------------------NuGet Download----------------------##
    nuget install <PACKAGE>

Downloading a .NET Component

Ensure that you have installed .NET.

  1. Select the corresponding NuGet repository from the self-hosted repo page and click Tutorial to download the configuration file dotnet.txt.

  2. Open the configuration file, find the command under dotnet add source, and add the source.

    ##----------------------dotnet add source----------------------##
    dotnet nuget add source {repo_url} add -n {repo_name} -u {user_name} -p {repo_password}

  3. Find the statement under dotnet download, replace < PACKAGE > with the name of the component to be downloaded, and run the download statement.

    ##----------------------dotnet download----------------------##
    dotnet add package <PACKAGE>