This repository contains a Makefile that automates the process of building, testing, installing, and restoring the Caddy server with custom plugins. It simplifies the steps needed to manage your Caddy installation, ensuring that the configuration is valid before making any live changes.
- Custom Plugin Management: Easily add or remove plugins for the Caddy build by modifying a single variable.
- Automated Testing: The
Makefilevalidates the Caddy configuration before installation, ensuring no downtime due to configuration issues. - Backup and Restore: The
Makefileautomatically backs up the existing Caddy binary before installing a new version and provides a restore option in case of issues. - Flexibility: You can override the default configuration file and plugin list using environment variables or command-line arguments.
This project builds on Caddy, a powerful, extensible, and easy-to-use web server written in Go.
- xcaddy: Used to build the Caddy server with custom plugins. Follow the installation instructions for
xcaddyin the official xcaddy GitHub repository.
You can download the Makefile using curl or wget:
# Using curl
curl -O https://raw.githubusercontent.com/Hansen333/caddy-automate/refs/heads/main/Makefile# Using wget
wget https://raw.githubusercontent.com/Hansen333/caddy-automate/refs/heads/main/Makefile| Target | Description |
|---|---|
help |
Displays usage instructions and available targets. |
build |
Builds the Caddy binary with the specified plugins. You can customize the plugin list using PLUGINS. |
test |
Tests the newly built Caddy binary against the current configuration to ensure validity. |
install |
Installs the new Caddy binary after backing up the old one. |
restore |
Restores a previously backed-up Caddy binary and restarts the service. Requires a file parameter. |
restart |
Restarts the Caddy service. |
clean |
Cleans up build artifacts and backups. |
-
PLUGINS: Custom plugins to include in the Caddy build. Defaults to:
--with github.com/caddy-dns/cloudflare --with github.com/caddy-dns/route53 --with github.com/caddyserver/replace-response
Example:
make build PLUGINS="--with github.com/caddyserver/replace-response" -
CONFIG: Path to the Caddy configuration file. Defaults to
/etc/caddy/Caddyfile.Example:
make install CONFIG=/etc/caddy/other-caddyfile
-
Build Caddy with Custom Plugins:
make build PLUGINS="--with github.com/caddyserver/replace-response" -
Install Caddy Using a Different Configuration File:
make install CONFIG=/etc/caddy/other-caddyfile
-
Restore a Previous Caddy Binary: If you need to restore a previous version of the Caddy binary, you can use the
restoretarget:make restore file=./caddy_20241015_190900
-
Clean Up Artifacts: To remove build artifacts and backup files, run:
make clean
-
Building Caddy: The
buildtarget compiles the Caddy binary using the specified plugins, which you can modify via thePLUGINSvariable. -
Testing: The
testtarget ensures that the new Caddy binary is compatible with the current configuration file before installation. If the configuration is invalid, the build process will stop. -
Installing: The
installtarget backs up the existing Caddy binary before installing the new version. The backup is stored with a timestamp, allowing for easy restoration. -
Restoring: The
restoretarget lets you revert to a previous version of Caddy by specifying the backup file. -
Restarting: The
restarttarget restarts the Caddy service to apply changes or for troubleshooting. -
make all: Thealltarget runs the entire process in sequence:- Build: It compiles the Caddy binary with the specified plugins.
- Test: It validates the new binary against the current configuration to ensure it’s functional.
- Install: If the test passes, the new binary is installed, and the old one is backed up.
- Restart: Finally, the Caddy service is restarted to apply the changes.
make allensures that every step is performed in order and no installation happens if the configuration test fails.
This project is built upon the Caddy Web Server and makes use of the xcaddy tool for building custom versions of Caddy with plugins.
Caddy is a powerful, extensible, and easy-to-use web server written in Go. For more information about Caddy, check out the official Caddy repository.
This repository is licensed under the MIT License. See the LICENSE file for more information.