Rolling your own private Ruby gem server on Google Cloud Platform
Software Engineering Intern
This is a big deal for organizations that build libraries with proprietary business logic or that mirror public libraries for internal use. In Ruby, these libraries are called gems, and until recently, there wasn't a good hosted solution for serving them. For Ruby in particular, many developers found themselves building their own custom solutions or relying on third parties such as Gemfury.
Running a gem server run on GCP has a lot of advantages. Specifically, the above command deploys the gem server to a Google App Engine Flex instance, which has 99.95% uptime (Google Container Engine support coming soon). App Engine can also autoscale the number of instances based on CPU utilization to minimize the amount of maintenance for the gem server. Having the gem server on GCP also allows you to use existing cloud infrastructure such as Stackdriver Logging, Cloud Storage and direct access to the underlying VM running the gem server for fine-grained control. The gem server can store an unlimited amount of public and private gems allowing an unlimited amount of users with the correct permissions to access it. This level of flexibility and customization makes GCP a highly productive environment to deploy apps to, and the gem server is no exception.
Using the gem serverLet’s take a look at how to install and configure a private gem server.
To deploy your own private gem server to GCP:
- First install the gem:
$ gem install google-cloud-gemserver
- Ensure you have Cloud SDK installed and a GCP project created with billing enabled. Also ensure that you're authenticated with it. For a full list of prerequisites, read this checklist.
- Run the following command in your terminal:
$ google-cloud-gemserver create --use-proj [MY_PROJECT_ID]where MY_PROJECT_ID is the GCP project ID the gem server will be deployed to. This deploys the gem server to App Engine and creates a default key used to push and fetch gems from the gem server. For brevity, the value of this key will later be referred to as “my-key” and its name will later be referred to as “my-key-name”.
Before you can download gems from the gem server, you need to create a key that has read access to the gem server. Conveniently, the “create” command above also generated a default key. Installing gems uses bundler, which needs to be configured such that it associates the gem server with
my-key when downloading gems, otherwise the download would fail with a 401 Unauthorized Error. This is also done automatically for
my-key when you use the “create” command. Now, make a small modification to your Gemfile:
“bundle install” and it fetches and installs the gem “MY_GEM” from the gem server!