1.0.4 • Published 6 years ago

smuggle v1.0.4

Weekly downloads
8
License
MIT
Repository
github
Last release
6 years ago

Smuggle

Install

$ npm i

Config

Generate a starter config.

$ smuggle init

Run

$ smuggle [--config smuggle.json]

Options

Example Config

{
    "repos": {
        "smuggle-test": {
            "type": "gitlab",
            "path": "/home/user/localhost/smuggle-test",
            "requiredHeaders": {
                "x-gitlab-event": "Pipeline Hook",
                "x-gitlab-token": "abc123"
            },
            "requiredProps": {
                "object_attributes.status": "success"
            },
            "reset": true,
            "action": "pull",
            "branch": "master",
            "postActions": [
                "echo 'Building application'",
                "npm run build",
                "echo 'Restarting PM2 instance'",
                "pm2 restart smuggle-test",
                "echo 'Cleaning up'",
                "sh /path/to/cleanup.sh"
            ]
        }
    }
}
KeyTypeRequiredDefaultDescription
reposObjectYes-One or more repository config
repos.{name}ObjectYes-Name of the repo (key) and config options (value)
repos.{name}.typeEnum("gitlab", "github")Yes-Type of Git hosting service
repos.{name}.pathStringYes-Source location of the repo
repos.{name}.requiredHeadersObjectNo{}Optional required headers to expect from webhook
repos.{name}.requiredPropsObjectNo{}Optional required body props to expect from webhook
repos.{name}.resetBooleanNoFalseIf a git reset --hard should be performed before updating repo
repos.{name}.actionEnum("pull", "fetch/merge")No"pull"Type of operation to use when updating repo
repos.{name}.branchStringNo"master"Branch to perform action on
repos.{name}.postActionsArray[String]No[]Optional, arbitrary commands to execute after updating repo

Running sudo Commands

Experimental

If you need to execute postActions as root, run Smuggle as a user with privileges.

# Run Smuggle as 'myuser', assuming there
# is a 'smuggle.json' in the same directory
$ su -c smuggle myuser

# Run Smuggle as 'myuser' with options
$ su - myuser -c 'smuggle --config "/path/to/smuggle.json"'

Testing via Docker

The Docker/Compose files will start a PM2 session. The example includes a client, server, and Smuggle instance. You can have your existing Docker setup run Smuggle, or modify the example to pull a different repository.

See example/environment.json for PM2 config.

Running the example with docker-compose build && docker-compose up will:

  • Clone the sample repo
  • Run NPM install
  • Build client assets (Webpack in this case)
  • Copy the Smuggle config to the container
  • Start the API server, client, and Smuggle via PM2

You can use something like LocalTunnel to temporarily get a HTTPS link to your container, and use that to test your webhook via GitLab or GitHub.

$ lt -p 3100 # Smuggle port for this example

TODO

  • Add option to verify os.hostname() matches payload's reported host
  • Handle sudo more intelligently