Skip to content

Commit 5701f0f

Browse files
authored
Change caddy to run on non privileged ports (#1106)
## Summary Change caddy to run on non privileged ports. I added the following script to the caddy example: - devbox run start Since I have a global caddy running on port `2019` for the admin endpoint already, I need to run this caddy under a separate admin port. ## Issue I still need help with (resolved. See commit "fix process compose") Running `devbox services up` has the following error ``` [caddy_1 ] Error: loading initial config: loading new config: starting caddy administration endpoint: listen tcp 127.0.0.1:2019: bind: address already in use ``` Where as `devbox run start` is successful 🤷‍♀️ Are we doing something special with process compose? Seems like for some reason, it is loading some initial config, then reload it with the new config. And because the initial config has a port conflict, everything fails. To reproduce, go to [https://devbox.sh/github.com/jetpack-io/devbox?folder=examples/servers/caddy&branch=lucille--caddy-on-vm](https://devbox.sh/github.com/jetpack-io/devbox?folder=examples/servers/caddy&branch=lucille--caddy-on-vm) ## How was it tested? devbox.sh
1 parent 4ce9fce commit 5701f0f

File tree

7 files changed

+36
-19
lines changed

7 files changed

+36
-19
lines changed

examples/servers/caddy/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
You can customize the config used by the caddy service by modifying the Caddyfile in devbox.d/caddy, or by changing the CADDY_CONFIG environment variable to point to a custom config. The custom config must be either JSON or Caddyfile format.
66

7-
After starting the service, you can test this example using `curl https://localhost:2020`
7+
After starting the service, you can test this example using `curl http://localhost:8082`
88

99
## Services
1010

1111
* caddy
1212

13-
Use `devbox services start|stop [service]` to interact with services
13+
Use `devbox run start` to start the caddy server.
14+
You can also use `devbox services start|stop [service]` to interact with services.
1415

1516
## This plugin creates the following helper files
1617

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# See https://caddyserver.com/docs/caddyfile for more details
2+
{
3+
admin 0.0.0.0:2020
4+
auto_https disable_certs
5+
http_port 8800
6+
https_port 4443
7+
}
28

3-
localhost:2020 {
4-
root * {$CADDY_ROOT_DIR}
5-
log {
6-
output file {$CADDY_LOG_DIR}/caddy.log
7-
}
8-
file_server
9-
}
9+
:8082 {
10+
root * {$CADDY_ROOT_DIR}
11+
log {
12+
output file {$CADDY_LOG_DIR}/caddy.log
13+
}
14+
file_server
15+
}

examples/servers/caddy/devbox.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"caddy@latest"
44
],
55
"shell": {
6-
"init_hook": null
6+
"init_hook": null,
7+
"scripts": {
8+
"start": "caddy run --config=devbox.d/caddy/Caddyfile"
9+
}
710
}
811
}

examples/servers/caddy/devbox.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"packages": {
44
"caddy@latest": {
55
"last_modified": "2023-05-01T16:53:22Z",
6+
"plugin_version": "0.0.2",
67
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#caddy",
78
"version": "2.6.4"
89
}

plugins/caddy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "caddy",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"readme": "You can customize the config used by the caddy service by modifying the Caddyfile in devbox.d/caddy, or by changing the CADDY_CONFIG environment variable to point to a custom config. The custom config must be either JSON or Caddyfile format.",
55
"env": {
66
"CADDY_CONFIG": "{{ .DevboxDir }}/Caddyfile",

plugins/caddy/Caddyfile

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# See https://caddyserver.com/docs/caddyfile for more details
2+
{
3+
admin 0.0.0.0:2020
4+
auto_https disable_certs
5+
http_port 8800
6+
https_port 4443
7+
}
28

3-
localhost:2020 {
4-
root * {$CADDY_ROOT_DIR}
5-
log {
6-
output file {$CADDY_LOG_DIR}/caddy.log
7-
}
8-
file_server
9-
}
9+
:8082 {
10+
root * {$CADDY_ROOT_DIR}
11+
log {
12+
output file {$CADDY_LOG_DIR}/caddy.log
13+
}
14+
file_server
15+
}

plugins/caddy/process-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: "0.6"
22

33
processes:
44
caddy:
5-
command: "caddy run --config=$CADDY_CONF"
5+
command: "caddy run --config=$CADDY_CONFIG"
66
availability:
77
restart: on_failure
88
max_restarts: 5

0 commit comments

Comments
 (0)