mirror of
https://github.com/ddworken/hishtory.git
synced 2025-04-09 23:48:53 +02:00
Add trigger-cron endpoint + optimize dockerfile for server
This commit is contained in:
parent
ab04756bab
commit
05f1af8714
@ -1,8 +1,10 @@
|
|||||||
FROM golang:1.17
|
FROM golang:1.17 AS builder
|
||||||
COPY go.mod ./
|
COPY go.mod ./
|
||||||
COPY go.sum ./
|
COPY go.sum ./
|
||||||
RUN unset GOPATH; go mod download
|
RUN unset GOPATH; go mod download
|
||||||
COPY . ./
|
COPY . ./
|
||||||
RUN unset GOPATH; go build -o /server -ldflags "-X main.ReleaseVersion=v0.`cat VERSION`" backend/server/server.go
|
RUN unset GOPATH; go build -o /server -ldflags "-X main.ReleaseVersion=v0.`cat VERSION`" backend/server/server.go
|
||||||
CMD [ "/server" ]
|
|
||||||
|
|
||||||
|
FROM golang:1.17
|
||||||
|
COPY --from=builder /server /server
|
||||||
|
CMD ["/server"]
|
||||||
|
@ -166,20 +166,35 @@ func init() {
|
|||||||
go runBackgroundJobs()
|
go runBackgroundJobs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cron() error {
|
||||||
|
err := updateReleaseVersion()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
err = cleanDatabase()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func runBackgroundJobs() {
|
func runBackgroundJobs() {
|
||||||
for {
|
for {
|
||||||
err := updateReleaseVersion()
|
err := cron()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Printf("Cron failure: %v", err)
|
||||||
}
|
|
||||||
err = cleanDatabase()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
}
|
||||||
time.Sleep(10 * time.Minute)
|
time.Sleep(10 * time.Minute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func triggerCronHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
err := cron()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type releaseInfo struct {
|
type releaseInfo struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
@ -297,6 +312,7 @@ func main() {
|
|||||||
http.Handle("/api/v1/ebootstrap", withLogging(apiEBootstrapHandler))
|
http.Handle("/api/v1/ebootstrap", withLogging(apiEBootstrapHandler))
|
||||||
http.Handle("/api/v1/eregister", withLogging(apiERegisterHandler))
|
http.Handle("/api/v1/eregister", withLogging(apiERegisterHandler))
|
||||||
http.Handle("/api/v1/banner", withLogging(apiBannerHandler))
|
http.Handle("/api/v1/banner", withLogging(apiBannerHandler))
|
||||||
|
http.Handle("/api/v1/trigger-cron", withLogging(triggerCronHandler))
|
||||||
http.Handle("/download/hishtory-linux-amd64", withLogging(bindaryDownloadHandler))
|
http.Handle("/download/hishtory-linux-amd64", withLogging(bindaryDownloadHandler))
|
||||||
http.Handle("/download/hishtory-linux-amd64.intoto.jsonl", withLogging(attestationDownloadHandler))
|
http.Handle("/download/hishtory-linux-amd64.intoto.jsonl", withLogging(attestationDownloadHandler))
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
|
Loading…
Reference in New Issue
Block a user