fix deploy and logs
This commit is contained in:
parent
79b3c8d693
commit
af8bbf536f
5 changed files with 40 additions and 6 deletions
|
|
@ -78,6 +78,9 @@ func (a *App) deployProjectFromMain(_ context.Context, p Project) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
repoDir := filepath.Join(projectDir, "repo")
|
repoDir := filepath.Join(projectDir, "repo")
|
||||||
|
if _, err := os.Stat(repoDir); err != nil {
|
||||||
|
return fmt.Errorf("repo checkout missing at %s (trigger deploy webhook/push first)", repoDir)
|
||||||
|
}
|
||||||
binDir := filepath.Join(projectDir, "bin")
|
binDir := filepath.Join(projectDir, "bin")
|
||||||
if err := os.MkdirAll(binDir, 0o755); err != nil {
|
if err := os.MkdirAll(binDir, 0o755); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -97,6 +100,25 @@ func (a *App) deployProjectFromMain(_ context.Context, p Project) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := a.buildProjectBinary(p); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return runSystemctlUser(p.UnixUser, "restart", p.ServiceName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) buildProjectBinary(p Project) error {
|
||||||
|
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 := ensureOwnedByUnixUser(binDir, p.UnixUser, 0o755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
binaryPath := filepath.Join(binDir, "app")
|
binaryPath := filepath.Join(binDir, "app")
|
||||||
if err := runCmd("go", "-C", repoDir, "build", "-o", binaryPath, "."); err != nil {
|
if err := runCmd("go", "-C", repoDir, "build", "-o", binaryPath, "."); err != nil {
|
||||||
return fmt.Errorf("build failed: %w", err)
|
return fmt.Errorf("build failed: %w", err)
|
||||||
|
|
@ -104,5 +126,5 @@ func (a *App) deployProjectFromMain(_ context.Context, p Project) error {
|
||||||
if err := ensureOwnedByUnixUser(binaryPath, p.UnixUser, 0o755); err != nil {
|
if err := ensureOwnedByUnixUser(binaryPath, p.UnixUser, 0o755); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return runSystemctlUser(p.UnixUser, "restart", p.ServiceName)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,14 @@ func (a *App) provisionProject(ctx context.Context, p *Project) error {
|
||||||
p.ProvisionError = err.Error()
|
p.ProvisionError = err.Error()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if p.RepoURL != "" {
|
||||||
|
if err := a.buildProjectBinary(*p); err != nil {
|
||||||
|
_ = a.updateProvisioningState(ctx, p.ID, "failed", err.Error())
|
||||||
|
p.ProvisionState = "failed"
|
||||||
|
p.ProvisionError = err.Error()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := a.renderSystemdForProject(ctx, *p); err != nil {
|
if err := a.renderSystemdForProject(ctx, *p); err != nil {
|
||||||
_ = a.updateProvisioningState(ctx, p.ID, "failed", err.Error())
|
_ = a.updateProvisioningState(ctx, p.ID, "failed", err.Error())
|
||||||
|
|
|
||||||
|
|
@ -248,11 +248,12 @@ func (a *App) handleProjectLogs(w http.ResponseWriter, r *http.Request, user Use
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lines := 200
|
lines := 100
|
||||||
|
const maxLogBytes = 64 * 1024
|
||||||
if raw := r.URL.Query().Get("lines"); raw != "" {
|
if raw := r.URL.Query().Get("lines"); raw != "" {
|
||||||
n, err := strconv.Atoi(raw)
|
n, err := strconv.Atoi(raw)
|
||||||
if err != nil || n < 1 || n > 1000 {
|
if err != nil || n < 1 || n > 300 {
|
||||||
http.Error(w, "lines must be 1-1000", http.StatusBadRequest)
|
http.Error(w, "lines must be 1-300", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lines = n
|
lines = n
|
||||||
|
|
@ -262,5 +263,8 @@ func (a *App) handleProjectLogs(w http.ResponseWriter, r *http.Request, user Use
|
||||||
http.Error(w, err.Error(), http.StatusBadGateway)
|
http.Error(w, err.Error(), http.StatusBadGateway)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(logs) > maxLogBytes {
|
||||||
|
logs = logs[:maxLogBytes] + "\n... (truncated)"
|
||||||
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"lines": lines, "logs": logs})
|
writeJSON(w, http.StatusOK, map[string]any{"lines": lines, "logs": logs})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -246,5 +246,5 @@ func (a *App) getServiceStatus(p Project) (ServiceStatus, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) getServiceLogs(p Project, lines int) (string, error) {
|
func (a *App) getServiceLogs(p Project, lines int) (string, error) {
|
||||||
return runJournalctlUser(p.UnixUser, "-u", p.ServiceName, "--no-pager", "-n", strconv.Itoa(lines), "-o", "short-iso")
|
return runJournalctlUser(p.UnixUser, "-u", p.ServiceName, "--no-pager", "-n", strconv.Itoa(lines), "-r", "-o", "short-iso")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ async function loadLogs(projectNode, projectID) {
|
||||||
const out = projectNode.querySelector('[data-logs-out]');
|
const out = projectNode.querySelector('[data-logs-out]');
|
||||||
out.textContent = 'loading logs...';
|
out.textContent = 'loading logs...';
|
||||||
try {
|
try {
|
||||||
const res = await api(`/api/projects/${projectID}/logs?lines=200`);
|
const res = await api(`/api/projects/${projectID}/logs?lines=100`);
|
||||||
out.textContent = res.logs || '(no logs)';
|
out.textContent = res.logs || '(no logs)';
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
out.textContent = `logs error: ${err.message}`;
|
out.textContent = `logs error: ${err.message}`;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue