Giter VIP home page Giter VIP logo

traefik-ondemand-plugin's Introduction

Traefik Ondemand Plugin

Project achieved, please see acouvreur/sablier

Traefik middleware to start containers on demand.

Github Actions Go Report Go Version Latest Release

Features

  • Support for Docker containers
  • Support for Docker swarm mode, scale services
  • Support for Kubernetes Deployments and Statefulsets
  • Start your container/service on the first request
  • Automatic scale to zero after configured timeout upon last request the service received
  • Dynamic loading page (cloudflare or grafana cloud style)
  • Customize dynamic and loading pages

Demo

Usage

Plugin configuration

Strategies

Dynamic Strategy (default)

Serve an HTML page that self reload.

testData:
  serviceUrl: http://ondemand:10000
  name: TRAEFIK_HACKATHON_whoami
  timeout: 1m
  waitui: true

Blocking Strategy

Blocking strategy is enabled by setting waitui to false.

Instead of displaying a self refreshing page, the request hangs until the service is ready to receive the request.

The timeout is set by blockdelay.

testData:
  serviceUrl: http://ondemand:10000
  name: TRAEFIK_HACKATHON_whoami
  timeout: 1m
  waitui: false
  blockdelay: 1m

Typical use case: an API calling another API

Custom loading/error pages

The loadingpage and errorpage keys in the plugin configuration can be used to override the default loading and error pages.

The value should be a path where a template that can be parsed by Go's html/template package can be found in the Traefik container.

An example of both a loading page and an error page template can be found in the pkg/pages/ directory in loading.html and error.html respectively.

The plugin will default to the built-in loading and error pages if these fields are omitted.

You must include <meta http-equiv="refresh" content="5" /> inside your html page to get auto refresh.

Example Configuration

testData:
  serviceUrl: http://ondemand:10000
  name: TRAEFIK_HACKATHON_whoami
  timeout: 1m
  waitui: false
  blockdelay: 1m
  loadingpage: /etc/traefik/plugins/traefik-ondemand-plugin/custompages/loading.html
  errorpage: /etc/traefik/plugins/traefik-ondemand-plugin/custompages/error.html
Parameter Type Default Required Example Description
serviceUrl string empty yes http://ondemand:10000 The docker container name, or the swarm service name
name string empty yes (except if names is set) TRAEFIK_HACKATHON_whoami The container/service/kubernetes resource to be stopped (docker ps docker service ls)
names []string [] yes (except if name is set) [TRAEFIK_HACKATHON_whoami-1, TRAEFIK_HACKATHON_whoami-2] The containers/services to be stopped (docker ps docker service ls)
timeout time.Duration 1m no 1m30s The duration after which the container/service will be scaled down to 0
waitui bool true no true Serves a self-refreshing html page when the service is scaled down to 0
displayname string the middleware name no My App Serves a self-refreshing html page when the service is scaled down to 0
blockdelay time.Duration 1m no 1m30s When waitui is false, wait for the service to be scaled up before blockdelay
loadingpage string empty no /etc/traefik/plugins/traefik-ondemand-plugin/custompages/loading.html The path in the traefik container for the loading page template
errorpage string empty no /etc/traefik/plugins/traefik-ondemand-plugin/custompages/error.html The path in the traefik container for the error page template

Traefik-Ondemand-Service

The traefik-ondemand-service must be used to bypass Yaegi limitations.

Yaegi is the interpreter used by Traefik to load plugin and run them at runtime.

The docker library that interacts with the docker deamon uses unsafe which must be specified when instanciating Yaegi. Traefik doesn't, and probably never will by default.

Examples

Development

export TRAEFIK_PILOT_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx docker stack deploy -c docker-compose.yml TRAEFIK_HACKATHON

Authors

Alexis Couvreur (left) Alexandre Hiltcher (middle) Matthias Schneider (right)

Alexandre, Alexis and Matthias

traefik-ondemand-plugin's People

Contributors

acouvreur avatar mschneider82 avatar sourgrasses avatar nastaliss avatar

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.