Connecting External CI

Limio Custom Components aim to put your development team in the driver seat's, enabling them to use the tools they already know and a CI process to release changes in a controlled environment.

In this tutorial we will be using CircleCI but any similar tool should be able to replicate this flow.

To get started you will need to make a Limio Support Request to gain Component Repository Credentials. This will give you the required access keys to access the repository and in turn connect your CI instance.

The easiest way to then mirror your repository using a Cron Job in your CI pipeline, though different tool packages can allow you to use Triggers, to duplicate your repository on pushes to specific branches in your GitHub repository.

Which ever way you choose to execute your mirroring process you can now use the Limio provided Credentials paired with the GitHub API Key to run a scripting process using tools like Python to clone your repository.

Your YAML file for CI should look something like this:

jobs:
  clone:
    working_repositories: ~/repositories
    docker:
      - image: circleci/node:5.1
    steps:
      - checkout
      - restore_cache:
          key: v1-dependencies-{{ checksum "<<YOUR DEPENDENCY LOCK FILE>>" }}
      - run:
          name: Install Dependencies
          command: |
            <<YOUR CHOSEN DEPENDENCY MANAGEMENT INSTALL>>
      - save_cache:
          key: v1-dependencies-{{ checksum "<<YOUR DEPENDENCY LOCK FILE>>" }}
          paths:
            - "~/.local/share/virtualenvs"
      - run:
          name: Setting up SSH access
          command: |
            chmod +x ./ssh.sh
            scripts/setup-ssh.sh $SSH_KEY_ID
      - run:
          name: Mirror Limio Repository to AWS CodeCommit
          command: node ./clone.py

workflows:
  version: 2
  nightly:
    jobs:
      - clone
    triggers:
      - schedule:
          cron: “0 0 * * *” # Trigger every night at 00:00
          filters:
            branches:
              only:
                - master

ssh.sh

This will be the file that will setup your credentials with your Limio Components Repository, this should look like this:

# Add CodeCommit to SSH Configuration
# see https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-without-cli.html#setting-up-without-cli-configure-client
 echo "Host git-codecommit.*.amazonaws.com
 User $1
 IdentityFile /home/circleci/.ssh/id_rsa" >> /home/circleci/.ssh/config

# Add CodeCommit Server as Known Host
ssh-keyscan -H git-codecommit.us-east-1.amazonaws.com >> ~/.ssh/known_hosts

clone.js

This will be your work file that will do the cloning of the repository, while Node is used in this example any scripting language can be used, an example of how this looks is as follows. Notice it uses a clean up job the delete the local repository after the sync job is complete:

import { execSync } from "node:child_process"

// Enables synchronous execution
async function executeCommand(command) {
    try {
        return execSync(command, { stdio: `inherit` })
    } catch (e) {
        console.error(e); // should contain code (exit code) and signal (that caused the termination).
    }
}

const repositoryName = <<YOUR REPOSITORY NAME>>

async function cloneRepo() {
    console.log(`Cloning repository ${repositoryName}`)
    await executeCommand(`git clone --mirror https://github.com/${repositoryName}/`)
}

async function deleteRepo() {
    console.log(`Deleting repository ${repositoryName}`)
    await executeCommand(`rm -Rf ${repositoryName}`)
}
    
async function syncRepo() {
    console.log(`Pushing changes from repository ${repositoryName} to Limio")
    await executeCommand(`cd ${repositoryName} && git remote add sync https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/${repositoryName}`)
    await executeCommand(`cd ${repositoryName} && git push sync --mirror`)
}

async function run() {
    await cloneRepo()
    await syncRepo()
    await deleteRepo()
}

run()

Last updated