Giter VIP home page Giter VIP logo

caddy-builder's Introduction

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 [email protected]
}

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.

caddy-builder's People

Contributors

stefanprodan avatar

Stargazers

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

Watchers

 avatar  avatar  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.