Giter Site home page Giter Site logo

grim's Introduction

Grim: Dead simple build server

Deprecated As of October 2018 grim relies on a github api call that no longer works. We will not be upgrading the daemon to fix this. Please find a different solution to your build tool needs.

Grim is the "GitHub Responder In MediaMath". We liked the acronym and awkwardly filled in the details to fit it. In short, it is a task runner that is triggered by GitHub push/pull request hooks that is intended as a much simpler and easy-to-use build server than the more modular alternatives (eg. Jenkins).

On start up, Grim will:

  1. Create (or reuse) an Amazon SQS queue with the name specified in its config file as GrimQueueName
  2. Detect which GitHub repositories it is configured to work with
  3. Create (or reuse) an Amazon SNS topic for each repository
  4. Configure each created topic to push to the Grim queue
  5. Configure each repositories' AmazonSNS service to push hook updates (push, pull_request) to the topic

Grimd data flow

An example including two repositories watched by three Grimd's (one in EC2 and two MacBookPros).

Each GitHub repo can push to exactly one SNS topic. Multiple SQS queues can subscribe to one topic and multiple Grim instances can read from the same SQS queue. If a Grim instance isn't configured to respond to the repo specified in the hook it silently ignores the event.

Installation

1. Get grimd

wget https://artifactory.mediamath.com/artifactory/libs-release-global/com/mediamath/grim/grimd/[RELEASE]/grimd-[RELEASE].zip

2. Global Configuration

Grim tries to honor the conventional Unix filesystem hierarchy as much as possible. Configuration files are by default found in /etc/grim. You may override that default by specifying --config-root [some dir], more briefly -c [some dir] or by setting the GRIM_CONFIG_ROOT environment variable. Inside that directory there is expected to be a config.json that specifies the other paths used as well as global defaults. Here is an example:

{
	"GrimQueueName": "grim-queue",
	"ResultRoot": "/var/log/grim",
	"WorkspaceRoot": "/var/tmp/grim",
	"AWSRegion": "us-east-1",
	"AWSKey": "xxxx",
	"AWSSecret": "xxxx",
	"GitHubToken": "xxxx",
	"HipChatToken": "xxxx"
}

If you don't configure GrimQueueName, ResultRoot or WorkspaceRoot Grim will use default values. The AWS credentials supplied must be able to create and modify SNS topics and SQS queues.

Required GitHub token scopes

  • write:repo_hook to be able to create/edit repository hooks
  • repo:status to be able set commit statuses
  • repo to be able to download the repo

3. Repository Configuration

In order for Grim to respond to GitHub events it needs subdirectories to be made in the configuration root. Inside those subdirectories should be a config.json and optionally a build.sh. Here is an example directory structure:

/etc/grim
/etc/grim/config.json
/etc/grim/MediaMath
/etc/grim/MediaMath/grim
/etc/grim/MediaMath/grim/config.json
/etc/grim/MediaMath/grim/build.sh

The file config.json can have an empty JSON object or have the following fields:

{
	"GitHubToken": "xxxx",
	"HipChatToken": "xxxx"
	"HipChatRoom": "xxxx",
	"PathToCloneIn": "/go/src/github.com/MediaMath/grim"
}

The GitHub and HipChat tokens will override the global ones if present. The HipChat room is optional and if present will indicate that status messages will go to that room. The field PathToCloneIn is relative to the workspace that was created for this build.

Build script location

Grim will look for a build script first in the configuration directory for the repo as build.sh and failing that in the root of the cloned repo as either .grim_build.sh or grim_build.sh.

The environment variables available to this script are documented here.

Environment Variables

CLONE_PATH= the path relative to the workspace the repo is cloned in
GH_EVENT_NAME= either 'push', 'pull_request' or '' (for manual builds)
GH_ACTION= the sub action of a pull request (eg. 'opened', 'closed', or 'reopened', 'synchronize') or blank for other event types
GH_USER_NAME= the user initiating the event
GH_OWNER= the owner part of a repo (eg. 'MediaMath')
GH_REPO= the name of a repo (eg. 'grim')
GH_TARGET= the branch that a commit was merged to
GH_REF= the ref to build
GH_STATUS_REF= the ref to set the status of
GH_URL= the GitHub URL to find the changes at

grim's People

Contributors

bhand-mm avatar bluebytes60 avatar harisgodil-mm avatar kklipsch avatar logie17 avatar varun06 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grim's Issues

Update godoc

Overview is empty. Also should review all of the comments and prove that golint passes.

grimd integration tests

A lot of what grim does can only be seen when interacting with external systems. Setting up those external systems is hard. We need to add automated integration tests.

Take a stand on how to do github clone access

Currently we leave it murky how one should set up grim to clone github repos. In our build server we use ssh private keys (and not well I might add) but that is not documented in the grim documentation. We should move to supporting and encouraging oauth based cloning (as we already require oauth access for other things and oauth access is at least as limited as private keys or deploy key, if not org machine users).

To that end:

  1. document the choices and how to implement them.
  2. add the oauth token as an argument to the prepare.sh script (but only to this, very dangerous to include in build scripts).
  3. create a "prepare" sub command that outputs our "preferred" prepare.sh script.

Include build server identification in hipchat messages

In the case of multiple grim servers (either clustered or other) it is very useful to know "which" grim server is generating a hipchat message.

We should:

  1. Add a root configuration option like "grib_server_id" or something. If not provided use the existing grim_queue_name.
  2. Include that configuration option in each of the hipchat messages.

Allow for secret storage in grim configs

We have potential jobs that need secrets to run their integration tests. Storing those secrets in the code repos is problematic (and in open source projects completely unacceptable).

If we could store them in grim configs then the grim deployment jobs (which assumedly all ready do secret storage correctly right? RIGHT?) could embed them in the configs.

grimd panic if config.json not present in repo.

When grimd runs, it looks for a config.json in repo, config.json is of following format:

{
    "GitHubToken": "",
    "HipChatToken":"",
    "HipChatRoom":"",
    "PathToCloneIn":"/go/src/github.com/MediaMath/test/grim"
}

If the file is not found by grimd, it panics with following error message -

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x7413f]

Better notification/logging when no grim script is available

When a build job is triggered that cannot find a build script the following is added to the logs:

"error while performing build: fork/exec : no such file or directory"

and the following is added to hipchat:

"Error during build of MediaMath/Keryx initiated by a ..."

As this is frequently the first interaction with grim that someone has (setting up a job) it behooves us to make this a little nicer.

Should make the error more specific in both cases.

SNS Topic Name improvement

SNS Topic creation should look like the following:

  1. look for existing topic on repo
  2. If topic exists and permissions are ok for adding to the grim queue, do so.
  3. If topic exists and permissions are not ok for adding to the grim queue, error.
  4. If topic does not exists, create it with a "safe" name that is not configurable.

There is potential for races in 4, so need to give that some thought.

grimd logging

A) make results directory at beginning of build.
B) log the hook to results
C) log to the results directory at a minimum:

  • build start
  • workspace created
  • build script started
  • build script finished error/no error

D) grimd logging should include the creation of the results directory at a minimum.

timeout logic is odd

timeout doesnt actually kill the goroutine so you can get a timeout followed by a success. further goroutines can stack up taking resources.

Fix aws-go-sdk switch from *map to just map

This is a breaking change and off course it is breaking Grim.

/sqs_queue.go:97: cannot use map[string]*string literal (type *map[string]*string) as type map[string]*string in field value
./sqs_queue.go:151: invalid indirect of resp.Attributes (type map[string]*string)
./sqs_queue.go:168: cannot use map[string]*string literal (type *map[string]*string) as type map[string]*string in field value

need GRIM fix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.