Skip to content

Commit

Permalink
improvements (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
obvionaoe authored May 12, 2024
1 parent 6caa4ea commit 5afd142
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 223 deletions.
3 changes: 0 additions & 3 deletions .ansible-lint

This file was deleted.

3 changes: 0 additions & 3 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# These are supported funding model platforms
---
patreon: obvionaoe
custom:
- https://www.buymeacoffee.com/obvionaoe
- https://paypal.me/obvionaoe
53 changes: 0 additions & 53 deletions .github/stale.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: ansible-lint
on:
pull_request:
branches:
- main
jobs:
ansible-lint:
name: Ansible Lint # Naming the build is important to use it as a status check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ansible-lint
uses: ansible/ansible-lint@main # or version tag instead of 'main'
62 changes: 0 additions & 62 deletions .github/workflows/testing.yml

This file was deleted.

7 changes: 0 additions & 7 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
---
extends: default

rules:
line-length:
max: 200
level: warning

ignore: |
.github/*.yml
101 changes: 63 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,100 @@
# Ansible Role: Caddy

<!-- [![CI](https://github.com/obvionaoe/ansible-role-caddy/workflows/CI/badge.svg?event=push)](https://github.com/obvionaoe/ansible-role-caddy/actions?query=workflow%3ACI) -->
[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![Project Status](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Ansible Galaxy](https://img.shields.io/ansible/role/57668)](https://galaxy.ansible.com/obvionaoe/caddy)

An Ansible role to set up a [Caddy](https://caddyserver.com/) server running in Docker with the [Docker Proxy](https://github.com/lucaslorentz/caddy-docker-proxy) plugin installed.

## Requirements

Docker.
- [Docker](https://docker.io)

## Role Variables

Available variables are listed below, along with default values (see `defaults/main.yml`):

caddy_host_user: caddy
caddy_host_group: caddy
```yaml
timezone: Etc/UTC
```
The timezone the container should be in. This variable does not include the `caddy` prefix so that all roles that support this feature can be configured through a single variable.

```yaml
caddy_timezone: "{{ timezone }}"
```

The timezone the container should be in. This variable is by default set to the value passed to the `timezone` variable and is used only when, for some reason, the timezone to be passed to Caddy's container should not be the one that the `timezone` variable is set to.

The `user` and `group` to use when creating the host directories.
```yaml
caddy_host_user: caddy
caddy_host_group: caddy
```

caddy_host_dir: /caddy
caddy_host_data_dir: "{{ caddy_host_dir }}/data"
The user and group to use when creating the host directories.

```yaml
caddy_host_dir: /caddy
caddy_host_data_dir: "{{ caddy_host_dir }}/data"
```

The root host directory and the data directory that will be mounted onto the container.

caddy_image_tag: '2.4'
caddy_image_name: 'lucaslorentz/caddy-docker-proxy'
caddy_image: "{{ caddy_image_name }}:{{ caddy_image_tag }}"
```yaml
caddy_image_tag: '2.8'
caddy_image_name: 'lucaslorentz/caddy-docker-proxy'
caddy_image: "{{ caddy_image_name }}:{{ caddy_image_tag }}"
```

Variables to control which image will be used when running the container, in case you build your own image.

caddy_container_name: caddy
```yaml
caddy_container_name: caddy
```

The name to give to the container.

caddy_container_state: started
caddy_container_restart_handler_state: restarted
caddy_container_restart_policy: unless-stopped
caddy_container_restart_retries: 5
```yaml
caddy_container_restart_policy: unless-stopped
caddy_container_restart_retries: 5
```

Variables to control the `state` of the container, and the `restart_policy`.
Variables to control the state of the container, and the restart policy.

caddy_container_volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- "{{ caddy_host_data_dir }}:/data"
```yaml
caddy_container_volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- "{{ caddy_host_data_dir }}:/data"
```

Variable to specify which host directories should be mounted to the container.

caddy_container_ports:
- 80:80
- 443:443
```yaml
caddy_container_ports:
- 80:80
- 443:443
```

Variable to specify which `container ports` to publish.
Variable to specify which container ports to publish.

caddy_create_networks: true
caddy_container_networks:
- name: caddy
```yaml
caddy_create_networks: true
caddy_container_networks:
- name: caddy
```

Variables to specify what Docker `networks` to add the container to, and if these `networks` should be created.
Variables to specify what Docker networks to add the container to, and if these networks should be created.

caddy_container_labels: {}
```yaml
caddy_container_labels: {}
```

Variable to define labels to give to the container. These labels are used to configure Caddy. A comprehensive guide on how to use the labels can be found [here](https://github.com/lucaslorentz/caddy-docker-proxy#caddy-cli).

caddy_container_env_vars:
TZ: Europe/Lisbon
CADDY_INGRESS_NETWORKS: '"{{ caddy_container_networks[0].name }}"'
```yaml
caddy_container_env_vars: {}
```

Variable to define environment variables to pass to the container. A full list of the available options can be found [here](https://github.com/lucaslorentz/caddy-docker-proxy#caddy-cli).
Variable to define environment variables to pass to the container. A full list of the available options can be found [here](https://github.com/lucaslorentz/caddy-docker-proxy#caddy-cli).

## Dependencies

Expand All @@ -77,10 +105,7 @@ None.
```yaml
- hosts: all
roles:
- name: obvionaoe.caddy
caddy_container_labels:
caddy: www.example.com
caddy.redir: https://example.com{uri}
- obvionaoe.caddy
```

## License
Expand All @@ -90,4 +115,4 @@ MIT

## Author Information

This role was created in 2022 by [Luís Guimarâes](https://obvionaoe.xyz).
This role was created in 2022 by [Luís Guimarâes](https://obvionaoe.dev).
16 changes: 11 additions & 5 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
---
timezone: Etc/UTC

caddy_timezone: "{{ timezone }}"

caddy_host_user: caddy
caddy_host_group: caddy

caddy_host_dir: /caddy
caddy_host_data_dir: "{{ caddy_host_dir }}/data"

caddy_image_tag: '2.4'
caddy_image_tag: '2.8'
caddy_image_name: 'lucaslorentz/caddy-docker-proxy'
caddy_image: "{{ caddy_image_name }}:{{ caddy_image_tag }}"

caddy_container_name: caddy

caddy_container_state: started
caddy_container_restart_handler_state: started
caddy_container_restart_policy: unless-stopped
caddy_container_restart_retries: 5

Expand All @@ -25,11 +27,15 @@ caddy_container_ports:
- 443:443

caddy_create_networks: true

# The first network should be de caddy network where other containers also need to be
caddy_container_networks:
- name: caddy

caddy_container_labels: {}

caddy_container_env_vars:
TZ: Europe/Lisbon
caddy_container_env_vars: {}

__caddy_preset_env_vars:
TZ: "{{ caddy_timezone }}"
CADDY_INGRESS_NETWORKS: '"{{ caddy_container_networks[0].name }}"'
4 changes: 2 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Restart Caddy
docker_container:
community.docker.docker_container:
name: "{{ caddy_container_name }}"
state: "{{ caddy_container_restart_handler_state }}"
state: started
restart: true
10 changes: 8 additions & 2 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ galaxy_info:

license: license (MIT)

min_ansible_version: 2.4
min_ansible_version: "2.4"

platforms:
- name: Ubuntu
versions:
- focal
- jammy

- name: Debian
versions:
- bullseye
- bookworm

galaxy_tags:
- caddy
Expand All @@ -20,4 +26,4 @@ galaxy_info:
- server
- web

dependencies: []
dependencies: []
14 changes: 0 additions & 14 deletions molecule/default/converge.yml

This file was deleted.

Loading

0 comments on commit 5afd142

Please sign in to comment.