├── .github ├── renovate.json └── workflows │ ├── ci.yaml │ ├── deploy.yaml │ ├── labels.yaml │ ├── lock.yaml │ ├── pr-labels.yaml │ ├── release-drafter.yaml │ └── stale.yaml ├── .yamllint ├── LICENSE ├── README.md └── caddy-2 ├── .README.j2 ├── DOCS.md ├── Dockerfile ├── build.yaml ├── config.yaml ├── icon.png ├── logo.png └── rootfs ├── etc ├── caddy │ └── Caddyfile └── s6-overlay │ └── s6-rc.d │ ├── caddy │ ├── dependencies.d │ │ └── base │ ├── finish │ ├── run │ └── type │ └── user │ └── contents.d │ └── caddy └── usr └── bin └── caddy.sh /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "rebaseWhen": "behind-base-branch", 4 | "dependencyDashboard": true, 5 | "labels": ["dependencies", "no-stale"], 6 | "commitMessagePrefix": "⬆️", 7 | "commitMessageTopic": "{{depName}}", 8 | "regexManagers": [ 9 | { 10 | "fileMatch": ["/Dockerfile$", "/build.yaml$"], 11 | "matchStringsStrategy": "any", 12 | "matchStrings": [ 13 | "ARG BUILD_FROM=(?.*?):(?.*?)\\s+", 14 | "(aarch64|amd64|armhf|armv7|i386):\\s[\"']?(?.*?):(?.*?)[\"']?\\s" 15 | ], 16 | "datasourceTemplate": "docker" 17 | }, 18 | { 19 | "fileMatch": ["/Dockerfile$"], 20 | "matchStrings": [ 21 | "ENV CADDY_VERSION=[\"']?(?v[\\d.]+)[\"']?" 22 | ], 23 | "datasourceTemplate": "github-releases", 24 | "depNameTemplate": "caddyserver/caddy" 25 | }, 26 | { 27 | "fileMatch": ["/Dockerfile$"], 28 | "matchStringsStrategy": "any", 29 | "matchStrings": [ 30 | "\\s\\s(?[a-z0-9-]+)=(?[a-z0-9-_.]+)\\s+" 31 | ], 32 | "versioningTemplate": "loose", 33 | "datasourceTemplate": "repology", 34 | "depNameTemplate": "alpine_3_21/{{package}}" 35 | } 36 | ], 37 | "packageRules": [ 38 | { 39 | "matchDatasources": ["repology"], 40 | "automerge": true 41 | }, 42 | { 43 | "groupName": "Add-on base image", 44 | "matchDatasources": ["docker"] 45 | }, 46 | { 47 | "groupName": "Add-on base image", 48 | "matchDatasources": ["docker"], 49 | "matchUpdateTypes": ["minor", "patch"], 50 | "automerge": true 51 | } 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: CI 3 | 4 | # yamllint disable-line rule:truthy 5 | on: 6 | workflow_dispatch: 7 | 8 | jobs: 9 | workflows: 10 | uses: einschmidt/workflows/.github/workflows/addon-ci.yaml@main 11 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Deploy 3 | 4 | # yamllint disable-line rule:truthy 5 | on: 6 | release: 7 | types: 8 | - published 9 | workflow_run: 10 | workflows: ["CI"] 11 | branches: [main] 12 | types: 13 | - completed 14 | 15 | jobs: 16 | workflows: 17 | uses: einschmidt/workflows/.github/workflows/addon-deploy.yaml@main 18 | secrets: 19 | DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }} 20 | -------------------------------------------------------------------------------- /.github/workflows/labels.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Sync labels 3 | 4 | # yamllint disable-line rule:truthy 5 | on: 6 | schedule: 7 | - cron: "34 5 * * *" 8 | workflow_dispatch: 9 | 10 | jobs: 11 | workflows: 12 | uses: einschmidt/workflows/.github/workflows/labels.yaml@main 13 | -------------------------------------------------------------------------------- /.github/workflows/lock.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Lock 3 | 4 | # yamllint disable-line rule:truthy 5 | on: 6 | schedule: 7 | - cron: "38 2 * * *" 8 | workflow_dispatch: 9 | 10 | jobs: 11 | workflows: 12 | uses: einschmidt/workflows/.github/workflows/lock.yaml@main 13 | -------------------------------------------------------------------------------- /.github/workflows/pr-labels.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: PR Labels 3 | 4 | # yamllint disable-line rule:truthy 5 | on: 6 | pull_request_target: 7 | types: 8 | - opened 9 | - labeled 10 | - unlabeled 11 | - synchronize 12 | 13 | jobs: 14 | workflows: 15 | uses: einschmidt/workflows/.github/workflows/pr-labels.yaml@main 16 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Release Drafter 3 | 4 | # yamllint disable-line rule:truthy 5 | on: 6 | push: 7 | branches: 8 | - main 9 | 10 | jobs: 11 | workflows: 12 | uses: einschmidt/workflows/.github/workflows/release-drafter.yaml@main 13 | -------------------------------------------------------------------------------- /.github/workflows/stale.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Stale 3 | 4 | # yamllint disable-line rule:truthy 5 | on: 6 | schedule: 7 | - cron: "0 8 * * *" 8 | workflow_dispatch: 9 | 10 | jobs: 11 | workflows: 12 | uses: einschmidt/workflows/.github/workflows/stale.yaml@main 13 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | rules: 3 | braces: 4 | level: error 5 | min-spaces-inside: 0 6 | max-spaces-inside: 1 7 | min-spaces-inside-empty: -1 8 | max-spaces-inside-empty: -1 9 | brackets: 10 | level: error 11 | min-spaces-inside: 0 12 | max-spaces-inside: 0 13 | min-spaces-inside-empty: -1 14 | max-spaces-inside-empty: -1 15 | colons: 16 | level: error 17 | max-spaces-before: 0 18 | max-spaces-after: 1 19 | commas: 20 | level: error 21 | max-spaces-before: 0 22 | min-spaces-after: 1 23 | max-spaces-after: 1 24 | comments: 25 | level: error 26 | require-starting-space: true 27 | min-spaces-from-content: 2 28 | comments-indentation: 29 | level: error 30 | document-end: 31 | level: error 32 | present: false 33 | document-start: 34 | level: error 35 | present: true 36 | empty-lines: 37 | level: error 38 | max: 1 39 | max-start: 0 40 | max-end: 1 41 | hyphens: 42 | level: error 43 | max-spaces-after: 1 44 | indentation: 45 | level: error 46 | spaces: 2 47 | indent-sequences: true 48 | check-multi-line-strings: false 49 | key-duplicates: 50 | level: error 51 | line-length: 52 | level: warning 53 | max: 120 54 | allow-non-breakable-words: true 55 | allow-non-breakable-inline-mappings: true 56 | new-line-at-end-of-file: 57 | level: error 58 | new-lines: 59 | level: error 60 | type: unix 61 | trailing-spaces: 62 | level: error 63 | truthy: 64 | level: error 65 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 einschmidt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Home Assistant Add-on: Caddy 2 2 | 3 | Caddy 2 is a powerful, enterprise-grade, open-source web server with automatic HTTPS, designed for simplicity, security, and high performance. It is the go-to solution for handling everything from basic web hosting to complex reverse proxy setups in both personal and enterprise environments. 4 | 5 | ## About 6 | 7 | Caddy 2 simplifies and enhances your Home Assistant experience by automating much of the infrastructure management involved in running web services. With built-in HTTPS management, reverse proxy capabilities, and modular extensibility, Caddy can take care of many critical tasks. 8 | -------------------------------------------------------------------------------- /caddy-2/.README.j2: -------------------------------------------------------------------------------- 1 | # Home Assistant Add-on: Caddy 2 2 | 3 | Caddy 2 is a modern, powerful, enterprise-grade open-source web server designed for simplicity, security, and flexibility. 4 | It’s unique in its ability to automatically manage HTTPS by default, without any complex configuration. 5 | 6 | ## About 7 | 8 | Caddy 2 simplifies and enhances your Home Assistant experience by automating much of the infrastructure management involved in running web services. 9 | With built-in HTTPS management, reverse proxy capabilities, and modular extensibility, Caddy can take care of many critical tasks. 10 | 11 | {% if channel == "edge" %} 12 | ## WARNING! THIS IS AN EDGE VERSION! 13 | 14 | This Home Assistant Add-ons repository contains edge builds of add-ons. 15 | Edge builds add-ons are based upon the latest development version. 16 | 17 | - They may not work at all. 18 | - They might stop working at any time. 19 | - They could have a negative impact on your system. 20 | 21 | This repository was created for: 22 | 23 | - Anybody willing to test. 24 | - Anybody interested in trying out upcoming add-ons or add-on features. 25 | - Developers. 26 | 27 | If you are more interested in stable releases of our add-ons: 28 | 29 | 30 | 31 | {% endif %} 32 | {% if channel == "beta" %} 33 | ## WARNING! THIS IS A BETA VERSION! 34 | 35 | This Home Assistant Add-ons repository contains beta releases of add-ons. 36 | 37 | - They might stop working at any time. 38 | - They could have a negative impact on your system. 39 | 40 | This repository was created for: 41 | 42 | - Anybody willing to test. 43 | - Anybody interested in trying out upcoming add-ons or add-on features. 44 | 45 | If you are more interested in stable releases of our add-ons: 46 | 47 | 48 | 49 | {% endif %} 50 | -------------------------------------------------------------------------------- /caddy-2/DOCS.md: -------------------------------------------------------------------------------- 1 | # Home Assistant Add-on: Caddy 2 2 | 3 | Caddy 2 is a modern, powerful, enterprise-grade open-source web server designed for simplicity, security, and flexibility. 4 | It’s unique in its ability to automatically manage HTTPS by default, without any complex configuration. 5 | 6 | ## Table of Contents 7 | 8 | 1. [Add-on Installation](#add-on-installation) 9 | 2. [Basic Setup Examples](#basic-setup-examples) 10 | 3. [Configuration Options](#configuration-options) 11 | 4. [Advanced Usage: Custom Binaries & Plugins](#advanced-usage-custom-binaries--plugins) 12 | 13 | ## Add-on Installation 14 | 15 | To install the Caddy 2 add-on, first add the repository to your [Hass.io](https://home-assistant.io/hassio/) instance by entering the following URL: 16 | 17 | `https://github.com/einschmidt/hassio-addons` 18 | 19 | If you encounter any issues, refer to the [official documentation](https://home-assistant.io/hassio/installing_third_party_addons/) for guidance. 20 | 21 | Once the repository is added, search for and install the "Caddy 2" add-on. 22 | 23 | ## Basic Setup Examples 24 | 25 | The Caddy 2 add-on offers multiple setup methods to accommodate different environments and network configurations. These setups range from simple to more complex, allowing you to choose the level of customization that fits your needs. 26 | 27 | ### Default Proxy Server Setup (Simple) 28 | 29 | By default, Caddy 2 runs as a proxy server for Home Assistant without needing a `Caddyfile`. It uses the configuration provided in the add-on settings and automatically handles HTTPS for you. 30 | 31 | **Note**: If a `Caddyfile` is found in the configuration directory, the `non_caddyfile_config` settings will be ignored in favor of the Caddyfile. 32 | 33 | #### Example Configuration 34 | 35 | **Important**: _Always restart the add-on after making changes to the configuration._ 36 | 37 | For a basic proxy setup, forwarding `yourdomain.com` to Home Assistant, use the following example (without a `Caddyfile`): 38 | 39 | ```yaml 40 | non_caddyfile_config: 41 | email: your@email.com 42 | domain: yourdomain.com 43 | destination: localhost 44 | port: 8123 45 | log_level: info 46 | args: [] 47 | env_vars: [] 48 | ``` 49 | 50 | **Note**: _These examples are for guidance only. Customize them according to your needs._ 51 | 52 | ### Caddyfile Setup (Intermediate) 53 | 54 | For more advanced customization, you can create and use a Caddyfile to define your proxy server's configuration. This allows greater control over settings such as routing, headers, and SSL management. 55 | 56 | To use a Caddyfile, place the file in the add-on configuration directory. You can access this directory using either the [SSH][ssh] or [Samba][samba] add-ons. The add-on will only search for the Caddyfile in this specific location. 57 | 58 | #### Add-on Configuration Directory 59 | 60 | The Caddyfile needs to be placed in the add-on's configuration directory, which can be found at: 61 | 62 | ``` 63 | /addon_configs/c80c7555_caddy-2 64 | ``` 65 | 66 | ##### Accessing the Configuration Directory 67 | 68 | SSH: You can access the configuration directory via SSH by navigating to `/addon_configs/`. 69 | 70 | Samba: Alternatively, with the Samba add-on, you can access this folder from your network as a shared directory. Look for the `addon_configs` folder and locate the appropriate directory. 71 | 72 | #### Managing Certificates 73 | 74 | Caddy 2 can automatically generate SSL certificates. If you want to use certificates from other add-ons (such as the Let’s Encrypt add-on), they can be placed in the `/ssl` directory. The Caddy 2 add-on will have access to this folder, allowing you to use external certificates or create certificates for other services. 75 | 76 | #### Example Caddyfile 77 | 78 | A simple Caddyfile for proxying traffic to a Home Assistant installation might look like this: 79 | 80 | ``` 81 | { 82 | email your@email.com 83 | } 84 | 85 | yourdomain.com { 86 | reverse_proxy localhost:8123 87 | } 88 | ``` 89 | 90 | For more advanced configurations, refer to the [Caddyfile documentation](https://caddyserver.com/docs/caddyfile). 91 | 92 | #### Example Configuration for Caddyfile 93 | 94 | **Important**: _Restart the add-on after changing the configuration._ 95 | 96 | To instruct the add-on to use and monitor the `Caddyfile`, your configuration should look like this: 97 | 98 | ```yaml 99 | non_caddyfile_config: {} 100 | log_level: info 101 | args: 102 | - "--watch" 103 | env_vars: [] 104 | ``` 105 | 106 | **Note**: _Customize this example for your specific setup._ 107 | 108 | ### Custom Caddy Binary Setup (Advanced) 109 | 110 | For advanced users, you can replace the default Caddy binary with a custom one. Place your `caddy` binary in the [add-on configuration directory](#add-on-configuration-directory), using [SSH][ssh] or [Samba][samba]. The add-on will use binaries found in this folder. 111 | 112 | #### Example Configuration 113 | 114 | **Important**: _Restart the add-on after any configuration changes._ 115 | 116 | Here’s an example configuration using a custom Caddy binary and a `Caddyfile`, with automatic updates and formatting enabled: 117 | 118 | ```yaml 119 | non_caddyfile_config: {} 120 | log_level: info 121 | args: 122 | - "--watch" 123 | env_vars: [] 124 | caddy_upgrade: true 125 | caddy_fmt: true 126 | ``` 127 | 128 | **Note**: _These examples are meant for reference. Adjust them to match your setup._ 129 | 130 | ## Configuration Options 131 | 132 | ### Option: `non_caddyfile_config.email` 133 | 134 | Defines the email address used when creating an ACME account with your Certificate Authority (CA). This is recommended to help manage certificates in case of issues. 135 | 136 | **Note**: This option is only used for the default reverse proxy setup. It will be ignored once a `Caddyfile` is found in the configuration directory. 137 | 138 | ### Option: `non_caddyfile_config.domain` 139 | 140 | Specifies the domain name for your setup. 141 | 142 | **Note**: This option is only applicable to the default reverse proxy setup and will be ignored if a `Caddyfile` is present in the configuration directory. 143 | 144 | ### Option: `non_caddyfile_config.destination` 145 | 146 | Sets the upstream address for the reverse proxy. Typically, `localhost` is sufficient for most setups. To target specific addresses, you can use `127.0.0.1` for IPv4 or `::1` for IPv6. 147 | 148 | **Note**: This option is only used for the default reverse proxy setup and is ignored if a `Caddyfile` is found in the configuration directory. 149 | 150 | ### Option: `non_caddyfile_config.port` 151 | 152 | Defines the port for the upstream address. For example, Home Assistant typically uses port `8123`. 153 | 154 | **Note**: This setting is only applied in the default reverse proxy configuration. It is ignored if a `Caddyfile` is present in the configuration directory. 155 | 156 | ### Option: `caddy_upgrade` 157 | 158 | Enables automatic upgrades for custom Caddy binaries and their plugins. Set this option to `true` to allow updates, or `false` to disable it. The default is `false`. 159 | 160 | **Note**: This feature only applies to custom binaries (Caddy version 2.4 or higher) and is not needed if using the default Caddy binary. 161 | 162 | ### Option: `caddy_fmt` 163 | 164 | Enables automatic formatting and prettifying of the `Caddyfile`. Set this option to `true` to enable formatting or `false` to disable it. By default, it is disabled. 165 | 166 | **Note**: This feature requires a valid `Caddyfile` to work. 167 | 168 | ### Option: `args` 169 | 170 | Allows you to specify additional command-line arguments for Caddy 2. Add one or more arguments to the list, and they will be executed each time the add-on starts. 171 | 172 | **Note**: The `--config` argument is automatically added. For more information, refer to the official [Caddy documentation](https://caddyserver.com/docs/command-line#caddy-run). 173 | 174 | ### Option: `env_vars` 175 | 176 | Allows you to define multiple environment variables, usually used for custom Caddy binary builds. These variables can be set in the following format: 177 | 178 | Example: 179 | 180 | ```yaml 181 | env_vars: 182 | - name: NAMECHEAP_API_USER 183 | value: xxxx 184 | - name: NAMECHEAP_API_KEY 185 | value: xxxx 186 | ``` 187 | 188 | ### Option: `env_vars.name` 189 | 190 | Specifies the name of the environment variable. 191 | 192 | ### Option: `env_vars.value` 193 | 194 | Specifies the value assigned to the environment variable. 195 | 196 | ### Option: `log_level` 197 | 198 | Controls the verbosity of the log output from the add-on. This setting is useful for debugging or monitoring the add-on’s behavior. Available log levels are: 199 | 200 | - `trace`: Shows detailed information, including all internal function calls. 201 | - `debug`: Provides extensive debugging information. 202 | - `info`: Shows typical events and information. 203 | - `warning`: Logs unexpected situations that are not errors. 204 | - `error`: Records runtime errors that don’t need immediate action. 205 | - `fatal`: Critical errors that make the add-on unusable. 206 | 207 | Each level includes the messages from more severe levels. For example, `debug` also includes `info` messages. The default setting is `info`, which is recommended unless troubleshooting. 208 | 209 | ## Advanced Usage: Custom Binaries & Plugins 210 | 211 | ### Overview 212 | 213 | This add-on uses a single binary file to launch Caddy, which makes it highly customizable. You can run a custom build of Caddy with any version and plugins you need, providing maximum flexibility for advanced users. 214 | 215 | ### Custom Caddy Binaries 216 | 217 | To build your own version of Caddy, including specific plugins or features, you can follow the instructions provided in the official Caddy documentation using the [`xcaddy` tool](https://caddyserver.com/docs/build#xcaddy). This allows you to compile your own version of Caddy with custom modules or plugins that are not included in the default binary. 218 | 219 | ### Installing a Custom Binary 220 | 221 | To use a custom-built Caddy binary, follow these steps: 222 | 223 | 1. Build your custom Caddy binary using `xcaddy` or obtain a pre-built version that suits your needs. 224 | 2. Place the `caddy` binary file into the add-on configuration folder. 225 | 3. Restart the Caddy 2 add-on to begin using your custom version of Caddy. 226 | 227 | #### Accessing the Configuration Folder 228 | 229 | The add-on configuration folder can be found at: 230 | 231 | ``` 232 | /addon_configs/c80c7555_caddy-2 233 | ``` 234 | 235 | This is where you should place your custom `caddy` binary and any related configuration files. 236 | 237 | Once the add-on is restarted, Caddy will use the custom binary you've provided, allowing you to leverage any additional features or plugins included in your custom build. 238 | 239 | [ssh]: https://home-assistant.io/addons/ssh/ 240 | [samba]: https://home-assistant.io/addons/samba/ 241 | -------------------------------------------------------------------------------- /caddy-2/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG BUILD_FROM 2 | # hadolint ignore=DL3006 3 | FROM $BUILD_FROM 4 | 5 | # Use bash as the default shell 6 | SHELL ["/bin/bash", "-c"] 7 | 8 | RUN \ 9 | set -eux \ 10 | \ 11 | && mkdir -p \ 12 | /data/caddy \ 13 | \ 14 | && apk add --no-cache \ 15 | nss-tools=3.109-r0 16 | 17 | # https://github.com/caddyserver/caddy/releases 18 | ENV CADDY_VERSION="v2.10.0" 19 | 20 | # Install Caddy 21 | ARG BUILD_ARCH=amd64 22 | RUN \ 23 | set -eux \ 24 | \ 25 | && BINARCH="${BUILD_ARCH}" \ 26 | && if [ "${BUILD_ARCH}" = "armhf" ]; then BINARCH="armv6"; fi \ 27 | && if [ "${BUILD_ARCH}" = "armv7" ]; then BINARCH="armv7"; fi \ 28 | && if [ "${BUILD_ARCH}" = "aarch64" ]; then BINARCH="arm64"; fi \ 29 | \ 30 | && curl -J -L -o /tmp/caddy.tar.gz "https://github.com/caddyserver/caddy/releases/download/${CADDY_VERSION}/caddy_${CADDY_VERSION//v/}_linux_${BINARCH}.tar.gz" \ 31 | && tar zxvf /tmp/caddy.tar.gz -C /usr/bin caddy \ 32 | && chmod +x /usr/bin/caddy \ 33 | && rm -rf /tmp/caddy \ 34 | && caddy version 35 | 36 | # Copy root filesystem 37 | COPY rootfs / 38 | 39 | # ensure that nsswitch.conf is set up for Go's "netgo" implementation 40 | # - https://github.com/golang/go/blob/go1.19.3/src/net/conf.go#L227-L303 41 | # - docker run --rm debian grep '^hosts:' /etc/nsswitch.conf 42 | # Alpine 3.16 includes nsswitch.conf 43 | RUN set -eux \ 44 | \ 45 | && if [ -e /etc/nsswitch.conf ]; then \ 46 | grep '^hosts: files dns' /etc/nsswitch.conf; \ 47 | else \ 48 | echo 'hosts: files dns' > /etc/nsswitch.conf; \ 49 | fi 50 | 51 | ENV XDG_CONFIG_HOME=/data 52 | ENV XDG_DATA_HOME=/ssl 53 | 54 | # Build arguments 55 | ARG BUILD_ARCH 56 | ARG BUILD_DATE 57 | ARG BUILD_DESCRIPTION 58 | ARG BUILD_NAME 59 | ARG BUILD_REF 60 | ARG BUILD_REPOSITORY 61 | ARG BUILD_VERSION 62 | 63 | # Labels 64 | LABEL \ 65 | io.hass.name="${BUILD_NAME}" \ 66 | io.hass.description="${BUILD_DESCRIPTION}" \ 67 | io.hass.arch="${BUILD_ARCH}" \ 68 | io.hass.type="addon" \ 69 | io.hass.version=${BUILD_VERSION} \ 70 | maintainer="Einschmidt" \ 71 | org.opencontainers.image.title="${BUILD_NAME}" \ 72 | org.opencontainers.image.description="${BUILD_DESCRIPTION}" \ 73 | org.opencontainers.image.vendor="Einschmidt" \ 74 | org.opencontainers.image.authors="einschmidt" \ 75 | org.opencontainers.image.licenses="MIT" \ 76 | org.opencontainers.image.url="https://google.com" \ 77 | org.opencontainers.image.source="https://github.com/${BUILD_REPOSITORY}" \ 78 | org.opencontainers.image.documentation="https://github.com/${BUILD_REPOSITORY}/blob/main/README.md" \ 79 | org.opencontainers.image.created=${BUILD_DATE} \ 80 | org.opencontainers.image.revision=${BUILD_REF} \ 81 | org.opencontainers.image.version=${BUILD_VERSION} 82 | -------------------------------------------------------------------------------- /caddy-2/build.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | build_from: 3 | aarch64: "ghcr.io/hassio-addons/base:17.2.5" 4 | amd64: "ghcr.io/hassio-addons/base:17.2.5" 5 | armhf: "ghcr.io/hassio-addons/base:17.2.5" 6 | armv7: "ghcr.io/hassio-addons/base:17.2.5" 7 | -------------------------------------------------------------------------------- /caddy-2/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Caddy 2 3 | version: dev 4 | slug: caddy-2 5 | description: Open source web and proxy server with automatic HTTPS 6 | url: "https://github.com/einschmidt/addon-caddy-2" 7 | arch: 8 | - armhf 9 | - armv7 10 | - amd64 11 | - aarch64 12 | startup: services 13 | map: 14 | - type: share 15 | read_only: false 16 | - type: addon_config 17 | read_only: false 18 | - type: ssl 19 | read_only: false 20 | host_network: true 21 | options: 22 | non_caddyfile_config: 23 | email: your@email.com 24 | domain: mydomain.com 25 | destination: localhost 26 | port: 8123 27 | args: [] 28 | env_vars: [] 29 | log_level: info 30 | schema: 31 | non_caddyfile_config: 32 | email: email? 33 | domain: str? 34 | destination: str? 35 | port: port? 36 | caddy_upgrade: bool? 37 | caddy_fmt: bool? 38 | args: 39 | - str 40 | env_vars: 41 | - name: str 42 | value: str 43 | log_level: list(trace|debug|info|notice|warning|error|fatal) 44 | environment: 45 | LOG_FORMAT: "{LEVEL}: {MESSAGE}" 46 | init: false 47 | breaking_versions: 48 | - 2.0.0 49 | -------------------------------------------------------------------------------- /caddy-2/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/einschmidt/addon-caddy-2/ad3902a81350cfa4ccf6b7a2e6af7aaca4e6a4d8/caddy-2/icon.png -------------------------------------------------------------------------------- /caddy-2/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/einschmidt/addon-caddy-2/ad3902a81350cfa4ccf6b7a2e6af7aaca4e6a4d8/caddy-2/logo.png -------------------------------------------------------------------------------- /caddy-2/rootfs/etc/caddy/Caddyfile: -------------------------------------------------------------------------------- 1 | { 2 | email {$EMAIL} 3 | } 4 | 5 | {$DOMAIN} { 6 | reverse_proxy {$DESTINATION}:{$PORT} 7 | } -------------------------------------------------------------------------------- /caddy-2/rootfs/etc/s6-overlay/s6-rc.d/caddy/dependencies.d/base: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/einschmidt/addon-caddy-2/ad3902a81350cfa4ccf6b7a2e6af7aaca4e6a4d8/caddy-2/rootfs/etc/s6-overlay/s6-rc.d/caddy/dependencies.d/base -------------------------------------------------------------------------------- /caddy-2/rootfs/etc/s6-overlay/s6-rc.d/caddy/finish: -------------------------------------------------------------------------------- 1 | #!/command/with-contenv bashio 2 | # shellcheck shell=bash 3 | # ============================================================================== 4 | # Home Assistant Add-on: Caddy 2 5 | # ============================================================================== 6 | declare exit_code 7 | readonly exit_code_container=$( /run/s6-linux-init-container-results/exitcode 23 | fi 24 | 25 | # If the signal is SIGTERM, we should halt the container and take down 26 | # the whole process tree. 27 | [[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt 28 | 29 | # The service exited with a non-zero exit code, which means it crashed. 30 | elif [[ "${exit_code_service}" -ne 0 ]]; then 31 | 32 | # The service might be a result of another service crashing. Only 33 | # overwrite the container exit code if it is not already set. 34 | if [[ "${exit_code_container}" -eq 0 ]]; then 35 | echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode 36 | fi 37 | 38 | # We should halt the container and take down the whole process tree. 39 | exec /run/s6/basedir/bin/halt 40 | 41 | # The service exited with a zero exit code, which means it exited, let 42 | # S6 supervision restart it. 43 | else 44 | bashio::log.info "Service ${service} restarting..." 45 | fi -------------------------------------------------------------------------------- /caddy-2/rootfs/etc/s6-overlay/s6-rc.d/caddy/run: -------------------------------------------------------------------------------- 1 | #!/command/with-contenv bashio 2 | # shellcheck shell=bash 3 | # ============================================================================== 4 | # Home Assistant Add-on: Caddy 2 5 | # Runs Caddy 6 | # ============================================================================== 7 | 8 | # Run Add-on 9 | exec /usr/bin/caddy.sh 10 | -------------------------------------------------------------------------------- /caddy-2/rootfs/etc/s6-overlay/s6-rc.d/caddy/type: -------------------------------------------------------------------------------- 1 | longrun -------------------------------------------------------------------------------- /caddy-2/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/caddy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/einschmidt/addon-caddy-2/ad3902a81350cfa4ccf6b7a2e6af7aaca4e6a4d8/caddy-2/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/caddy -------------------------------------------------------------------------------- /caddy-2/rootfs/usr/bin/caddy.sh: -------------------------------------------------------------------------------- 1 | #!/command/with-contenv bashio 2 | # shellcheck shell=bash 3 | # ============================================================================== 4 | # Home Assistant Add-on: Caddy 2 5 | # 6 | # Launch Caddy 7 | # ------------------------------------------------------------------------------ 8 | 9 | 10 | # Prepare Caddy function to set custom Caddy path and check for custom Caddy 11 | # binary at the specified path. If found, exports custom Caddy variables; 12 | # otherwise, uses the built-in Caddy binary path. 13 | # Finally, checks the Caddy version. 14 | prepare_caddy() { 15 | bashio::log.info 'Prepare Caddy...' 16 | 17 | # Set custom Caddy path 18 | CUSTOM_CADDY_PATH="/config/caddy" 19 | 20 | # Check for custom Caddy binary at custom Caddy path 21 | bashio::log.info "Checking path: ${CUSTOM_CADDY_PATH}" 22 | if bashio::fs.file_exists "${CUSTOM_CADDY_PATH}"; then 23 | bashio::log.info "Found custom Caddy binary at ${CUSTOM_CADDY_PATH}" 24 | export CUSTOM_CADDY=true 25 | export CADDY_PATH="${CUSTOM_CADDY_PATH}" 26 | else 27 | bashio::log.info "Use built-in Caddy" 28 | export CUSTOM_CADDY=false 29 | export CADDY_PATH="/usr/bin/caddy" 30 | fi 31 | 32 | # Check caddy version 33 | "${CADDY_PATH}" version 34 | } 35 | 36 | # Upgrade Caddy function to upgrade Caddy to the latest version 37 | caddy_upgrade() { 38 | bashio::log.info 'Upgrade Caddy...' 39 | 40 | if ! ${CUSTOM_CADDY}; then 41 | bashio::log.info "Cannot upgrade Caddy as no custom binary has been found" 42 | return 0 43 | elif [ "$(${CADDY_PATH} version | awk '{print $1}')" == "$(curl -sL https://api.github.com/repos/caddyserver/caddy/releases/latest | jq -r '.tag_name')" ]; then 44 | bashio::log.info "Custom Caddy uses the latest version" 45 | return 0 46 | else 47 | bashio::log.info "Initiate upgrade" 48 | "${CADDY_PATH}" upgrade 49 | fi 50 | } 51 | 52 | prepare_caddyfile() { 53 | bashio::log.info 'Prepare Caddyfile...' 54 | 55 | # Set custom Caddyfile path 56 | CUSTOM_CADDYFILE_PATH="/config/Caddyfile" 57 | 58 | # Check for existing Caddyfile 59 | if bashio::fs.file_exists "${CUSTOM_CADDYFILE_PATH}"; then 60 | bashio::log.info "Caddyfile found at ${CUSTOM_CADDYFILE_PATH}" 61 | export CONFIG_PATH=${CUSTOM_CADDYFILE_PATH} 62 | export CADDYFILE=true 63 | else 64 | bashio::log.info "No Caddyfile found" 65 | bashio::log.info "Use non_caddyfile_config" 66 | export CONFIG_PATH=/etc/caddy/Caddyfile 67 | export CADDYFILE=false 68 | 69 | non_caddyfile_config 70 | fi 71 | } 72 | 73 | non_caddyfile_config() { 74 | bashio::log.trace "${FUNCNAME[0]}" 75 | 76 | EMAIL=$(bashio::config 'non_caddyfile_config.email') 77 | DOMAIN=$(bashio::config 'non_caddyfile_config.domain') 78 | DESTINATION=$(bashio::config 'non_caddyfile_config.destination') 79 | PORT=$(bashio::config 'non_caddyfile_config.port') 80 | 81 | export EMAIL 82 | export DOMAIN 83 | export DESTINATION 84 | export PORT 85 | } 86 | 87 | caddy_fmt() { 88 | bashio::log.info 'Format Caddyfile...' 89 | 90 | if ! ${CADDYFILE}; then 91 | bashio::log.info "No Caddyfile found" 92 | return 0 93 | fi 94 | 95 | if [ -w ${CONFIG_PATH} ]; then 96 | bashio::log.info "Overwrite Caddyfile" 97 | "${CADDY_PATH}" fmt --overwrite ${CONFIG_PATH} 98 | else 99 | bashio::log.info "Caddyfile has been found but is not writable" 100 | fi 101 | } 102 | 103 | main() { 104 | bashio::log.trace "${FUNCNAME[0]}" 105 | 106 | declare name 107 | declare value 108 | declare -a args=() 109 | 110 | # Load command line arguments 111 | for arg in $(bashio::config 'args|keys'); do 112 | # shellcheck disable=SC2207 113 | args+=( $(bashio::config "args[${arg}]") ) 114 | done 115 | 116 | # Load custom environment variables 117 | for var in $(bashio::config 'env_vars|keys'); do 118 | name=$(bashio::config "env_vars[${var}].name") 119 | value=$(bashio::config "env_vars[${var}].value") 120 | bashio::log.info "Setting ${name} to ${value}" 121 | export "${name}=${value}" 122 | done 123 | 124 | # Format Caddyfile 125 | # bashio::log.info "Format Caddyfile" 126 | # "${CADDY_PATH}" fmt "${CONFIG_PATH}" 127 | 128 | # Prepare Caddy 129 | prepare_caddy 130 | 131 | # Upgrade Caddy 132 | if bashio::config.true 'caddy_upgrade'; then 133 | caddy_upgrade 134 | fi 135 | 136 | # Prepare Caddyfile 137 | prepare_caddyfile 138 | 139 | # Format Caddyfile 140 | if bashio::config.true 'caddy_fmt'; then 141 | caddy_fmt 142 | fi 143 | 144 | # Run Caddy 145 | bashio::log.info "Run Caddy..." 146 | bashio::log.debug "'${CADDY_PATH}' run --config '${CONFIG_PATH}' '${args[*]}'" 147 | "${CADDY_PATH}" run --config "${CONFIG_PATH}" "${args[@]}" 148 | } 149 | main "$@" 150 | --------------------------------------------------------------------------------