Bug 270120 - www/caddy: support JSON config files
Summary: www/caddy: support JSON config files
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Adam Weinberger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-11 18:50 UTC by Paweł Krawczyk
Modified: 2023-03-11 20:02 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (adamw)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paweł Krawczyk 2023-03-11 18:50:07 UTC
Caddy v2 native configuration format is plain JSON, which is not supported by the current logic in /usr/local/etc/rc.d/caddy which always sets the --adapter flag. With this patch, when caddy_adapter="json", Caddy will start with the config file path but without --adapter, which will imply the JSON format:

diff --git a/www/caddy/files/caddy.in b/www/caddy/files/caddy.in
index 85251ab1c..4314db8d1 100644
--- a/www/caddy/files/caddy.in
+++ b/www/caddy/files/caddy.in
@@ -54,7 +54,11 @@ load_rc_config $name
 export XDG_CONFIG_HOME XDG_DATA_HOME
 
 command="${caddy_command}"
-caddy_flags="--config ${caddy_config} --adapter ${caddy_adapter}"
+if [ "${caddy_adapter}" = "json" ]; then
+        caddy_flags="--config ${caddy_config}"
+else
+        caddy_flags="--config ${caddy_config} --adapter ${caddy_adapter}"  
+fi
 pidfile="/var/run/${name}/${name}.pid"
 
 required_files="${caddy_config} ${caddy_command}"
Comment 1 Adam Weinberger freebsd_committer freebsd_triage 2023-03-11 19:41:18 UTC
I had always assumed that caddy would have `--adapter json` for that. I had no idea that wasn't a thing!

This patch seems like a great idea.
Comment 2 commit-hook freebsd_committer freebsd_triage 2023-03-11 20:00:26 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=b45468408f73857aa7a0f4e62ee852baebb52bfa

commit b45468408f73857aa7a0f4e62ee852baebb52bfa
Author:     Pawel Krawczyk <pawel.krawczyk@hush.com>
AuthorDate: 2023-03-11 19:57:30 +0000
Commit:     Adam Weinberger <adamw@FreeBSD.org>
CommitDate: 2023-03-11 19:59:20 +0000

    www/caddy{,-custom}: Fix startup with JSON configuration

    Caddy supports a wide number of configuration file formats, including
    its built-in "Caddyfile" format, and the "native" format is JSON.

    When anything other than the native JSON format is used, caddy needs to
    be passed the --adapter [formatname] flag (though it automatically
    handles the case where the config filename is Caddyfile). However, as
    JSON is the native format, there is no "json" adapter.

    The added patch drops the --adapter flag when caddy_adapter is "json".

    PR:             270120

 www/caddy-custom/Makefile       | 2 +-
 www/caddy-custom/files/caddy.in | 8 +++++++-
 www/caddy/Makefile              | 2 +-
 www/caddy/files/caddy.in        | 8 +++++++-
 4 files changed, 16 insertions(+), 4 deletions(-)
Comment 3 Adam Weinberger freebsd_committer freebsd_triage 2023-03-11 20:02:41 UTC
Committed. Thanks!