Giter Club home page Giter Club logo

homer-service-discovery's Introduction

Homer Service Discovery

This tool generates configuration files for Homer using Docker container labels.

Using Docker container or Consul catalog labels for service discovery is inspired by the same approach used by Traefik and Watchtower.

Features

  • Generates Homer config using container labels
  • Watches for container changes or Consul changes
  • Supports standalone Docker and Docker Swarm
  • Sort items by priority
  • Multi-arch

Usage

Create a base configuration for this tool to build upon. This will contain your services sections, title, logo, etc. A value unique to this tool is priority. The higher the priority of an item, the higher on the list it will appear.

title: My Self Hosted Kingdom
subtitle: Enter!

services:
  - name: Numbers
    icon: fas fa-list-ol
    items:
      - name: 4
        icon: fas fa-dice-four
        url: https://fontawesome.com/v5.15/icons/dice-four?style=solid
        priority: 4
      - name: 3
        icon: fab fa-html5
        url: https://fontawesome.com/v5.15/icons/html5?style=brands
        priority: 3
      - name: 1
        icon: far fa-money-bill-alt
        url: https://fontawesome.com/v5.15/icons/money-bill-alt?style=regular
        priority: 1

  # Empty section
  - name: Letters
    icon: fas fa-sun
    items: []

Start Homer following its instructions to mount the /www/assets directory. This is where the config.yaml file resides.

docker run -d \
  -p 8080:8080 \
  -v /folder1/homer/:/www/assets \
  b4bz/homer:latest

Start this tool while:

  • mounting the base config
  • mounting homer's config
  • mounting the Docker socket
  • using environment variables to provide their mountpoints.
docker run -d \
  -v /folder1/homer/config.yml:/config.yml \
  -v /sd/base.yml:/base.yml \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  ghcr.io/calvinbui/homer-service-discovery

You can visit your Homer Dashboard to see the initial generated config (remember to hard refresh).

Start adding labels to your containers to have this tool pick them up. For example, the following command will regenerate the config and add the http-echo service to the Numbers service.

docker run -d \
  -p 5678:5678 \
  -l homer.enable=true \
  -l homer.service=Numbers \
  -l homer.name='This is number 2!' \
  -l homer.subtitle='http-echo server'
  -l homer.icon='far fa-hand-peace' \
  -l homer.priority=2 \
  -l homer.url='http://localhost:5678' \
  hashicorp/http-echo \
  --text="Be yourself; everyone else is already taken"

The full list of labels are:

Label Description
homer.enable Set to true include in Homer's config
homer.service The name of Homer Service to add this item to. It must exist in the base config
homer.priority The priority level of the service. The higher the number, the higher it appears in the Service
homer.name The item's name (See Homer's documentation)
homer.logo The item's logo (See Homer's documentation)
homer.icon The item's icon (See Homer's documentation)
homer.subtitle The item's subtitle (See Homer's documentation)
homer.tag The item's tag (See Homer's documentation)
homer.url The item's url (See Homer's documentation)
homer.target The item's target (See Homer's documentation)
homer.tagstyle The item's tagstyle (See Homer's documentation)
homer.type The item's type (See Homer's documentation)
homer.class The item's class (See Homer's documentation)
homer.background The item's background (See Homer's documentation)

Environment Variables

Key Description Default
LOG_LEVEL The level of log verbosity Info
HOMER_BASE_CONFIG Where the base config is located /base.yml
HOMER_CONFIG Where the Homer config is located /config.yml
SERVICE_DISCOVERY Either Docker or Consul Docker
HOMER_DOCKER_SWARM Docker Swarm supprt. Either true or false false
CONSUL_HOST Host for Consul connnection 127.0.0.1:8500

homer-service-discovery's People

Contributors

calvinbui avatar dependabot[bot] avatar kungfoochris avatar thecubed avatar vincentdcmps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

homer-service-discovery's Issues

[BUG] - Couldn't get it to work

Describe the bug
New service is not getting added even after adding label to docker container running on the same network

To Reproduce
Steps to reproduce the behaviour:

  1. i created base.yml and config.yml for homer
  2. Started homer container loadsup fine with config.yml
  3. started homer-sd container on same network as homer '....'
  4. See log
