summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ship/deploy_impl_v2.go78
1 files changed, 43 insertions, 35 deletions
diff --git a/cmd/ship/deploy_impl_v2.go b/cmd/ship/deploy_impl_v2.go
index 9ff674e..5b68dc3 100644
--- a/cmd/ship/deploy_impl_v2.go
+++ b/cmd/ship/deploy_impl_v2.go
@@ -46,20 +46,22 @@ func deployStaticV2(ctx *deployContext) *output.ErrorResponse {
46 // Non-fatal, continue 46 // Non-fatal, continue
47 } 47 }
48 48
49 // Generate Caddyfile 49 // Generate Caddyfile only if it doesn't exist (preserve manual edits)
50 caddyfile, err := templates.StaticCaddy(map[string]string{
51 "Domain": ctx.URL[8:], // Strip https://
52 "RootDir": remotePath,
53 "Name": name,
54 })
55 if err != nil {
56 return output.Err(output.ErrCaddyFailed, "failed to generate Caddyfile: "+err.Error())
57 }
58
59 // Upload Caddyfile
60 caddyPath := fmt.Sprintf("/etc/caddy/sites-enabled/%s.caddy", name) 50 caddyPath := fmt.Sprintf("/etc/caddy/sites-enabled/%s.caddy", name)
61 if err := client.WriteSudoFile(caddyPath, caddyfile); err != nil { 51 caddyExists, _ := client.Run(fmt.Sprintf("test -f %s && echo exists", caddyPath))
62 return output.Err(output.ErrCaddyFailed, "failed to write Caddyfile: "+err.Error()) 52 if strings.TrimSpace(caddyExists) != "exists" {
53 caddyfile, err := templates.StaticCaddy(map[string]string{
54 "Domain": ctx.URL[8:], // Strip https://
55 "RootDir": remotePath,
56 "Name": name,
57 })
58 if err != nil {
59 return output.Err(output.ErrCaddyFailed, "failed to generate Caddyfile: "+err.Error())
60 }
61
62 if err := client.WriteSudoFile(caddyPath, caddyfile); err != nil {
63 return output.Err(output.ErrCaddyFailed, "failed to write Caddyfile: "+err.Error())
64 }
63 } 65 }
64 66
65 // Reload Caddy 67 // Reload Caddy
@@ -150,18 +152,21 @@ func deployDockerV2(ctx *deployContext) *output.ErrorResponse {
150 return output.Err(output.ErrServiceFailed, "failed to write systemd unit: "+err.Error()) 152 return output.Err(output.ErrServiceFailed, "failed to write systemd unit: "+err.Error())
151 } 153 }
152 154
153 // Generate Caddyfile 155 // Generate Caddyfile only if it doesn't exist (preserve manual edits)
154 caddyfile, err := templates.AppCaddy(map[string]string{
155 "Domain": ctx.URL[8:], // Strip https://
156 "Port": strconv.Itoa(port),
157 })
158 if err != nil {
159 return output.Err(output.ErrCaddyFailed, "failed to generate Caddyfile: "+err.Error())
160 }
161
162 caddyPath := fmt.Sprintf("/etc/caddy/sites-enabled/%s.caddy", name) 156 caddyPath := fmt.Sprintf("/etc/caddy/sites-enabled/%s.caddy", name)
163 if err := client.WriteSudoFile(caddyPath, caddyfile); err != nil { 157 caddyExists, _ := client.Run(fmt.Sprintf("test -f %s && echo exists", caddyPath))
164 return output.Err(output.ErrCaddyFailed, "failed to write Caddyfile: "+err.Error()) 158 if strings.TrimSpace(caddyExists) != "exists" {
159 caddyfile, err := templates.AppCaddy(map[string]string{
160 "Domain": ctx.URL[8:], // Strip https://
161 "Port": strconv.Itoa(port),
162 })
163 if err != nil {
164 return output.Err(output.ErrCaddyFailed, "failed to generate Caddyfile: "+err.Error())
165 }
166
167 if err := client.WriteSudoFile(caddyPath, caddyfile); err != nil {
168 return output.Err(output.ErrCaddyFailed, "failed to write Caddyfile: "+err.Error())
169 }
165 } 170 }
166 171
167 // Reload systemd and start service 172 // Reload systemd and start service
@@ -255,18 +260,21 @@ func deployBinaryV2(ctx *deployContext) *output.ErrorResponse {
255 return output.Err(output.ErrServiceFailed, "failed to write systemd unit: "+err.Error()) 260 return output.Err(output.ErrServiceFailed, "failed to write systemd unit: "+err.Error())
256 } 261 }
257 262
258 // Generate Caddyfile 263 // Generate Caddyfile only if it doesn't exist (preserve manual edits)
259 caddyfile, err := templates.AppCaddy(map[string]string{
260 "Domain": ctx.URL[8:], // Strip https://
261 "Port": strconv.Itoa(port),
262 })
263 if err != nil {
264 return output.Err(output.ErrCaddyFailed, "failed to generate Caddyfile: "+err.Error())
265 }
266
267 caddyPath := fmt.Sprintf("/etc/caddy/sites-enabled/%s.caddy", name) 264 caddyPath := fmt.Sprintf("/etc/caddy/sites-enabled/%s.caddy", name)
268 if err := client.WriteSudoFile(caddyPath, caddyfile); err != nil { 265 caddyExists, _ := client.Run(fmt.Sprintf("test -f %s && echo exists", caddyPath))
269 return output.Err(output.ErrCaddyFailed, "failed to write Caddyfile: "+err.Error()) 266 if strings.TrimSpace(caddyExists) != "exists" {
267 caddyfile, err := templates.AppCaddy(map[string]string{
268 "Domain": ctx.URL[8:], // Strip https://
269 "Port": strconv.Itoa(port),
270 })
271 if err != nil {
272 return output.Err(output.ErrCaddyFailed, "failed to generate Caddyfile: "+err.Error())
273 }
274
275 if err := client.WriteSudoFile(caddyPath, caddyfile); err != nil {
276 return output.Err(output.ErrCaddyFailed, "failed to write Caddyfile: "+err.Error())
277 }
270 } 278 }
271 279
272 // Reload systemd and start service 280 // Reload systemd and start service