5
5
"errors"
6
6
"fmt"
7
7
"maps"
8
+ "os"
8
9
"slices"
9
10
"strings"
10
11
@@ -18,9 +19,10 @@ import (
18
19
)
19
20
20
21
type deployOptions struct {
21
- image string
22
- machines []string
23
- context string
22
+ caddyfile string
23
+ image string
24
+ machines []string
25
+ context string
24
26
}
25
27
26
28
func NewDeployCommand () * cobra.Command {
@@ -37,6 +39,8 @@ func NewDeployCommand() *cobra.Command {
37
39
},
38
40
}
39
41
42
+ cmd .Flags ().StringVar (& opts .caddyfile , "caddyfile" , "" ,
43
+ "Path to a custom global Caddy config (Caddyfile) that will be prepended to the auto-generated Caddy config." )
40
44
cmd .Flags ().StringVar (& opts .image , "image" , "" ,
41
45
"Caddy Docker image to deploy. (default caddy:LATEST_VERSION)" )
42
46
cmd .Flags ().StringSliceVarP (& opts .machines , "machine" , "m" , nil ,
@@ -51,6 +55,15 @@ func NewDeployCommand() *cobra.Command {
51
55
}
52
56
53
57
func runDeploy (ctx context.Context , uncli * cli.CLI , opts deployOptions ) error {
58
+ caddyfile := ""
59
+ if opts .caddyfile != "" {
60
+ data , err := os .ReadFile (opts .caddyfile )
61
+ if err != nil {
62
+ return fmt .Errorf ("read Caddyfile: %w" , err )
63
+ }
64
+ caddyfile = strings .TrimSpace (string (data ))
65
+ }
66
+
54
67
clusterClient , err := uncli .ConnectCluster (ctx , opts .context )
55
68
if err != nil {
56
69
return fmt .Errorf ("connect to cluster: %w" , err )
@@ -91,7 +104,7 @@ func runDeploy(ctx context.Context, uncli *cli.CLI, opts deployOptions) error {
91
104
placement := api.Placement {
92
105
Machines : cli .ExpandCommaSeparatedValues (opts .machines ),
93
106
}
94
- d , err := clusterClient .NewCaddyDeployment (opts .image , "" , placement )
107
+ d , err := clusterClient .NewCaddyDeployment (opts .image , caddyfile , placement )
95
108
if err != nil {
96
109
return fmt .Errorf ("create caddy deployment: %w" , err )
97
110
}
0 commit comments