#Deployment
KISO Themes is easily deployable. It works out of the box on Heroku (as long as you remember to set your credentials as described on the Installation page).
#Capistrano
There is some slight tweaking you'll have to do to your
deploy.rb
to have Capistrano tell bundler how to set your credentials on the machine you're deploying to. This step takes the form of calling bundler config gems.kiso.io <your_credentials>
before Capistrano executes the bundler:install
hook.In your
deploy.rb
you'll want to create a task
for setting up the execution:namespace :deploy do task :prepare_bundle_config do # Potentially change the role here to whatever is suitable for you on roles(:app) do # This command is using an rbenv Cap variable which was set like this: # set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec" # But your circumstance may be different, so configure accordingly execute "#{fetch :rbenv_prefix} bundle config gems.kiso.io #{ENV['KISO_CREDENTIALS']}" end end end
In the example above we are using best practices by pulling the credentials from an Environment variable as opposed to creating a security concern by simply pasting in the credentials.
Next, you want to hook onto the
bundler:install
Capistrano hook:namespace :deploy do before 'bundler:install', 'deploy:prepare_bundle_config' end
When you attempt a deploy, you should see in the deploy logs that Capistrano executes the
prepare_bundler_config
task before running bunlder:install
- thus setting your credentials on your deploy machine.#Heroku
If you're using Heroku, you need to set a special Environment variable as well, by running this on the command line:
heroku config:set BUNDLE_GEMS__KISO__IO=<SUBSTITUTE_YOUR_CREDENTIALS_HERE>
If you're using Review Apps, make sure to read the Heroku documentation on inheriting config vars and ensure that you setup the
BUNDLE_GEMS__KISO__IO
environment variable is required.#Inside Docker Containers
In order for Bundler to be able to access the private Gem server, you'll have to let it know what you're credentials are. This is achieved much in the same way as a Heroku deploy: you use Bundler's ability to be configured via environment variables, specifically
BUNDLE_GEMS__KISO__IO
The preferred method would be:
- Add your Kiso authentication token to an
.env
file in your project root, that is not checked in to Git and is in.gitignore
to prevent accidental credential leakage. - Configure
docker-compose.yml
to reference the environment variable in the.env
file as a value to be used for a named argument used in thebuild
configuration. - Configure the
Dockerfile
to accept the argument and inject that value into a finalENV
declaration forBUNDLE_GEMS__KISO__IO
.
Note: If you're not using Docker Compose, then you would just pass the argument with the Kiso docker when running
docker build
Here's an example:
- The
.env
file should contain an entry like so:
KISO_AUTH_TOKEN=<YOUR TOKEN FROM THE KISO DASHBOARD>
- Then in your
docker-compose.yml
you would specify the argument and reference an environment variable in an environment file as its value. The following example assumes yourdocker-compose.yml
file lives in your project root, along with an.env
file which holds your environment variables that you wish to keep secret (and should be in your.gitignore
to prevent accidental credential leakage in your Git history).
rails: env_file: .env build: args: - KISO_BUNDLER_CONFIG=${KISO_AUTH_TOKEN}
- This environment variable needs to be set during the container build phase so that Bundler can access it when bundling your project gems, so you'll need to add it as an argument that is used in your Dockerfile to set the environment variable that Bundler expects:
ARG KISO_BUNDLER_CONFIG ENV BUNDLE_GEMS__KISO__IO=${KISO_BUNDLER_CONFIG}