diff options
Diffstat (limited to 'cmd/ship')
| -rw-r--r-- | cmd/ship/deploy_impl_v2.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/cmd/ship/deploy_impl_v2.go b/cmd/ship/deploy_impl_v2.go index 5d9629d..417ee8f 100644 --- a/cmd/ship/deploy_impl_v2.go +++ b/cmd/ship/deploy_impl_v2.go | |||
| @@ -4,6 +4,7 @@ import ( | |||
| 4 | "fmt" | 4 | "fmt" |
| 5 | "net/http" | 5 | "net/http" |
| 6 | "strconv" | 6 | "strconv" |
| 7 | "strings" | ||
| 7 | "time" | 8 | "time" |
| 8 | 9 | ||
| 9 | "github.com/bdw/ship/internal/output" | 10 | "github.com/bdw/ship/internal/output" |
| @@ -25,17 +26,22 @@ func deployStaticV2(ctx *deployContext) *output.ErrorResponse { | |||
| 25 | name := ctx.Name | 26 | name := ctx.Name |
| 26 | remotePath := fmt.Sprintf("/var/www/%s", name) | 27 | remotePath := fmt.Sprintf("/var/www/%s", name) |
| 27 | 28 | ||
| 28 | // Create directory | 29 | // Create directory and set ownership for upload |
| 30 | user, _ := client.Run("whoami") | ||
| 31 | user = strings.TrimSpace(user) | ||
| 29 | if _, err := client.RunSudo(fmt.Sprintf("mkdir -p %s", remotePath)); err != nil { | 32 | if _, err := client.RunSudo(fmt.Sprintf("mkdir -p %s", remotePath)); err != nil { |
| 30 | return output.Err(output.ErrUploadFailed, "failed to create directory: "+err.Error()) | 33 | return output.Err(output.ErrUploadFailed, "failed to create directory: "+err.Error()) |
| 31 | } | 34 | } |
| 35 | if _, err := client.RunSudo(fmt.Sprintf("chown -R %s:%s %s", user, user, remotePath)); err != nil { | ||
| 36 | return output.Err(output.ErrUploadFailed, "failed to set directory ownership: "+err.Error()) | ||
| 37 | } | ||
| 32 | 38 | ||
| 33 | // Upload files using rsync | 39 | // Upload files using rsync |
| 34 | if err := client.UploadDir(ctx.Path, remotePath); err != nil { | 40 | if err := client.UploadDir(ctx.Path, remotePath); err != nil { |
| 35 | return output.Err(output.ErrUploadFailed, err.Error()) | 41 | return output.Err(output.ErrUploadFailed, err.Error()) |
| 36 | } | 42 | } |
| 37 | 43 | ||
| 38 | // Set ownership | 44 | // Set ownership back to www-data |
| 39 | if _, err := client.RunSudo(fmt.Sprintf("chown -R www-data:www-data %s", remotePath)); err != nil { | 45 | if _, err := client.RunSudo(fmt.Sprintf("chown -R www-data:www-data %s", remotePath)); err != nil { |
| 40 | // Non-fatal, continue | 46 | // Non-fatal, continue |
| 41 | } | 47 | } |
