npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ci-server

v1.4.0

Published

Personal CI Server node module

Downloads

7

Readme

CI Server

Motivation

This is a experimental project, which I started to have automate build system for most of our UI projects in our organization.

But this turned out to be one of the best projects that I have ever thought of. This is a basic projection of what Travis-ci.org offers. This is not a complete implementation / projection of Travis-ci (which is my ultimate goal of this project completion and gracefully present it back to the community which I love so much).

Introduction

The CI Server is tiny node module, which helps you build a CI server of your own with your own instruction, and this is implemented to work with any SCM system which supports webhooks.

Installation

The package is available on the npm registry and you can install it using npm / yarn

npm install ci-server or yarn add ci-server

Usage

Once your installed the ci-server node module, there is a few configurations which the module expects.

  1. config.json - Is a configuration JSON telling the which branch's should the CI build trigger and specify the script filename.
  {
    "WATCH_BRANCHS": ["develop", "feature/subscription-integration"],
    "FILENAME": "script.sh"
  }  
  1. script file - This is basic shell script file, having the build instructions to be executed on a build instance. In your script file, by default the first argument is the branch which triggered the build, you can access it with $1.

  2. Instantiating the CI server instance. Once the above configurations are done. You need to instantiate and ci, which exposes few methods for your use, as below.

  const CI = require('ci-server');

  const config = {
    WEBHOOK_PATH: '/webhook',
    SECRET: 'secret',
    BUILD_PATH: '/ci/workspace',
    PORT: 9000
  };

  const server = new CI(config);

  server.start(function instanceCB(err, port) {
    if(err) {
      console.log('Error on CI instance' + err);
    } else {
      console.log('Webhook listening for events on port' + port);
    }
  }, function deploymentCB(err, deploymenstStatus));

WEBHOOK_PATH - GITHUB webhook namespace, for the events to be received and perform the build activities

SECRET - This is secret code which you specify when creating a webhook handler for you git repo. This is covered in details below.

BUILD_PATH - Your project workspace on the server.

PORT - (Optional) Port on which the CI server would be instantiated and run. (Default PORT - 7777)

start() - This is the API function exposed, when you create a CI instance by calling new CI(). This takes two callbacks, where

  • the first callback is the instance callback which is executed when the server is started.

  • second callback is the deployment callback which is executed on every deployment cycle.

The first callback takes two parameters, where the first parameter is the error and second is the port which the ci server is running.

The second callback takes two parameters, where

  • the first parameter is the error when a particular deployment cycles errors out.

  • second parameter is given on deployment success, this is an Object having properties from

    • path - The provided Build path
    • branch - The branch is it deployed from.
    • payload - The github payload, this is useful as this provides information on the committer, branch, the commit ID.

You can use this object for referential / logging purpose.

Creating webhook for your project

Follow the below steps to create a webook for project repo.

  1. Click on the settings tab of your project repo.

    Settings Settings Screen

  2. On side navigation panel click on webhook.

    Nav Nav panel Screen

  3. For webhook URL path, provide your CI server running instance eg. http://10.23.45.67:7777/webhook. The IP address changes, based on where you are running the ci server project.

  4. Select content-type as application/json from the dropdown.

  5. Provide the secret key. Please note this would be you secret key that you would provide as a config for creating the ci server instance.

  6. Select the events which you want the webhook to emit (For the sake of this project, we are only interested in push events)

    webhook Webhook form unfilled

    webhook Webhook form filled Screen

  7. Save the webhook.


NOTE: If you don't have a server and you are curious to see what this project can do. start the project on you local machine. By this we are running the project on localhost:7777/webhook. Now you need to expose it to the internet.

There are many ways, but we will use something simpler, using ngrok. which you can download here.

Run the ngrok command as ngrok http 7777

This opens up you server and be accessed publicly, now copy the random address it generates and pate it in the webhook URL path with the namespace.

That's it you now have a CI serve, which is more controllable because you are giving it instructions to perform for every CI build.

If you like this, please spread the word out. If you find an issue, raise a bug which I will be more happy to resolve. Because that is the only way you would help me learn.