Add caddy reverse proxy role

Acts as reverse proxy for the docker instance. Can be configured through
docker labels. Proxies anything that is received on port 80 or 443.
This commit is contained in:
Marty Oehme 2025-07-14 10:01:19 +02:00
parent ec91e97fed
commit e6b6154043
Signed by: Marty
GPG key ID: 4E535BC19C61886E
3 changed files with 54 additions and 0 deletions

View file

@ -25,6 +25,11 @@
- name: Prepare all docker hosted containers
hosts: instance_system
tasks:
- name: Set up Caddy stack
ansible.builtin.import_role:
name: caddy
tags: caddy
- name: Set up Arr stack
ansible.builtin.import_role:
name: arr

View file

@ -0,0 +1,19 @@
- name: Install python requirements
ansible.builtin.package:
name: "{{ item }}"
state: present
loop:
- python3-yaml # for docker compose_v2
- python3-requests # for docker network
- name: Ensure caddy network exists
community.docker.docker_network:
name: caddy
- name: Start the compose stack
community.docker.docker_compose_v2:
project_name: caddy
definition: "{{ lookup('template', 'docker-compose.yaml.j2') | from_yaml }}"
remove_orphans: true
wait: true
wait_timeout: 60

View file

@ -0,0 +1,30 @@
services:
caddy:
image: lucaslorentz/caddy-docker-proxy:ci-alpine
ports:
- 80:80
- 443:443
networks:
- caddy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- caddy_data:/caddy
labels:
caddy.auto_https: "off"
whoami:
container_name: whoami
image: traefik/whoami
networks:
- caddy
labels:
caddy: "http://test.pichi.berlin"
caddy.reverse_proxy: "{{ '{{' }}upstreams 80{{ '}}'}}" # has to be done to prevent ansible templating
networks:
caddy:
external: true
volumes:
caddy_data: {}