Tuesday, June 25, 2024
HomeCloud ComputingAdd your Ruby gems to AWS CodeArtifact

Add your Ruby gems to AWS CodeArtifact


Voiced by Polly

Up to date 8 Might 2024: I up to date the command to gather RUBYGEMS_HOST to suppress the trailing /


Ruby builders can now use AWS CodeArtifact to securely retailer and retrieve their gems. CodeArtifact integrates with normal developer instruments like gem and bundler.

Purposes typically use quite a few packages to hurry up improvement by offering reusable code for widespread duties like community entry, cryptography, or knowledge manipulation. Builders additionally embed SDKs–such because the AWS SDKs–to entry distant providers. These packages could come from inside your group or from third events like open supply initiatives. Managing packages and dependencies is integral to software program improvement. Languages like Java, C#, JavaScript, Swift, and Python have instruments for downloading and resolving dependencies, and Ruby builders usually use gem and bundler.

Nevertheless, utilizing third-party packages presents authorized and safety challenges. Organizations should guarantee bundle licenses are suitable with their initiatives and don’t violate mental property. They need to additionally confirm that the included code is protected and doesn’t introduce vulnerabilities, a tactic referred to as a provide chain assault. To handle these challenges, organizations usually use personal bundle servers. Builders can solely use packages vetted by safety and authorized groups made accessible by means of personal repositories.

CodeArtifact is a managed service that permits the protected distribution of packages to inner developer groups with out managing the underlying infrastructure. CodeArtifact now helps Ruby gems along with npm, PyPI, Maven, NuGet, SwiftPM, and generic codecs.

You may publish and obtain Ruby gem dependencies out of your CodeArtifact repository within the AWS Cloud, working with present instruments corresponding to gem and bundler. After storing packages in CodeArtifact, you’ll be able to reference them in your Gemfile. Your construct system will then obtain accepted packages from the CodeArtifact repository through the construct course of.

How you can get began
Think about I’m engaged on a bundle to be shared with different improvement groups in my group.

On this demo, I present you ways I put together my surroundings, add the bundle to the repository, and use this particular bundle construct as a dependency for my challenge. I concentrate on the steps particular to Ruby packages. You may learn the tutorial written by my colleague Steven to get began with CodeArtifact.

I take advantage of an AWS account that has a bundle repository (MyGemsRepo) and area (stormacq-test) already configured.

CodeArtifact - Ruby repository

To let the Ruby instruments acess my CodeArtifact repository, I begin by gathering an authentication token from CodeArtifact.

export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token 
                                     --domain stormacq-test              
                                     --domain-owner 012345678912         
                                     --query authorizationToken          
                                     --output textual content`

export GEM_HOST_API_KEY="Bearer $CODEARTIFACT_AUTH_TOKEN"

Observe that the authentication token expires after 12 hours. I need to repeat this command after 12 hours to acquire a contemporary token.

Then, I request the repository endpoint. I cross the area identify and area proprietor (the AWS account ID). Discover the --format ruby possibility.

export RUBYGEMS_HOST=`aws codeartifact get-repository-endpoint  
                           --domain stormacq-test               
                           --domain-owner 012345678912          
                           --format ruby                        
                           --repository MyGemsRepo              
                           --query repositoryEndpoint           
                           --output textual content | sed 's:/*$::'`

Now that I’ve the repository endpoint and an authentication token, gem will use these surroundings variable values to hook up with my personal bundle repository.

I create a quite simple challenge, construct it, and ship it to the bundle repository.

CodeArtifact - building and pushing a custom package

$ gem construct hola.gemspec 

Efficiently constructed RubyGem
  Title: hola-codeartifact
  Model: 0.0.0
  File: hola-codeartifact-0.0.0.gem
  
$ gem push hola-codeartifact-0.0.0.gem 
Pushing gem to https://stormacq-test-486652066693.d.codeartifact.us-west-2.amazonaws.com/ruby/MyGemsRepo...

I confirm within the console that the bundle is on the market.

CodeArtifact - Hola package is present

Now that the bundle is on the market, I can use it in my initiatives as common. This includes configuring the native ~/.gemrc file on my machine. I comply with the directions supplied by the console, and I ensure I change ${CODEARTIFACT_AUTH_TOKEN} with its precise worth.

CodeArtifact - console instructions to connect to the repo

As soon as ~/.gemrc is accurately configured, I can set up gems as common. They are going to be downloaded from my personal gem repository.

$ gem set up hola-codeartifact

Fetching hola-codeartifact-0.0.0.gem
Efficiently put in hola-codeartifact-0.0.0
Parsing documentation for hola-codeartifact-0.0.0
Putting in ri documentation for hola-codeartifact-0.0.0
Achieved putting in documentation for hola-codeartifact after 0 seconds
1 gem put in

Set up from upstream
I may also affiliate my repository with an upstream supply. It’ll routinely fetch gems from upstream once I request one.

To affiliate the repository with rubygems.org, I take advantage of the console, or I sort

aws codeartifact  associate-external-connection 
                   --domain stormacq-test       
                   --repository MyGemsRepo      
                   --external-connection public:ruby-gems-org

{
    "repository": {
        "identify": "MyGemsRepo",
        "administratorAccount": "012345678912",
        "domainName": "stormacq-test",
        "domainOwner": "012345678912",
        "arn": "arn:aws:codeartifact:us-west-2:012345678912:repository/stormacq-test/MyGemsRepo",
        "upstreams": [],
        "externalConnections": [
            {
                "externalConnectionName": "public:ruby-gems-org",
                "packageFormat": "ruby",
                "status": "AVAILABLE"
            }
        ],
        "createdTime": "2024-04-12T12:58:44.101000+02:00"
    }
}

As soon as related, I can pull any gems by means of CodeArtifact. It’ll routinely fetch packages from upstream when not domestically accessible.

$ gem set up rake 

Fetching rake-13.2.1.gem
Efficiently put in rake-13.2.1
Parsing documentation for rake-13.2.1
Putting in ri documentation for rake-13.2.1
Achieved putting in documentation for rake after 0 seconds
1 gem put in

I take advantage of the console to confirm the rake bundle is now accessible in my repo.

Issues to know
There are some issues to bear in mind earlier than importing your first Ruby packages.

Pricing and availability
CodeArtifact prices for Ruby packages are the identical as for the opposite bundle codecs already supported. CodeArtifact billing will depend on three metrics: the storage (measured in GB per thirty days), the variety of requests, and the information switch out to the web or to different AWS Areas. Information switch to AWS providers in the identical Area isn’t charged, which means you’ll be able to run your steady integration and supply (CI/CD) jobs on Amazon Elastic Compute Cloud (Amazon EC2) or AWS CodeBuild, for instance, with out incurring a cost for the CodeArtifact knowledge switch. As common, the pricing web page has the main points.

CodeArtifact for Ruby packages is on the market in all 13 Areas the place CodeArtifact is on the market.

Now, go construct your Ruby functions and add your personal packages to CodeArtifact!

— seb



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments