JFrog Help Center

Our new portal is coming soon!
Documentation + Knowledge Base





JFrog Help Center - A new knowledge experience is coming your way soon!



You are viewing an old version of this page. View thecurrent version.

Compare with CurrentView Page History

« PreviousVersion 20Next »

Overview

Artifactory provides full support for RubyGems repositories including:

  • Local repositories with RubyGems API support
  • Caching and proxying remote RubyGems repositories
  • 聚合多个本地虚拟存储库and remote repositories including indices of both gems and specifications
  • Support for common Ruby tools such as gem and bundler
  • Support for Bundler Compact index for Local and Remote repositories, providing you with the latest version of the package that is compatible with your installed Ruby version of the project.

For general information on configuring Artifactory to work with RubyGems, please refer toConfiguring Artifactory.

Page Contents



General Configuration

All RubyGems repositories must be prefixed with api/gems in the path

When using the RubyGems command line to access a repository through Artifactory, the repository URL must be prefixed withapi/gemsin the path.

All RubyGems commands, includinggem sourceandgem push,must prepend the repository path withapi/gems.

For example, if you are using Artifactory standalone or as a local service, you would access your RubyGems repositories using the following URL:

http://localhost:8081/artifactory/api/gems/

Or, if you are using Artifactory Cloud, the URL would be:

https://.jfrog.io/artifactory/api/gems/


Local Repositories

Local RubyGems repositories are physical, locally-managed repositories into which you can deploy and manage your in-house Gems.

To create a local RubyGems repository, in theAdministrationmodule, underRepositories | Repositories | Local,clickNew Local Repositoryand setGemsto be thePackage Type.


You can set up a local RubyGems repository as follows:

You need to add the repository source URL by modifying your~/.gemrcfile or using thegem sourcecommand as displayed below. You can extract the source URL by selecting the repository in the Tree Browser and clickingSet Me Up.

Notice that there are two sources. First, the remote proxy, then the local one. This will effectively allow you to retrieve Gems from both of them in the specified order.

All RubyGems repositories must be prefixed with api/gems in the path

When using the RubyGems command line to access a repository through Artifactory, the repository URL must be prepended withapi/gemsin the path.

gem source -a http://localhost:8081/artifactory/api/gems/my-gems-local/

Default Files

Upon creation of a Local RubyGems repository, Artifactory populates it with the following set of files that are required for indexing the repository:

  • rubygems-update-*.gem(created under thegemsfolder of the repository)
  • quick/Marshal.*
  • latest_specs.*.gz
  • prerelease_specs.*.gz
  • specs.*.gz

The local RubyGems repository is displayed in theApplicationmodule |Artifactory|Artifacts.

Usage

First, setup the appropriatecredentialsfor thegemtool: either include the API key in the~/.gem/credentialsfile or issue this command:

Setting Up Credentials
curl http://localhost:8081/artifactory/api/gems//api/v1/api_key.yaml -u admin:password > ~/.gem/credentials

Running on Linux

You may need to change the permissions of the credentials file to 600 (chmod 600)

Running on Windows

The credentials file is located under%USERPROFILE%/.gem/credentials

You also need to set the API key encoding to be "ASCII". For example:

curlhttp://localhost:8081/artifactory/api/gems//api/v1/api_key.yaml | Out-File ~/.gem/credentials -Encoding "ASCII"

API keys

You can modify the credentials file manually and add different API keys. You can later usegem push -k keyto choose the relevant API key.

In order topushgems to the local repository, you can set the global variable$RUBYGEMS_HOSTto point to the local repository as follows:

Setting RUBYGEMS_HOST
export RUBYGEMS_HOST=http://localhost:8081/artifactory/api/gems/

To get this value, select your repository intheApplicationmodule|Artifactory|Artifacts|Gems-localandclickSet Me Up.

Alternatively you could use thegem pushcommand with--host, and optionally,--keyto specify the relevant API key.

Make sure you are familiar with your effective sources and their order as specified in the~/.gemrcfile.

Also, make sure you are familiar with your global$RUBYGEMS_HOSTvariable before you issue agem pushcommand or use thepush --hostoption.

When a local repository is first created, it is populated withrubygems-update-*.gemby default. In order to disable this behavior, you must change thesystem propertiesto include:
artifactory.gems.gemsAfterRepoInitHack=false

Make sure you deploy to a "gems" folder

When deploying Gems to your repositories, you need to place them in a gems folder for Artifactory to include them in its indexing calculations.


