gort

package module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

README

GORT

Build Status GoDoc Go Report Card Maintainability Test Coverage

Moving Gopher as GORT

GORT is a simple HTTP handler to receive remote calls to run scripts bundled in Docker containers. Why the name is gort - because the idea is "GO-Run-Things"

Safety notice: Until this tool doesn't have the authorization, you need to cover it using any firewalls or use it as internal service in your k8s cluster without exposing it outside.

Usage

Refer to Install for getting gort binary

To use gort in your Docker container download the latest version from Project Release Page

$ ./gort
2019/10/30 12:32:06 Gort is started on port 5000

GORT uses the following environment variables for a customized run

PORT as default will be handled over 5000 port

SCRIPTS_DIR by default will search scripts at ./dist in the same directory where the binary

GORT_RATE_LIMIT is a parameter to set Throttle Limit, Throttle is not a rate-limiter per user. Instead, it just puts a ceiling on the number of current in-flight requests

Endpoints
Health

Allows you to check the health of application/container

  • URL

    /v1/health

  • Method

    GET

  • Success Response

    • Code: 200
      Content: OK
List

List scripts directory

  • URL

    /v1/list-dist

  • Method

    GET

  • Success Response

    • Code: 200
Start

Allows you to start script from the scripts directory

  • URL

    /v1/start

  • Method

    POST

  • Data

    Requires JSON data as payload

    {
      "executor": "node",
      "script": "script.js",
      "env_vars": [
        "FOO=bar",
        "BAR=foo"
      ],
      "args": [
        "--foo=bar",
        "--bar=foo"
      ]
    }
    
  • Success Response

    • Code: 200
      Content: The function is executed in the background. Refer to container logs to see the output
  • Error Responses

    • Code: 400
      Content: Required parameters 'executor' and 'script' were not found in the payload

    • Code: 422
      Content: Not able to parse data as valid JSON

    • Code: 500
      Content: Requested executor is not installed

    • Code: 501
      Content: Requested script is not found in the scripts directory

  • Sample Call:

$ curl -X POST http://127.0.0.1:5000/v1/start -d '{"executor":"python", "script": "crawler.py"}'
The function will be executed in the background. Refer to container logs to see the output

Install

Binary

Binary are available for download on the Project Release Page

However, you also able to change something in the source code and build your Gort for yourself

$ go build ./...

Use cases

Dockerfile Example Usage

For instance, we have a few crawlers which should be executed on demand.

They was built by NPM

#
# STEP ONE: Build scripts
#
FROM node:10 AS builder
# Create app directory
WORKDIR /app
# Copy our files inside of the docker builder
COPY . .
# Install dependencies
RUN npm install && npm build
#
# STEP TWO: Build our images bundled with gort and copy scripts from builder
#
FROM alpine
# Create app directory
WORKDIR /app
# Install dependecies
RUN apk add --no-cache bash nodejs ca-certificates && \
    wget https://github.com/idestis/gort/releases/download/1.0.0/gort_1.0.0_linux_amd64 -O gort && \
    chmod +x gort
# Copy our scripts from builder step
COPY --from=builder /app/dist /app/dist
# PORT variable for Gort
ENV PORT 8080
# Expose outside
EXPOSE 8080
ENTRYPOINT ['gort']

After when we published and executed this docker container elsewhere, we can send requests to start any our function

$ curl -X POST https://address/v1/start -d '{"executor":"python", "script": "example.py"}'
The function will be executed in the background. Refer to container logs to see the output

In STDOUT of the container we will be able to see logs

2019/10/30 12:19:01 Just ran subprocess of example.py with PID 52177

For instance, you can schedule this runs using your services or any CI tool like Jenkins, drone.io

Contribute

Refer to CONTRIBUTING.md

Dependencies

TBD

  • Authorization method to protect your endpoints
  • Subprocesses list
  • Cleanup zombie subprocesses

Documentation

Overview

Package gort is small HTTP handler written on Go to receive remote calls to run scripts bundled in Docker containers

Complete documentation you can find in repository

https://github.com/idestis/gort

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListScriptsHandler added in v1.2.1

func ListScriptsHandler(w http.ResponseWriter, r *http.Request)

ListScriptsHandler will return scripts list from the SCRIPTS_DIR

func NotFoundHandler

func NotFoundHandler(w http.ResponseWriter, r *http.Request)

NotFoundHandler will return custom error message

func StartScriptHandler added in v1.2.1

func StartScriptHandler(w http.ResponseWriter, r *http.Request)

StartScriptHandler will start requested script and print output to stdout

Types

type Script

type Script struct {
	// Executor defines the name of
	// the interpreter program to be executed
	Executor string `json:"executor"`
	// Script will refer to script name from the dist folder
	Script string `json:"script"`
	// EnvVars slice will hold all environment variables for the script
	EnvVars []string `json:"env_vars"`
	// Args slice will hold additional arguments for the command
	Args []string `json:"args"`
}

Script sctruct will hold an entity to define which script we should run

Directories

Path Synopsis
Package utils provides helpers for gort such as directory scanner or slice search
Package utils provides helpers for gort such as directory scanner or slice search

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL