Code Monkey home page Code Monkey logo

traefik-pages's Introduction

traefik-pages

CI

Website hosting server (think GitHub Pages) designed to deeply integrate with Traefik for routing and TLS termination.

Work in progress

Usage

Create a directory of directories, where the name of each directory is the hostname of a site you want to serve, with its content inside.

/mnt/sites
├── example.com
│   └── index.html
└── othersite.example.com
    └── index.html

How the files get there is up to you. Minio, rsync, webdav, ansible, doesn't matter.

How it works

traefik-pages integrates with Traefik via the HTTP provider. When Traefik hits the API, traefik-pages lists the directories containing sites to get the hostnames required, and returns a configuration of routers for Traefik to use. These routers have rules matching the hostnames from the directories, and services matching the one specified for traefik-pages. Traefik constantly polls traefik-pages for an updated configuration, so newly created sites wll be quickly picked up on.

Installation

First, create a container for traefik-pages:

  traefik-pages:
    image: theorangeone/traefik-pages:latest
    volumes:
      - ./sites:/mnt/sites:ro
    environment:
      - SITES_ROOT=/mnt/sites
      - TRAEFIK_SERVICE=traefik-pages@docker
      - AUTH_PASSWORD=hunter2
    labels:
      - traefik.enable=true

This doesn't need to be in the same file as Traefik, but it does need to be accessible to Traefik using a fixed hostname and IP. If Traefik is running in host mode (as I do), you'll need to bind traefik-pages to an internal interface, and listen to that.

The label enables traefik autoconfiguration to detect traefik-pages. Note that $TRAEFIK_SERVICE must match the service name created by traefik.

Next, you'll need to create a HTTP provider for Traefik, using the ports and password previously configured.

providers:
  ...
  http:
    endpoint:
      - "http://[email protected]:5000/.traefik-pages/provider"

Here you can also configure the polling interval for traefik-pages.

Now, simply start Traefik and traefik-pages, and they should begin communicating and creating routers for your sites.

Configuration

Configuration for traefik-pages is done entirely through environment variables:

  • $SITES_ROOT: Directory where sites are stored (required).

  • $TRAEFIK_SERVICE: Service name for traefik-pages, where traffic will be routed (required).

  • $AUTH_PASSWORD: Basic auth username required for access to private URLs (/.traefik-pages/*) (required).

  • $DENY_PREFIXES: Comma-separated list of URL prefixes to ignore (immediately return 404). Empty by default.

  • $LOG_INTERNAL: Whether to log requests for internal URLs (default false).

  • $TRAEFIK_CERT_RESOLVER: Traefik certificate resolver to use to provision TLS certificates (by default no certificates will be requested).

  • $PORT: Port to listen on (default 5000).

  • $WORKERS: Number of worker processes to handle requests (default 1).

Performance

traefik-pages is written in Rust, and designed to be as fast as possible.

Requests per second:    6786.85 [#/sec] (mean)
Time per request:       14.734 [ms] (mean)
Time per request:       0.147 [ms] (mean, across all concurrent requests)
Transfer rate:          1471.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     3   15   5.5     14      51
Waiting:        2   14   5.5     14      51
Total:          3   15   5.5     14      51

Percentage of the requests served within a certain time (ms)
  50%     14
  66%     16
  75%     17
  80%     18
  90%     21
  95%     25
  98%     30
  99%     35
 100%     51 (longest request)

These tests were run on a 2600X, with a single worker process.

traefik-pages's People

Contributors

codemonkeysoftware avatar realorangeone avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

traefik-pages's Issues

Docker compose configuration

I mixed up the alias settings of Docker 😞 .
Correct docker.compose.yml:

version: "3.3"

services:
  traefik:
    container_name: traefik
    image: traefik:latest
    command: "--log.level=DEBUG"
    ports:
      - "443:443"
      - "8080:8080"
    networks:
      web:
      traefikpages:
        aliases:
          - traefik
    volumes:
      - "./letsencrypt:/letsencrypt"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - ./traefik:/etc/traefik

  traefik-pages:
    container_name: traefik-pages
    image: theorangeone/traefik-pages:latest
    volumes:
      - ./sites:/mnt/sites:ro
    environment:
      - SITES_ROOT=/mnt/sites
      - TRAEFIK_SERVICE=traefik-pages@docker
      - AUTH_PASSWORD=hunter2
      - TRAEFIK_CERT_RESOLVER=le
    labels:
      - traefik.enable=true
    networks:
      traefikpages:
        aliases:
         - traefikpages

networks:
  web:
    external: true
  traefikpages:

traefik.yml

entryPoints:
  web:
    address: ":80"
  web-secure:
    address: ":443"

ping: {}

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    watch: true
    exposedByDefault: false
  http:
    endpoint:
      - "http://hunter2@traefikpages:5000/.traefik-pages/provider"
  file:
    filename: /etc/traefik/file-provider.yml

api:
  dashboard: true
  insecure: true

certificatesResolvers:
  le:
    acme:
      email: "[email protected]" # Change this
      storage: "acme.json"
#      caServer: "https://acme-staging-v02.api.letsencrypt.org/directory"
      tlsChallenge: true

file-provider.yml

http:
  services:
    traefik-pages:
      loadBalancer:
        servers:
          - url: "http://traefikpages:5000"
OP I'm struggling to get traefik-pages to work. Right now I'm stuck on: ``` traefik | time="2022-05-03T15:51:26Z" level=error msg="Provider connection error cannot fetch configuration data: Get \"http://hunter2@traefikpages:5000/.traefik-pages/provider\": dial tcp 172.22.0.3:5000: connect: connection refused, retrying in 342.491979ms" providerName=http ```

Any chance you could point me in the right direction?

docker-compose.yml

version: "3.3"

services:
  traefik:
    container_name: traefik
    image: traefik:latest
    ports:
      - "443:443"
      - "8080:8080"
    networks:
      web:
      traefikpages:
        aliases:
          - traefikpages
    volumes:
      - "./letsencrypt:/letsencrypt"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - ./traefik:/etc/traefik

  traefik-pages:
    container_name: traefik-pages
    image: theorangeone/traefik-pages:latest
    volumes:
      - ./sites:/mnt/sites:ro
    environment:
      - SITES_ROOT=/mnt/sites
      - TRAEFIK_SERVICE=traefik-pages@docker
      - AUTH_PASSWORD=hunter2
    labels:
      - traefik.enable=true
    ports:
      - "5000:5000"
    networks:
      traefikpages:

networks:
  web:
    external: true
  traefikpages:

traefik/traefik.yml

entryPoints:
  web:
    address: ":80"
  web-secure:
    address: ":443"

ping: {}

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    watch: true
    exposedByDefault: false
  http:
    endpoint:
      - "http://hunter2@traefikpages:5000/.traefik-pages/provider"
  file:
    filename: /etc/traefik/file-provider.yml

api:
  dashboard: true
  insecure: true

log:
  level: DEBUG

traefik/file-provider.yml

http:
  services:
    traefik-pages:
      loadBalancer:
        servers:
          - url: "http://traefikpages:5000"

I'm guessing it's some trivial error, but I'm failing to find it 🙃 .

Documentation $TRAEFIK_SERVICE does not match actual service

Currently the documentation lists the $TRAEFIK_SERVICE as traefik-pages@docker, but the service is created using a file and is therefore traefik-pages@file so traefik cannot find the service. Either $TRAEFIK_SERVICE should point to the file service or the docker-compose example should include tags to create the docker service.

I'm happy to submit an MR for the change, but thought you might have a preference for which solution was used.

Thanks for building this, btw. It's really handy.

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.