# docker service logs  dashboards_homer-sd
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 11:59AM DBG Loading internal config
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 11:59AM INF Building Homer config from base config
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 11:59AM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 11:59AM INF Start watching for container creations and deletions
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 11:59AM INF Event 'start' received from dashboards_homer.1.lks2ch79joktgvs3cfd9nvq2a. Generating Homer config...
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 11:59AM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 11:59AM INF Event 'health_status: healthy' received from dashboards_homer.1.lks2ch79joktgvs3cfd9nvq2a. Generating Homer config...
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 11:59AM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:00PM INF Event 'die' received from traefik_reverse-proxy.3rqeb31c9upeocahsfbbcob5x.n5hs805nmgvi2jhr9ni7xn48l. Generating Homer config...
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:00PM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:00PM INF Event 'start' received from traefik_reverse-proxy.3rqeb31c9upeocahsfbbcob5x.zd4gg2jrl7xey1qhml0hc3a7p. Generating Homer config...
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:00PM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:12PM INF Event 'health_status: unhealthy' received from frontends_dashy.1.a72bzyx54bq7trtz6wabdkdno. Generating Homer config...
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:12PM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:12PM INF Event 'die' received from frontends_dashy.1.a72bzyx54bq7trtz6wabdkdno. Generating Homer config...
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:12PM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:12PM INF Event 'start' received from frontends_dashy.1.rxvia8fimadhrd6fdu07dqiz0. Generating Homer config...
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:12PM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:27PM INF Event 'die' received from frontends_dashy.1.rxvia8fimadhrd6fdu07dqiz0. Generating Homer config...
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:27PM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:27PM INF Event 'die' received from frontends_uptime-kuma.1.psywehcro0tjqtqaa5qq2zixk. Generating Homer config...
dashboards_homer-sd.1.6zdppva9ud9m@swarm-master    | 12:27PM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.ntyny9cgtrir@swarm-master    | 12:27PM DBG Loading internal config
dashboards_homer-sd.1.ntyny9cgtrir@swarm-master    | 12:27PM INF Building Homer config from base config
dashboards_homer-sd.1.ntyny9cgtrir@swarm-master    | 12:27PM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.ntyny9cgtrir@swarm-master    | 12:27PM INF Start watching for container creations and deletions
dashboards_homer-sd.1.ntyny9cgtrir@swarm-master    | 12:37PM INF Event 'start' received from frontends_uptime-kuma.1.qfjmfeong6rhmullelvrnxm8i. Generating Homer config...
dashboards_homer-sd.1.ntyny9cgtrir@swarm-master    | 12:37PM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.ntyny9cgtrir@swarm-master    | 12:37PM INF Event 'start' received from frontends_dashy.1.lo752yrz6192zitujoc3lopv1. Generating Homer config...
dashboards_homer-sd.1.ntyny9cgtrir@swarm-master    | 12:37PM INF Homer config was successfully generated and updated
dashboards_homer-sd.1.ntyny9cgtrir@swarm-master    | 12:38PM INF Event 'health_status: healthy' received from frontends_uptime-kuma.1.qfjmfeong6rhmullelvrnxm8i. Generating Homer config...
dashboards_homer-sd.1.ntyny9cgtrir@swarm-master    | 12:38PM INF Homer config was successfully generated and updated

this is my docker compose stack file

# cat ../dashboards/homer/docker-compose.yml 
version: "3.7"

services:
  homer:
    image: b4bz/homer:22.02.1
    hostname: "homer"
    networks:
      - web
    volumes:
      - /data/homer/assets:/www/assets
    ports:
      - 8095:8080
    # Set any environmental variables
    environment:
      DOCKER_HOST: dockersocket
    deploy:
      labels:
          - "traefik.enable=true"
          - "traefik.http.routers.homer-http.rule=Host(`homer.home.local`)"
          - "traefik.http.routers.homer-http.entrypoints=web"
          - "traefik.http.routers.homer-http.service=homer-http-svc"
          - "traefik.http.services.homer-http-svc.loadbalancer.server.port=8080"
          - "traefik.http.services.homer-http-svc.loadbalancer.passhostheader=true"
          - "diun.enable=true"
      mode: replicated
      replicas: 1
      restart_policy:
        condition: on-failure
      placement:
        constraints:
           - "node.role==manager"

  homer-sd:
    image: ghcr.io/calvinbui/homer-service-discovery
    hostname: "homer-sd"
    networks:
      - web
    volumes:
      - /data/homer/assets/config.yml:/config.yml
      - /data/homer/sd/base.yml:/base.yml
      - /var/run/docker.sock:/var/run/docker.sock:ro
    deploy:
      labels:
          - "diun.enable=true"
      mode: replicated
      replicas: 1
      restart_policy:
        condition: on-failure
      placement:
        constraints:
           - "node.role==manager"

networks:
  web:
    external: true
    name: web

and this is my traefik-stack.yml

# cat traefik-stack.yml 
version: '3.7'

services:
  reverse-proxy:
    image: traefik:2.6
    hostname: "traefik"
    command:
      - "--api.dashboard=true"
      - "--providers.docker"
      - "--providers.docker.swarmMode=true"
      - "--entrypoints.web.address=:80"
      - "--providers.docker.exposedByDefault=false"
      - "--providers.docker.network=web"
      - "--log.level=DEBUG"
      - "--log.filePath=/var/log/traefik.log"
      - "--accessLog.filePath=/var/log/access.log"
    ports:
      - "80:80"
      - "8080:8080"
    environment:
      DOCKER_HOST: dockersocket
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/log/traefik.log:/var/log/traefik.log
      - /var/log/access.log:/var/log/access.log
      - /home/ansible/stacks/traefik/static/traefik.yml:/traefik.yml
      - /home/ansible/stacks/traefik/config:/config/
    networks:
      - web
    deploy:
      labels:
          - "diun.enable=true"
          - "traefik.enable=true"
          - "traefik.http.routers.api.rule=Host(`traefik.home.local`)"
          - "traefik.http.routers.api.service=api@internal"
          # - "traefik.http.routers.api.middlewares=auth"
          # - "traefik.http.middlewares.auth.basicauth.users="
          # Dummy service for Swarm port detection. The port can be any valid integer value.
          - "traefik.http.services.dummy-svc.loadbalancer.server.port=9999"
          # Homer Service discovery label
          - "homer.enable=true"
          - "homer.service=Homelab"
          - "homer.name=traefik"
          - "homer.subtitle='traefik Reverse Proxy'"
          - "homer.icon='far fa-hand-peace'"
          - "homer.priority=2"
          - "homer.url='http://traefik.home.local'"
      mode: global
      placement:
        constraints: [node.role == manager]

networks:
  proxy:
    driver: bridge
    external: true

networks:
  web:
    driver: overlay
    attachable: true
    name: web


Expected behavior
A new service addition as shown in the example.

Additional context
in homer service discovery log noticed not sure why is it attempting to load dashy

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.