From 2d9114c8ad80157cc9243e7d94b10b84e3bdfa1e Mon Sep 17 00:00:00 2001 From: Nick Guenther Date: Fri, 24 Feb 2023 21:56:36 -0500 Subject: [PATCH] GITEA_PUBLIC_PATH -> GITEA_CUSTOM This is an environment variable Gitea also can use. --- README.md | 12 ++++++++++++ bids-hook.go | 26 +++++++++++--------------- start | 13 +++++++++++-- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 94b60f6..257ea7a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ # bids-hook Tiny CI server to run bids-validator using Gitea webhooks + + +## Deployment + +Results are placed in `%(GITEA_CUSTOM)/public/bids-validator/`; +this folder needs to be writable (and ideally created first and owned) +by the user running this daemon. + +It assumes the URL `%(ROOT_URL)s/static/assets/` loads from +Gitea's `%(GITEA_CUSTOM)/public/`; it is **not** compatible +with configuring Gitea's `%(STATIC_URL_PREFIX)` so that +static files are hosted on a different server or CDN. diff --git a/bids-hook.go b/bids-hook.go index 9d37a6f..a792ec6 100644 --- a/bids-hook.go +++ b/bids-hook.go @@ -52,12 +52,11 @@ var ( // can be generated from a gitea admin account under "Settings" -> "Applications" giteaToken []byte - // the path to Gitea's static assets directory - // read from environment variable GITEA_PUBLIC_PATH + // the path to Gitea's custom/ directory + // read from environment variable GITEA_CUSTOM // used to save job result pages - // it should already exist - // should end with "/custom/public" - giteaPublicPath string + // see https://docs.gitea.io/en-us/config-cheat-sheet/#default-configuration-non-appini-configuration + giteaCustom string // executable run by the worker for each accepted job // read from environment variable WORKER_SCRIPT @@ -286,7 +285,7 @@ func (j job) resultUrl() string { // file path to the results page for this job // see also j.resultUrl() func (j job) resultPath() string { - return filepath.Join(giteaPublicPath, fmt.Sprintf("%s.html", j.uuid)) + return filepath.Join(giteaCustom, "public", fmt.Sprintf("%s.html", j.uuid)) } // file path to the log file for this job @@ -457,20 +456,17 @@ func readConfig() { } giteaToken = []byte(val) - val, ok = os.LookupEnv("GITEA_PUBLIC_PATH") + val, ok = os.LookupEnv("GITEA_CUSTOM") if !ok { - log.Fatal("missing environment variable GITEA_PUBLIC_PATH") + log.Fatal("missing environment variable GITEA_CUSTOM") } - giteaPublicPath, err = filepath.Abs(val) + giteaCustom, err = filepath.Abs(val) if err != nil { - log.Fatalf("invalid GITEA_PUBLIC_PATH: %v", err) + log.Fatalf("invalid GITEA_CUSTOM: %v", err) } - info, err = os.Stat(giteaPublicPath) + err = os.MkdirAll(filepath.Join(giteaCustom, "public"), 0750) if err != nil { - log.Fatalf("error opening GITEA_PUBLIC_PATH: %v", err) - } - if !info.IsDir() { - log.Fatal("GITEA_PUBLIC_PATH is not a directory") + log.Fatalf("error creating output folder: %v", err) } val, ok = os.LookupEnv("WORKER_SCRIPT") diff --git a/start b/start index ba9f448..39640e4 100755 --- a/start +++ b/start @@ -1,5 +1,16 @@ #!/bin/bash +set -e + +# this replicates the default location logic from https://docs.gitea.io/en-us/config-cheat-sheet/ +# any setting can be overridden just by setting its variable before calling this script +: ${GITEA_APP_PATH:=../gitea/gitea} +: ${GITEA_WORK_DIR:="$(dirname "$GITEA_APP_PATH")"} + +: ${GITEA_CUSTOM:="$GITEA_WORK_DIR/custom"} + +export GITEA_CUSTOM + # 127.0.0.1 is localhost, and 2845 is 0xB1D export BIDS_HOOK_URL='http://127.0.0.1:2845/bids-hook' export BIDS_HOOK_SECRET='blabla' @@ -7,8 +18,6 @@ export BIDS_HOOK_SECRET='blabla' export GITEA_ROOT_URL='http://127.0.0.1:3000' export GITEA_TOKEN='69e45fa9cfa75a7497633c6be8dd2347226e2f62' -export GITEA_PUBLIC_PATH='./custom/public' - export WORKER_SCRIPT='./worker' export WORKER_LOG_PATH='./log' export WORKER_QUEUE_CAPACITY=20