Author | Jakob Wakeling <[email protected]> |
Date | 2025-01-11 06:36:26 |
Commit | 54413b9514588efb4ac91826eff31595a2e9b6e9 |
Parent | b6b062e839814307951e8786debde361bb74da60 |
Add example Podman command, and refine cron page
Diffstat
M | README.md | | | 21 | +++++++++++++++++++++ |
M | res/admin/cron.html | | | 10 | +++++++--- |
M | src/admin/cron.go | | | 24 | ++++++++++++------------ |
M | src/cron/cron.go | | | 16 | ++++++++-------- |
4 files changed, 48 insertions, 23 deletions
diff --git a/README.md b/README.md index 3337143..d1db11e 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,27 @@ Note that at present, compatibility between updates is not guaranteed. To build **Goit**, from the project root, run `make build`. +To run **Goit** with Podman, a command like the following should be used: + +```sh +podman run -u 0:0 --userns keep-id:uid=973,gid=973 \ + -v /GOIT/CONFIG/ON/HOST:/home/git/.config/goit:Z \ + -v /GOIT/DATA/ON/HOST:/home/git/.local/share/goit:Z \ + -v /GOIT/STATE/ON/HOST:/home/git/.local/state/goit:Z \ + -p 8080:8080 -p 2222:22 --name goit goit:0.2.0 +``` + +- `-u 0:0` is required to start the container as the root user, to run OpenSSH. +- Goit runs as the `git` user with UID 973 inside the container. +- UID 973 is mapped to the host user with `--userns`, for file permissions. +- Directories for config, data, and state can (optionally) be mapped to + directories on the host for persistence. +- Config is stored at `/home/git/.config/goit` inside the container. +- Data is stored at `/home/git/.local/share/goit` inside the container. +- State is stored at `/home/git/.local/state/goit` inside the container. +- The port 8080 is exposed inside the container for HTTP. +- The port 22 is exposed inside the container for SSH. + ## Meta Copyright (C) 2023, Jakob Wakeling diff --git a/res/admin/cron.html b/res/admin/cron.html index ad97916..a82d388 100644 --- a/res/admin/cron.html +++ b/res/admin/cron.html @@ -8,7 +8,7 @@ <thead> <tr> <td><b>ID</b></td> - <td><b>Repository</b></td> + <td><b>Description</b></td> <td><b>Schedule</b></td> <td><b>Next</b></td> <td><b>Last</b></td> @@ -17,8 +17,12 @@ <tbody> {{range .Jobs}} <tr> - <td>{{.Id}}</td> - <td><a href="/{{.Repo}}">{{.Repo}}</a></td> + <td>{{.ID}}</td> + {{if .Repo}} + <td>Mirror <a href="/{{.Repo}}">{{.Description}}</a></td> + {{else}} + <td>{{.Description}}</td> + {{end}} <td>{{.Schedule}}</td> <td>{{.Next}}</td> <td>{{.Last}}</td> diff --git a/src/admin/cron.go b/src/admin/cron.go index ea12693..4f46689 100644 --- a/src/admin/cron.go +++ b/src/admin/cron.go @@ -5,7 +5,6 @@ package admin import ( "fmt" - "log" "net/http" "time" @@ -16,7 +15,7 @@ import ( func HandleCron(w http.ResponseWriter, r *http.Request) { auth, user, err := goit.Auth(w, r, true) if err != nil { - log.Println("[/admin/cron]", err.Error()) + util.PrintFuncError(err) goit.HttpError(w, http.StatusInternalServerError) return } @@ -26,7 +25,7 @@ func HandleCron(w http.ResponseWriter, r *http.Request) { return } - type row struct{ Id, Repo, Schedule, Next, Last string } + type row struct{ ID, Description, Repo, Schedule, Next, Last string } data := struct { Title string Jobs []row @@ -35,24 +34,25 @@ func HandleCron(w http.ResponseWriter, r *http.Request) { for _, job := range goit.Cron.Jobs() { repo := &goit.Repo{} - if job.Rid != -1 { - if r, err := goit.GetRepo(job.Rid); err != nil { - log.Println("[/admin/cron]", err.Error()) + if job.RID != -1 { + if r, err := goit.GetRepo(job.RID); err != nil { + util.PrintFuncError(err) } else if r != nil { repo = r } } data.Jobs = append(data.Jobs, row{ - Id: fmt.Sprint(job.Id), - Repo: repo.Name, - Schedule: job.Schedule.String(), - Next: job.Next.String(), - Last: util.If(job.Last == time.Time{}, "never", job.Last.String()), + ID: fmt.Sprint(job.ID), + Description: util.If(repo.Name != "", repo.Name, "Session Cleanup"), + Repo: repo.Name, + Schedule: job.Schedule.String(), + Next: job.Next.String(), + Last: util.If(job.Last == time.Time{}, "never", job.Last.String()), }) } if err := goit.Tmpl.ExecuteTemplate(w, "admin/cron", data); err != nil { - log.Println("[/admin/cron]", err.Error()) + util.PrintFuncError(err) } } diff --git a/src/cron/cron.go b/src/cron/cron.go index a44e8ed..3a8568e 100644 --- a/src/cron/cron.go +++ b/src/cron/cron.go @@ -24,8 +24,8 @@ type Cron struct { } type Job struct { - Id uint64 - Rid int64 + ID uint64 + RID int64 Schedule Schedule Next, Last time.Time fn func() @@ -86,7 +86,7 @@ func (c *Cron) Start() { continue } - log.Println("[cron] running job", job.Id, job.Rid) + log.Println("[cron] running job", job.ID, job.RID) j := job c.waiter.Add(1) @@ -177,12 +177,12 @@ func (c *Cron) Add(rid int64, schedule Schedule, fn func()) uint64 { c.lastId += 1 - job := Job{Id: c.lastId, Rid: rid, Schedule: schedule, fn: fn} + job := Job{ID: c.lastId, RID: rid, Schedule: schedule, fn: fn} job.Next = job.Schedule.Next(time.Now().UTC()) c.jobs = append(c.jobs, job) - log.Println("[cron] added job", job.Id, "for", job.Rid) - return job.Id + log.Println("[cron] added job", job.ID, "for", job.RID) + return job.ID } func (c *Cron) RemoveFor(rid int64) { @@ -193,10 +193,10 @@ func (c *Cron) RemoveFor(rid int64) { tmp := c.jobs[:0] for _, job := range c.jobs { - if job.Rid != rid { + if job.RID != rid { tmp = append(tmp, job) } else { - log.Println("[cron] removing job", job.Id, "for", job.Rid) + log.Println("[cron] removing job", job.ID, "for", job.RID) } }