Circle CI
Integrate Onboardbase CLI into your CircleCI builds
This section assumes you already used Onboardbase CLI in your project, check the installation and setup sections.
TIP
You can authenticate the CLI with Environment variables.
Supported environment variables are:
ONBOARDBASE_TOKEN
- A service tokenONBOARDBASE_PROJECT
- an onboardbase project nameONBOARDBASE_ENVIRONMENT
- an environment in the specified project
It is easier to create an Onboardbase configuration file during development through the onboardbase setup
command, which is not the case most time for automated CI/CD processes.
In this guide, we will illustrate how to pull all your managed Onboardbase secrets into your CI/CD pipelines that automatically authorize and set up with values from Circle Environment Configurations.
This section assumes you already used Onboardbase CLI in your project. Check the installation and setup sections.
Generate Service Token
Click on the Manage Organization from an admin account and generate two service tokens, one for staging and the other for production.
Go to your CircleCI project setting and add new secrets STAGING_ONBOARDBASE_TOKEN
and PRODUCTION_ONBOARDBASE_TOKEN
with the new service tokens.
Generate Setup File
Login to your Onboardbase account, select the project to set up for, click on the environment to switch to the right environment, then from the dropdown towards the right, once you open it, you'll see a generated setup you can copy.
Generate the setup for both your production and staging secrets.
Then, on Github, create two new secrets with the name STAGING_ONBOARDBASE_SETUP
and PRODUCTION_ONBOARDBASE_HOST
and add the two setup configurations, respectively.
Access to a remote SSH server
This guide assumes you have SSH access to a remote server and also have access to the private key.
Add the private keys(staging and production servers) to your GitHub project secrets with the names PRODUCTION_SSH_KEY
and STAGING_SSH_KEY
, respectively.
Overall, to have the perfect configuration requirements, your CI process should have access to the following config variables:
STAGING_ONBOARDBASE_TOKEN
PRODUCTION_ONBOARDBASE_TOKEN
STAGING_ONBOARDBASE_SETUP
PRODUCTION_ONBOARDBASE_HOST
STAGING_SSH_KEY
PRODUCTION_SSH_KEY
STAGING_SSH_HOST
PRODUCTION_SSH_HOST
A sample workflow
version: 2
jobs:
build:
working_directory: ~/app-name
docker:
- image: circleci/node:6-browsers
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
- run:
name: install-onboardbase
command: |-
curl -Ss https://files.onboardbase.com/install.sh | bash - && source ~/.bashrc
onboardbase --version
- run:
# Authenticate the onboardbasae
name: authenticate-onboardbase
command: onboardbase config:set-token $STAGING_ONBOARDBASE_TOKEN --scope (pwd)
- run:
# Test the project
name: test
command: yarn test
- run:
# Setup the project
name: setup-onboardbase
command: echo "$STAGING_ONBOARDBASE_SETUP" > ./.onboardbase.yaml
- run:
# Setup ssh
name: setup-ssh
command: |-
which rsync || ( apt-get update -y && apt-get install rsync -y ) \
which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y ) \
eval $(ssh-agent -s) \
ssh-add <(echo "$STAGING_SSH_KEY") \
mkdir -p ~/.ssh \
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- run:
# Deploy the project
name: deploy
command: |-
ssh -o "StrictHostKeyChecking no" $STAGING_SSH_HOST "cd ~/app && git fetch && git checkout dev && git pull origin dev && yarn && rm -rf ./dist && yarn build && pm2 restart 'express-server'"
Test Pipeline
For the test stage to run successfully, we need to install Onboardbase CLI.
The stage before it installs authenticates and setup the runner using the staging credentials, so it can successfully read the secrets from the project and environment in the setup file.
- name: Install Onboardbase
command: |-
curl -Ss https://files.onboardbase.com/install.sh | bash - && source ~/.bashrc \
onboardbase --version
- name: Setup Onboardbase
command: |-
onboardbase config:set-token $STAGING_ONBOARDBASE_TOKEN \
echo $STAGING_ONBOARDBASE_SETUP > .onboardbase.yml
Deployment
This CI/CD workflow file assumes you are using Onboardbase CLI to manage the environments already, and please check one of our manage tutorials to set up a managed server.
Onboardbase Circle CI Orb
This orb configures the Onboardbase CLI in a CircleCI runner
Usage
In your Circle CI config, add the Onboardbase orb and install the Onboardbase CLI.
usage:
version: 2.1
orbs:
onboardbase: onboardbase/[email protected]
workflows:
use-my-orb:
jobs:
- onboardbase/install
You can view the latest version of the orb here
Make sure to set the ONBOARDBASE_TOKEN
, ONBOARDBASE_PROJECT
, and ONBOARDBASE_ENVIRONMENT
environment variables in order for the orb to authenticate the CLI with your Onboardbase account.
Updated 3 months ago