Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

stefanprodan/caddy-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

caddy-builder

Build Status

Build Caddy with plugins from source using Docker multi-build

Usage

Clone the caddy-builder repository:

$ git clone https://github.com/stefanprodan/caddy-builder.git
$ cd caddy-builder

Add the Caddy plugins that you want to the plugins.go file:

package caddyhttp

import (
	// http.prometheus
	_ "github.com/miekg/caddy-prometheus"
	// http.ipfilter
	_ "github.com/pyed/ipfilter"
)

Edit the docker-compose file and replace the image prefix with your own repo name:

version: "3.3"

services:
  caddy:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        CADDY_VERSION: ${CADDY_VERSION:-0.10.9}
    image: stefanprodan/caddy:${CADDY_VERSION:-0.10.9}
    container_name: caddy
    ports:
      - 80:80
      - 443:443
      - 9180:9180

Build the image with Docker Compose:

CADDY_VERSION=0.10.9 docker-compose build caddy

Run Caddy container exposing 80, 443 and 9180 ports:

docker-compose up -d

Remove the container, www volume and image:

docker-compose down -v --rmi all

Running Caddy with Docker

The stefanprodan/caddy comes with a default Caddyfile that you can override by mounting your own config:

$ docker run -d --name caddy \
    -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile \
    -p 80:80 \
    stefanprodan/caddy

Mount your site root using the www volume:

$ docker run -d --name caddy \
    -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile \
    -v $(pwd)/site:/www \
    -p 80:80 \
    stefanprodan/caddy

Expose the Prometheus metric endpoint on http://localhost:9180/metrics:

$ docker run -d --name caddy \
    -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile \
    -v $(pwd)/site:/www \
    -p 80:80 -p 9180:9180 \
    stefanprodan/caddy

In your Caddyfile configure the http.prometheus plugin:

example.com {
    prometheus 0.0.0.0:9180
    log stdout
    errors stderr
}

Persist Let's Encrypt certificates on host:

$ docker run -d --name caddy \
    -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile \
    -v $(pwd)/certs:/.caddy \
    -p 80:80 -p 443:443 \
    stefanprodan/caddy

In your Caddyfile configure the tls email:

example.com {
    tls contact@example.com
}

Running Caddy with Docker Swarm

In order to deploy Caddy with a custom config on Docker Swarm, you need to use Docker engine version 17.06 or later. The Caddy image has curl installed so you can easily define a health check:

version: "3.3"

configs:
  caddy_config:
    file: ./Caddyfile

volumes:
  certs: {}

services:
  caddy:
    image: stefanprodan/caddy
    ports:
      - 80:80
      - 443:443
    configs:
      - source: caddy_config
        target: /etc/caddy/Caddyfile
    volumes:
      - certs:/.caddy
    deploy:
      mode: replicated
      replicas: 1    
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:80"]
      interval: 5s
      timeout: 1s
      retries: 3

License

The caddy-builder is MIT licensed and the Caddy source code is Apache 2.0 licensed. Because stefanprodan/caddy is built from source, it's not subject to the EULA for Caddy's official binary distributions. If you plan to use Caddy for commercial purposes you should run the official Caddy distribution.

About

Build Caddy with plugins as an Ingress/Proxy for OpenFaaS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages