Compare commits

...

2 Commits

Author SHA1 Message Date
bf361bd587 inital setup 2023-06-10 21:09:01 +02:00
f3b17e69ff inital setup 2023-06-10 21:08:44 +02:00
7 changed files with 104 additions and 1 deletions

5
.env.sample Normal file
View File

@@ -0,0 +1,5 @@
TAG=
APIPORT=
BASEDIR=
EXTRANET=
INTRANET=

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
files/
.env

View File

@@ -1,2 +1,46 @@
# compose-caddy
# Basic Caddy docker-compose config
* can be run on single node setup or in swarm
* recommend to set `replicas` on 2 or more if deploy in swarm
## howto
### single node
#### start container
```bash
docker compose up -d
```
#### stop container (and remove)
```bash
docker compose down
```
#### view logs
```bash
docker compose logs -f
```
#### reload config
```bash
docker compose restart
```
### swarm
#### start aka deploy
```bash
docker stack deploy -c docker-compose.yml caddy
```
#### stop container aka service
```bash
docker service rm caddy_caddy
```
#### view logs
```bash
docker service logs caddy_caddy -f
```
#### reload config (no downtime if replica 2 or more)
```bash
docker service update caddy_caddy --force
```

34
docker-compose.yml Normal file
View File

@@ -0,0 +1,34 @@
# https://docs.docker.com/compose/compose-file/compose-file-v3/
---
version: "3.9"
services:
caddy:
image: caddy:${TAG:-alpine}
container_name: caddy
env_file: .env
restart: unless-stopped
deploy:
replicas: 1 # in swarm set min 2
placement:
max_replicas_per_node: 1
update_config:
parallelism: 1
delay: 10s
ports:
- 80:80
- 443:443
- ${APIPORT:-2019}:2019
volumes:
- ${BASEDIR:-./files}/conf:/etc/caddy/
- ${BASEDIR:-./files}/data/:/data
networks:
- frontend
- backend
networks:
frontend:
name: ${EXTRANET:-frontend}
external: true
backend:
name: ${INTRANET:-backend}
external: true

2
files/conf/Caddyfile Normal file
View File

@@ -0,0 +1,2 @@
import snippets/*
import pages/*

View File

@@ -0,0 +1,4 @@
http://example.com {
import auth "*"
respond "example.com here!"
}

12
files/conf/snippets/auth Normal file
View File

@@ -0,0 +1,12 @@
## generate pass hash (debian):
# sudo apt install apache2-utils
# htpasswd -bnBC 10 "" password | tr -d ':'
# user: test
# password: password
(auth) {
basicauth {args.0} {
test $2y$10$XSrHHXUlQZeRumAc9nl7QevDzKv9H5TXVtb6nxr0Gmrk6VogHWRVK
}
}