Skip to content

Small init system with templated config files; to be used as container entrypoint

License

Notifications You must be signed in to change notification settings

dbeneker/mittnite

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Mittnite - Smart init system for containers

Mittnite is a small, but smart init system designed for usage as ENTRYPOINT in container images.

It offers the following features:

  • Render configuration files from templates using Go's text/template engine.
  • Start processes and manage their lifecycle
  • Watch configuration files and send configurable signals to processes on change
  • Wait until required services are up before starting processes (currently supporting filesystem mounts, HTTP services, MySQL, Redis, AMQP and MongoDB)

Table of contents

Getting started

CLI usage

Basic

$ mittnite --help

Mittnite is a small, but smart init system designed for usage as `ENTRYPOINT` in container images

Usage:
  mittnite [flags]
  mittnite [command]

Available Commands:
  help        Help about any command
  renderfiles
  up
  version     Show extended information about the current version of mittnite

Flags:
  -c, --config-dir string   set directory to where your .hcl-configs are located (default "/etc/mittnite.d")
  -h, --help                help for mittnite

Use "mittnite [command] --help" for more information about a command.

Render templates and execute custom command

This will render all template files and execute the sleep 10 afterwards.

$ mittnite renderfiles sleep 10

Docker

Build your (go) application on top of the mittnite docker-image

In order to run your own static application - e.g. a golang-binary with mittnite, we recommend to inherit the mittnite docker-image and copy your stuff on top.

FROM            quay.io/mittwald/mittnite:stable
COPY            mittnite.d/ /etc/mittnite.d/
COPY            myApplication /usr/local/bin/
# ENTRYPOINT and CMD are optional, because they are inherited by parent image

Download mittnite in your own custom Dockerfile

If you'd like to use mittnite for non-static applications like node or similar, you can download the mittnite-binary from Github.

FROM        node:12-alpine
ENV         MITTNITE_VERSION="1.1.2"
RUN         wget -qO- https://github.com/mittwald/mittnite/releases/download/v${MITTNITE_VERSION}/mittnite_${MITTNITE_VERSION}_linux_x86_64.tar.gz \
                | tar xvz mittnite -C /usr/bin && \
            chmod +x /usr/bin/mittnite
COPY        mittnite.d/ /etc/mittnite.d/
ENTRYPOINT  ["/usr/bin/mittnite"]
CMD         ["up","--config-dir", "/etc/mittnite.d"]

Configuration

The directory specified with --config-dir, or the shorthand -c, can contain any number of .hcl configuration files.
All files in that directory are loaded by mittnite on startup and can contain any of the configuration directives.

Directives

Job

Possible directives to use in a job definition.

job "foo" {
  command = "/usr/local/bin/foo"
  args = "bar"
  max_attempts = 3
  canFail = false
  
  watch "/etc/conf.d/barfoo" {
    signal = 12
  }
}

File

Possible directives to use in a file definition.

file "/path/to/file.txt" {
  from = "examples/test.d/test.txt.tpl"
  params = {
    foo = "bar"
  }
}

file "/path/to/second_file.txt" {
  from = "examples/test.d/second_test.txt.tpl"
  overwrite = false
  params = {
    foo = "bar"
  }
}

Probe

Possible directives to use in a probe definition.

probe "probe-name" {
  wait = true

  redis {
    host = {
      hostname = "localhost"
      port = 6379
    }
    password = ""
  }
  
  mysql {
    host = {
      hostname = "localhost"
      port = 3306
    }
    credentials = {
      user = "foo"
      password = "bar"
    }
  }
  
  amqp {
    host = {
      hostname = "localhost"
      port = 5672
    }
    credentials = {
      user = "foo"
      password = "bar"
    }
    virtualhost = "amqp.localhost.com"
  }
  
  mongodb {
    host = {
      hostname = "localhost"
      port = 27017
    }
    credentials = {
      user = "foo"
      password = "bar"
    }    
    database = "mongo"
  }
  
  http {
    scheme = "http"
    host = {
        hostname = "localhost"
        port = 8080
    }
    path = "/status"
    timeout = "5s"
  }
}

Specifying a port is optional and defaults to the services default port.

HCL examples

Start a process

job webserver {
  command = "/usr/bin/http-server"

  watch "/etc/conf.d/*.conf" {
    signal = 12 # USR2
  }
}

Render a file on startup

file "/etc/conf.d/test.txt" {
  from = "examples/test.d/test.txt.tpl"

  params = {
    foo = "bar"
  }
}

Wait until a Redis connection is possible

probe redis {
  wait = true
  redis {
    host = {
      hostname = "localhost"
      port = 6379
    }
  }
}

More examples

More example files can be found in the examples directory

About

Small init system with templated config files; to be used as container entrypoint

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.3%
  • Dockerfile 0.7%