Skip to content

Commit

Permalink
GITEA_PUBLIC_PATH -> GITEA_CUSTOM
Browse files Browse the repository at this point in the history
This is an environment variable Gitea also can use.
  • Loading branch information
kousu committed Feb 25, 2023
1 parent 7caa4a6 commit 2d9114c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 11 additions & 15 deletions bids-hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
13 changes: 11 additions & 2 deletions start
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
#!/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'

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
Expand Down

0 comments on commit 2d9114c

Please sign in to comment.