rubygems-quickstart
Use a RubyGems registry to host private Ruby gems and serve them to the gem CLI and Bundler.
Before you begin
- Ensure you have the RubyGems CLI (
gem) installed on your local machine. Bundler is optional and required only if you install gems withbundle. - Access to a Harness account with appropriate permissions to create registries and connectors.
Create a RubyGems artifact registry
- Go to the Artifact Registry module in your Harness project.
- Click New Artifact Registry.
- In the Registry Type list, select Ruby.
- Enter a Registry Name.
registry name criteria
The registry name must start with a letter, should only contain lowercase alphanumerics,
_,.and-, and must be unique to your Harness account. - Optionally, add a Description and Labels for better organization.
- Select Create Registry to finalize.
Configure an upstream proxy (optional)
An upstream proxy allows your registry to fetch gems from external RubyGems sources when they are not available locally. The default upstream is RubyGems.org.
Create an upstream proxy
- In the Artifact Registry module, select the dropdown next to New Artifact Registry and select Upstream Proxy.
- Select Ruby as the proxy type.
- Enter an Upstream Proxy Key.
- Optionally, add a Description and Labels.
- Select your Source:
- RubyGems.org
- Custom
- If you choose Custom, enter your Remote Registry URL (for example,
https://rubygems.org). - Choose your Authentication method (
Anonymousby default for public RubyGems sources). - Click Create Upstream Proxy to establish the connection.
Configure the upstream proxy in your registry
- In the Artifact Registry module, select an existing RubyGems Artifact Registry.
- Go to the Configuration tab.
- In the Advanced (Optional) section, click Configure Upstream.
- Select from the list of compatible proxies to add them to your registry.
- Select Save to save the configuration.
If a gem is not found in your Harness registry, the upstream proxy fetches it from the remote registry and caches it.
Set up the RubyGems client
In your Harness RubyGems Artifact Registry, click Set Up Client and follow the instructions to configure the gem CLI to use the registry.
1. Generate identity token
- In your Harness RubyGems Artifact Registry, click Set Up Client.
- Click Generate Token to generate an identity token.
2. Configure registry
- Add the registry as a remote host:
gem sources --add https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/ruby
or (to save along with token)
gem sources --add https://<USERNAME>:<API_KEY>@pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/ruby
- Add the following entry to ~/.gem/credentials (create the file if it does not exist):
:<API_KEY_NAME>: "Bearer <API_KEY>"
- Configure Bundler to authenticate with this registry:
bundle config set --global "https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/ruby" "<USERNAME>:<API_KEY>"
- Add the registry URL to your Gemfile:
source "https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/ruby"
3. Push package
Set allowed_push_host in your gemspec to the registry host, then push your gem:
gem push <ARTIFACT_NAME>-<VERSION>.gem --host https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/ruby --key <API_KEY_NAME>
4. Install package
Install a gem from this registry:
gem install <ARTIFACT_NAME> -v <VERSION> --source https://<USERNAME>:<API_KEY>@pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/ruby
Reduce concurrent downloads to 1 in the .gemrc file and the Bundler config.
5. Yank package
Remove a gem version from this registry:
gem yank <ARTIFACT_NAME> -v <VERSION> --host https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/ruby --key <API_KEY_NAME>
Troubleshooting
Publish to a RubyGems registry returns 409 Conflict
Gem versions are immutable after publish. Choose a new SemVer version, or delete the existing version only if your registry retention and lifecycle policies allow it.
gem push or gem install returns 401 Unauthorized against a Harness RubyGems registry
Regenerate the identity token from Set Up Client, update ~/.gem/credentials or your Bundler config with the new token, and confirm the registry URL includes your account ID and registry name.
gem install returns 403 Forbidden, 404 Not Found, or the installation hangs
Reduce the number of concurent downloads in the ~/.gemrc file and config_file.