Remote Repositories

A remote RubyGems repository serves as a caching proxy for a repository managed at a remote URL such ashttp://rubygems.org.

Once requested, artifacts (Gems) are cached on demand. They can then be removed, but you cannot manually deploy anything into a remote repository.

To create a remote RubyGems repository, execute the following steps:

  1. in theAdministrationmodule, underRepositories | Repositories | Remote,clickNew Remote Repositoryand setGemsto be thePackage Type.
  2. Set theRepository Key, and specify theURLto the remote repository. The example below referencesrubygems.org.

Usage

In order to allow the integration with thegemcommand line tool, you must add the relevant source URL to your RubyGems configuration.
  1. In the Application module | Artifactory | Artifacts Tree Browser, select your newly created repository and clickSet Me Up.
  2. Copy the source URL from theRubyGems Sourcessection.
  3. Add this URL by modifying your~/.gemrcfile or using thegem sourcecommand as follows:

    All RubyGems repositories must be prefixed with api/gems in the path

    When using the RubyGems command line to access a repository through Artifactory, the repository URL must be prefixed withapi/gemsin the path.

    gem source -a http://localhost:8081/artifactory/api/gems/rubygems/

Additional Gem Commands You Can Use

You can remove previous source entries by modifying your~/.gemrcfile manually or by runninggem sources -r
You can also rungem sources --listto know what your effective sources are and their order.

Overcoming Unauthorized Status Failures

Some gem/bundler commands may fail with an Unauthorized (401) status. In some cases these can be overcome by usingoneof the following options:

  • Enable the "Anonymous User" by checkingAllow Anonymous AccessinSecurity General Configurationas described in Managing Users.
  • Create a specializedPermission Targetthat allows anonymous access only to the remote repository.
  • Use a source URL with embedded credentials, such as:gem sources-a http://user:password@host/...


Virtual Repositories

A Virtual RubyGems repository (or "repository group") can aggregate multiple local and remote RubyGems repositories, seamlessly exposing them under a single URL.

The repository is virtual in that you can resolve and retrieve artifacts from it but you cannot deploy anything to it. For more information please refer toVirtual Repositories.

The procedure for setting up a virtual repository is very similar to setting up a local or remote repository, however as a last step, you need to select the repositories that will be included in the virtual repository you are creating.

RubyGems Virtual Repository

Usage

Using a virtual RubyGems repository you can aggregate both your local and remote repositories.

You need to set the right repository source URL, in the same way as described inUsagefor a local RubyGems repository, just with the appropriate repository key as follows:

source:http://localhost:8081/artifactory/api/gems//

target:http://localhost:8081/artifactory/api/gems/(no slash at the end!)


Using the REST API

The REST API provides access to the Gems Add-on through the repository key using the following URL:

http://localhost:8081/artifactory/api/gems//


In addition to the basic binary repository operations, such as download, deploy, delete etc., thefollowingRubyGems.orgAPI Gem commands are supported:

Gem command
Curl syntax example
Remarks
Info curlhttp://localhost:8081/artifactory/api/gems/ository key>/api/v1/gems/my_gem.(json|xml|yaml) Optionally indicate JSON / XML / YAML (default: JSON)
Search curlhttp://localhost:8081/artifactory/api/gems//api/v1/search.(json|xml|yaml)?query=[query] Will search for gems with name containingquery
Dependencies curlhttp://localhost:8081/artifactory/api/gems/ <库关键> / api / v1 /依赖性?宝石= [gem1,。..] Use a csv of gem names for the value ofgems
Yank

curl -X DELETEhttp://localhost:8081/artifactory/api/gems//api/v1/yank

-d 'gem_name=gem_name' -d 'version=0.0.1' -d 'platform=ruby'

Deletesthe specific gem file from the repository


Indexing is done automatically by Artifactory in the background, however if you still need to recreate or update the spec index files,the following REST API commands are also available:

REST command
Curl syntax example
Remarks
ReIndex curl -X POSThttp://localhost:8081/artifactory/api/gems//reindex

Re-creates all spec index files.

Update index curl -X POSThttp://localhost:8081/artifactory/api/gems//updateIndex Updates all spec index files if needed.

Viewing RubyGems Artifact Information

If you select a RubyGems artifact in the Tree Browser you can select theRubyGemstab to view detailed information on the selected artifact.


Watch the Screencast

  • No labels
Copyright © 2023 JFrog Ltd.