fix service templates and paths
This commit is contained in:
parent
19a1e3916f
commit
3ac11468a1
7 changed files with 70 additions and 30 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -72,8 +73,15 @@ func (a *App) deployProjectFromMain(_ context.Context, p Project) error {
|
|||
if p.RepoURL == "" {
|
||||
return errors.New("project has no repo_url to deploy from")
|
||||
}
|
||||
projectDir := filepath.Join(a.cfg.ProjectRoot, slugify(p.UserID), p.Workspace, p.Slug)
|
||||
projectDir, err := a.projectDirFor(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoDir := filepath.Join(projectDir, "repo")
|
||||
binDir := filepath.Join(projectDir, "bin")
|
||||
if err := os.MkdirAll(binDir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := os.Stat(repoDir); os.IsNotExist(err) {
|
||||
if err := runCmd("git", "clone", "--branch", "main", "--single-branch", p.RepoURL, repoDir); err != nil {
|
||||
return err
|
||||
|
|
@ -89,5 +97,12 @@ func (a *App) deployProjectFromMain(_ context.Context, p Project) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
binaryPath := filepath.Join(binDir, "app")
|
||||
if err := runCmd("go", "-C", repoDir, "build", "-o", binaryPath, "."); err != nil {
|
||||
return fmt.Errorf("build failed: %w", err)
|
||||
}
|
||||
if err := ensureOwnedByUnixUser(binaryPath, p.UnixUser, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
return runSystemctlUser(p.UnixUser, "restart", p.ServiceName)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue