<!– Automatically generated by Pandoc –> ." Automatically generated by Pandoc 3.1.8 ." .TH “gemstash-multiple-sources” “7” “October 8, 2015” “” “” .SH Multiple Gem Sources Gemstash will stash from any amount of gem sources. By the end of this guide, you will be able to bundle using multiple gem sources, all stashed within your Gemstash server. .SS Default Source When you dont provide an explicit source (as with the Quickstart Guide), your gems will be fetched from rubygems.org. This default source is not set in stone. To change it, you need only edit the Gemstash configuration found at f[CR][ti]/.gemstash/config.ymlf: .IP .EX # [ti]/.gemstash/config.yml


:rubygems_url: my.gem-source.local .EE .PP Make sure to restart your Gemstash server after changing the config: .IP .EX $ gemstash stop $ gemstash start .EE .PP Once restarted, bundling against f[CR]http://localhost:9292f[R] will fetch gems from f[CR]https://my.gem-source.localf[R]. If you had bundled before making these changes, fear not; bundling with a different default gem source will store gems in a separate location, ensuring different sources wont leak between each other. .SS Bundling with Multiple Sources Changing the default source wont help you if you need to bundle against rubygems.org along with additional sources. If you need to bundle with multiple gem sources, Gemstash doesnt need to be specially configured. Your Gemstash server will honor any gem source specified via a specialized URL. Consider the following f[CR]Gemfilef[R]: .IP .EX # ./Gemfile require [dq]cgi[dq] source [dq]http://localhost:9292[dq] gem [dq]rubywarrior[dq]

source [dq]localhost:9292/upstream/#{CGI.escape([dq]https://my.gem-source.local)}[dq] do

gem \[dq]my-gem\[dq]

end

source [dq]http://localhost:9292/upstream/my-other.gem-source.local[dq] do

gem \[dq]my-other-gem\[dq]

end .EE .PP Notice the f[CR]CGI.escapef[R] call in the second source. This is important, as it properly URL escapes the source URL so Gemstash knows what gem source you want. The f[CR]/upstreamf prefix tells Gemstash to use a gem source other than the default source. You can now bundle with the additional source. .PP Notice that the third source doesnt need to be escaped. This is because the f[CR]https://f[R] is used by default when no scheme is set, and the source URL does not contain any characters that need to be escaped. .SS Authentication with Multiple Sources You can use basic authentication or API keys on sources directly in Gemfile or using ENV variables on the Gemstash instance. .PP Example f[CR]Gemfilef[R]: .IP .EX # ./Gemfile require [dq]cgi[dq] source [dq]http://localhost:9292[dq]

source [dq]localhost:9292/upstream/#{CGI.escape([dq]user:password[at]my.gem-source.local)}[dq] do

gem \[dq]my-gem\[dq]

end

source [dq]localhost:9292/upstream/#{CGI.escape([dq]api_key[at]my-other.gem-source.local)}[dq] do

gem \[dq]my-other-gem\[dq]

end .EE .PP If you set f[CR]GEMSTASH_f[R] ENV variable with your authentication information, you can omit it from the f[CR]Gemfilef[R]: .IP .EX # ./Gemfile source [dq]http://localhost:9292[dq]

source [dq]http://localhost:9292/upstream/my.gem-source.local[dq] do

gem \[dq]my-gem\[dq]

end .EE .PP And run the Gemstash with the credentials set in an ENV variable: .IP .EX GEMSTASH_MY__GEM___SOURCE__LOCAL=user:password gemstash start –config-file config.yml.erb .EE .PP The name of the ENV variable is the uppercase version of the host name, with all f[CR].f characters replaced with f[CR]__f[R], all f[CR]-f with f[CR]_f and a f[CR]GEMSTASH_f[R] prefix (it uses the same syntax as Bundler (bundler.io/v2.4/man/bundle-config.1.html#CREDENTIALS-FOR-GEM-SOURCES)). .PP Example: f[CR]my.gem-source.localf[R] => f[CR]GEMSTASH_MY__GEM___SOURCE__LOCALf[R] .SS Redirecting Gemstash supports an alternate mode of specifying your gem sources. If you want Gemstash to redirect Bundler to your given gem sources, then you can specify your f[CR]Gemfilef[R] like so: .IP .EX # ./Gemfile require [dq]cgi[dq] source [dq]localhost:9292/redirect/#{CGI.escape([dq]https://rubygems.org)}[dq] gem [dq]rubywarrior[dq] .EE .PP Notice the f[CR]/redirectf prefix. This prefix tells Gemstash to redirect API calls to the provided URL. Redirected calls like this will not be cached by Gemstash, and gem files will not be stashed, even if they were previously cached or stashed from the same gem source.