From 5922e5562728589af3969683cd3eb15085914f12 Mon Sep 17 00:00:00 2001 From: obvionaoe Date: Sun, 12 May 2024 23:45:32 +0100 Subject: [PATCH] improvements --- .ansible-lint | 3 - .github/FUNDING.yml | 3 - .github/stale.yml | 53 ------------------ .github/workflows/lint.yml | 13 +++++ .github/workflows/testing.yml | 62 --------------------- .yamllint | 7 --- README.md | 101 +++++++++++++++++++++------------- defaults/main.yml | 16 ++++-- handlers/main.yml | 4 +- meta/main.yml | 10 +++- molecule/default/converge.yml | 14 ----- molecule/default/molecule.yml | 14 ----- molecule/default/prepare.yml | 6 -- molecule/default/verify.yml | 8 --- tasks/main.yml | 12 ++-- 15 files changed, 103 insertions(+), 223 deletions(-) delete mode 100644 .ansible-lint delete mode 100644 .github/stale.yml create mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/testing.yml delete mode 100644 molecule/default/converge.yml delete mode 100644 molecule/default/molecule.yml delete mode 100644 molecule/default/prepare.yml delete mode 100644 molecule/default/verify.yml diff --git a/.ansible-lint b/.ansible-lint deleted file mode 100644 index 1871ae2..0000000 --- a/.ansible-lint +++ /dev/null @@ -1,3 +0,0 @@ ---- -skip_list: - - risky-shell-pipe diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index efab7e8..6a0a365 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,6 +1,3 @@ -# These are supported funding model platforms --- -patreon: obvionaoe custom: - - https://www.buymeacoffee.com/obvionaoe - https://paypal.me/obvionaoe diff --git a/.github/stale.yml b/.github/stale.yml deleted file mode 100644 index 1e3a00f..0000000 --- a/.github/stale.yml +++ /dev/null @@ -1,53 +0,0 @@ -# Configuration for probot-stale - https://github.com/probot/stale ---- -# Number of days of inactivity before an Issue or Pull Request becomes stale -daysUntilStale: 90 - -# Number of days of inactivity before an Issue or Pull Request with the stale label is closed. -# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. -daysUntilClose: 30 - -# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) -onlyLabels: [] - -# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable -exemptLabels: - - bug - - pinned - - security - - planned - -# Set to true to ignore issues in a project (defaults to false) -exemptProjects: false - -# Set to true to ignore issues in a milestone (defaults to false) -exemptMilestones: false - -# Set to true to ignore issues with an assignee (defaults to false) -exemptAssignees: false - -# Label to use when marking as stale -staleLabel: stale - -# Limit the number of actions per hour, from 1-30. Default is 30 -limitPerRun: 30 - -pulls: - markComment: |- - This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution! - - unmarkComment: >- - This pull request is no longer marked for closure. - - closeComment: >- - This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details. - -issues: - markComment: |- - This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! - - unmarkComment: >- - This issue is no longer marked for closure. - - closeComment: >- - This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..3028753 --- /dev/null +++ b/.github/workflows/lint.yml @@ -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' diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml deleted file mode 100644 index 1fbce54..0000000 --- a/.github/workflows/testing.yml +++ /dev/null @@ -1,62 +0,0 @@ ---- -name: Testing with Molecule - -on: - pull_request: - branches: - - master - push: - branches: - - master - schedule: - - cron: "0 7 */15 * *" - -defaults: - run: - working-directory: 'obvionaoe.caddy' - -jobs: - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - name: Check out the codebase. - uses: actions/checkout@v2 - with: - path: 'obvionaoe.caddy' - - - name: Set up Python 3. - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - - name: Install test dependencies. - run: | - pip3 install ansible yamllint ansible-lint - ansible-galaxy role install geerlingguy.docker - - - name: Lint code. - run: | - pwd - yamllint . - ansible-lint - - molecule: - name: Molecule - runs-on: ubuntu-latest - # strategy: - # fail-fast: false - - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - path: 'obvionaoe.caddy' - - - name: Test - uses: gofrolist/molecule-action@v2 - with: - molecule_command: test - molecule_working_dir: 'obvionaoe.caddy' - env: - ANSIBLE_FORCE_COLOR: '1' diff --git a/.yamllint b/.yamllint index adda317..7509c15 100644 --- a/.yamllint +++ b/.yamllint @@ -1,10 +1,3 @@ --- -extends: default - -rules: - line-length: - max: 200 - level: warning - ignore: | .github/*.yml diff --git a/README.md b/README.md index 8f43943..7cf209d 100644 --- a/README.md +++ b/README.md @@ -1,72 +1,100 @@ # Ansible Role: Caddy - -[![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 @@ -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 @@ -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). diff --git a/defaults/main.yml b/defaults/main.yml index dda3b9b..688823f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 @@ -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 }}"' diff --git a/handlers/main.yml b/handlers/main.yml index ac7cb75..3ba6e0c 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 diff --git a/meta/main.yml b/meta/main.yml index 87b6021..7ef9157 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -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 @@ -20,4 +26,4 @@ galaxy_info: - server - web - dependencies: [] +dependencies: [] diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml deleted file mode 100644 index 482af12..0000000 --- a/molecule/default/converge.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: Converge - hosts: localhost - become: true - gather_facts: false - pre_tasks: - - name: Update apt cache (on Debian). - apt: - update_cache: true - cache_valid_time: 3600 - when: ansible_os_family == 'Debian' - - roles: - - role: obvionaoe.caddy diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml deleted file mode 100644 index 2bd5967..0000000 --- a/molecule/default/molecule.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -dependency: - name: galaxy - -driver: - name: docker - -platforms: - - name: ubuntu2004 - image: geerlingguy/docker-ubuntu2004-ansible - pre_build_image: true - -provisioner: - name: ansible diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml deleted file mode 100644 index 7ec3449..0000000 --- a/molecule/default/prepare.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: Prepare - hosts: localhost - become: true - roles: - - geerlingguy.docker diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml deleted file mode 100644 index 6427f53..0000000 --- a/molecule/default/verify.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Verify - hosts: localhost - tasks: - - name: Verify Caddy is serving web requests. - uri: - url: http://localhost:80 - status_code: 200 diff --git a/tasks/main.yml b/tasks/main.yml index d99b47d..c96fdd6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,32 +1,32 @@ --- - name: Create Caddy directories - file: + ansible.builtin.file: path: "{{ item }}" owner: "{{ caddy_host_user }}" group: "{{ caddy_host_group }}" state: directory - mode: 0744 + mode: "0744" loop: - "{{ caddy_host_dir }}" - "{{ caddy_host_data_dir }}" - name: Create Docker networks - docker_network: + community.docker.docker_network: name: "{{ item.name }}" loop: "{{ caddy_container_networks }}" when: caddy_create_networks | bool - name: Start Caddy Docker Proxy - docker_container: + community.docker.docker_container: name: "{{ caddy_container_name }}" image: "{{ caddy_image }}" restart_policy: "{{ caddy_container_restart_policy }}" volumes: "{{ caddy_container_volumes }}" - env: "{{ caddy_container_env_vars }}" + env: "{{ __caddy_preset_env_vars | ansible.builtin.combine(caddy_container_env_vars) }}" published_ports: "{{ caddy_container_ports }}" networks: "{{ caddy_container_networks }}" labels: "{{ caddy_container_labels }}" detach: true - state: "{{ caddy_container_state }}" + state: started notify: - Restart Caddy