Sign inSign up

sidusio/discriminator

By sidusio

Updated over 6 years ago

Automatically add labels to docker containers

Image
0

392

sidusio/discriminator repository overview

discriminator

GoDoc License Go Report Card Build Status Image size docker hub

Automatically add labels to docker containers.

Getting Started

This application works by looking for a labels (default: io.sidus.discriminator) associated value (instructions) and specified templates to add or remove certain labels from that container.

WARNING: In order to modify the labels in a container, discriminator has to create a new one and remove the old one.

WARNING: This application is in beta, use at own risk.

Docker

The easiest way to run the application is through docker sidusio/discriminator

When you run the application in docker you have to mount in:

  1. Your docker socket: /var/run/docker.sock:/var/run/docker.sock
  2. A directory with your templates to /templates

Example run command:

docker run -v /var/run/docker.sock:/var/run/docker.sock -v yourTemplatesDirectory:/templates sidusio/discriminator
Configuration

The application is configured through environment variables

Enviornment VariableDefault valueDescription
DISCRIMINATOR_TEMPLATES_PATH/templatesDirectory with your templates
DISCRIMINATOR_TEMPLATES_EXTENSION.tmplThe extension of your templates
DISCRIMINATOR_CONTAINERS_LABELio.sidus.discriminatorThe label to look at for instructions
DISCRIMINATOR_INCLUDE_STOPPED_CONTAINERSfalseWhether to run the application on stopped containers
DISCRIMINATOR_RUN_INTERVAL5mHow often the application should go through the containers
DISCRIMINATOR_LOG_LEVELinfodebug/info/warn/error
DISCRIMINATOR_LOG_FORMATtexttext/json
Templates

Templates are called by instructions to modify the labels of the container.

Templates are parsed with text/template.

A row starting with a + is a label (key and value) that should be added/overwritten ex: +my.label=value

A row starting with a - is a label (only key) that should be removed ex: -my.label

All other rows will be discarded.

The following data is sent to the template parser and can be used in the template:

type Data struct {
	ContainerData struct {
		Labels map[string]string
		Name   string
	}
	Arguments map[string]string
}

Where arguments are the ones specified in the instruction.

Instructions

Instruction are specified with the application label (default io.sidus.discriminator).

An example instruction could be testtemplate() which would apply the template named testtemplate (without any file extensions).

You can also pass arguments to instructions: template(argument: value, argument2: value)

Instructions can be chained and will the be applied from left to right: template1() | template2(arg: value) | template3()

Contributing

Contributions are welcome!

For example, you could contribute by expanding this section.

Tag summary

Content type

Image

Digest

Size

9.2 MB

Last updated

over 6 years ago

docker pull sidusio/discriminator