Ruby On Rails
In this guide, we will discuss how to setup a Ruby on Rails project, that uses Onboardbase to manage its secrets(environment variables)
This section assumes you already have a project set up in Onboardbase Dashboard. If you don't, please create an account and get started!
1. Install Onboardbase CLI
Follow the installation guide to set up Onboardbase CLI for your machine.
2. In development: login
Run onboardbase login
in your project folder, and accept to open the page in a browser.
On the authorization page, enter your email and a confirmation link will be sent to you. Click on the link, and your CLI should be authorized. Check your terminal to confirm.
3. In production: use a service token
Running the onboardbase login
command creates an access token to Onboardbase. This is useful to quickly get developers started and monitor secret usage, but not suitable for a production environment because you usually don't have access to a web browser.
Instead, you need to create a Service Token for machine-to-machine authentication:
- Login to your Onboardbase account as an admin
- Click the profile icon in the navbar
- Scroll to the Service Token section
- Click Generate token button
- Enter the name of the service
- Click on Generate to finalize
To configure the service token in the Onboardbase CLI, start by preventing the service token from being leaked in the bash log history:
export HISTIGNORE='onboardbase*'
And then run the command to define the service token in the configuration settings:
onboardbase config:set --token "Service.****.****.*****" --scope /usr/src/app
4. Setup Onboardbase CLI
After successful installation, from the Rails Project directory in your terminal, run:
onboardbase setup
This will list all your projects stored by Onboardbase:
- Select the desired project for the current folder
- Select the development environment
- Write the main command to run the project. For example,
bin/rails server
. - Add onboardbase.yaml to your
.gitignore
file.
onboardbase setup
creates an onboardbase.yaml file that has all the details you selected during the setup and that will be used by the onboardbase run
command to know which secrets to pull from Onboardbase into your project.
5. Run commands
Onboardbase injects environment variables at runtime using the onboardbase run
command.
All you have to do is to encapsulate your scripts with onboardbase run
:
onboardbase run -c "bin/rails server"
If you run onboardbase run
without any command, it will run the default command defined in the onboardbase.yaml
file.
Updated 10 months ago