diff --git a/.woodpecker/dockerize-dev.yml b/.woodpecker/dockerize-dev.yml index 030744c..fc9e851 100644 --- a/.woodpecker/dockerize-dev.yml +++ b/.woodpecker/dockerize-dev.yml @@ -5,7 +5,7 @@ pipeline: branch: dev image: woodpeckerci/plugin-docker-buildx settings: - dockerfile: Dockerfile + dockerfile: DockerfileDev registry: https://codeberg.org/v2 repo: codeberg.org/gothub/gothub platforms: linux/amd64,linux/arm64 diff --git a/Dockerfile b/Dockerfile index 95f9900..5321429 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN apk --no-cache add git RUN git clone https://codeberg.org/gothub/gothub . RUN go mod download -RUN GOOS=linux GOARCH=$TARGETARCH go build -o /src/gothub +RUN GOOS=linux GOARCH=$TARGETARCH go build -o /src/gothub -ldflags="-X codeberg.org/gothub/gothub/utils.Branch=master" FROM alpine:3.16 as bin @@ -19,4 +19,4 @@ COPY --from=build /src/public ./public ENV DOCKER true EXPOSE 3000 -CMD ["/app/gothub", "serve"] \ No newline at end of file +CMD ["/app/gothub", "serve"] diff --git a/DockerfileDev b/DockerfileDev new file mode 100644 index 0000000..4ac8748 --- /dev/null +++ b/DockerfileDev @@ -0,0 +1,22 @@ +FROM --platform=$BUILDPLATFORM golang:alpine AS build + +ARG TARGETARCH + +WORKDIR /src +RUN apk --no-cache add git +RUN git clone https://codeberg.org/gothub/gothub . + +RUN go mod download +RUN GOOS=linux GOARCH=$TARGETARCH go build -o /src/gothub -ldflags="-X codeberg.org/gothub/gothub/utils.Branch=dev" + +FROM alpine:3.16 as bin + +WORKDIR /app +COPY --from=build /src/gothub . +COPY --from=build /src/views ./views +COPY --from=build /src/public ./public + +ENV DOCKER true +EXPOSE 3000 + +CMD ["/app/gothub", "serve"] diff --git a/README.md b/README.md index 260c73d..5aa428a 100644 --- a/README.md +++ b/README.md @@ -34,15 +34,17 @@ The ``master`` branch runs on the master branch of GotHub. This means that the i | Link | Cloudflare | Country | ISP | Branch | | -------- | ---------- | ----------- | ----- | ----- | | [gh.akisblack.dev](https://gh.akisblack.dev) | No | Germany | OVHcloud | master | -| [gothub.lunar.icu](https://gothub.lunar.icu) | Yes | Germany | Unesty | master | +| [gothub.esmailelbob.xyz](https://gothub.esmailelbob.xyz) | No | Canada | OVHcloud | master | +| [gothub.no-logs.com](https://gothub.no-logs.com/) | No | Sweden | Vultr | master | | [gh.odyssey346.dev](https://gh.odyssey346.dev) | No | France | OVHcloud (Trolling Solutions) | master | | [gh.phreedom.club](https://gh.phreedom.club) | No | Iceland | Flokinet | master | | [gothub.projectsegfau.lt](https://gothub.projectsegfau.lt) | No | GeoDNS (Luxembourg/USA/India) | BuyVM/Digital Ocean/Airtel | master | | [gh.riverside.rocks](https://gh.riverside.rocks) | No | USA | Comcast | master | +| [gh.fascinated.cc](https://gh.fascinated.cc) | Yes | Germany | Contabo | master | +| [gothub.lunar.icu](https://gothub.lunar.icu) | Yes | Germany | Unesty | master | | [gothub.xbdm.fun](https://gothub.xbdm.fun) | Yes | Germany | Hetzner | master | | [dev.gh.akisblack.dev](https://dev.gh.akisblack.dev) | No | Germany | OVHcloud | dev | -| [gh.creller.net](https://gh.creller.net) | No | Finland | Hetzner | dev | -| [gothub.esmailelbob.xyz](https://gothub.esmailelbob.xyz) | No | Canada | OVHcloud | dev | +| [gh.creller.net](https://gh.creller.net) | No | Scotland | British Telecommunications PLC | dev | | [gh.dev.odyssey346.dev](https://gh.dev.odyssey346.dev) | No | France | OVHcloud (Trolling Solutions) | dev | | [gothub.dev.projectsegfau.lt](https://gothub.dev.projectsegfau.lt) | No | Luxembourg | BuyVM | dev | diff --git a/cmd/gothub/update.go b/cmd/gothub/update.go index 54d6848..82bb938 100644 --- a/cmd/gothub/update.go +++ b/cmd/gothub/update.go @@ -3,6 +3,7 @@ package gothub import ( "bytes" "fmt" + "strings" "github.com/spf13/cobra" @@ -30,6 +31,9 @@ func update() { os.Exit(1) } gitPull := exec.Command("git", "pull") + curBranch := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") + curBranchOut, _ := curBranch.CombinedOutput() + ldFlags := "-X codeberg.org/gothub/gothub/utils.Branch=" + strings.Replace(string(curBranchOut), "\n", "", -1) var out bytes.Buffer gitPull.Stdout = &out err := gitPull.Run() @@ -42,7 +46,7 @@ func update() { os.Exit(1) } if runtime.GOOS == "windows" { - err := exec.Command("go", "build", "-o", "gothub.exe").Run() + err := exec.Command("go", "build", "-o", "gothub.exe", ldFlags).Run() if err != nil { fmt.Println("Couldn't build GotHub.", err) os.Exit(1) @@ -51,7 +55,7 @@ func update() { os.Exit(0) } } else { - err := exec.Command("go", "build").Run() + err := exec.Command("go", "build", "-ldflags", ldFlags).Run() if err != nil { fmt.Println("Couldn't build GotHub.", err) os.Exit(1) diff --git a/compose.yml b/compose.yml index d34f91e..ae3ec24 100644 --- a/compose.yml +++ b/compose.yml @@ -1,7 +1,7 @@ version: "3" services: gothub: - image: codeberg.org/gothub/gothub:latest + image: codeberg.org/gothub/gothub:latest # Master branch # image: codeberg.org/gothub/gothub:dev # Dev branch restart: unless-stopped ports: @@ -22,4 +22,4 @@ services: test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/version || exit 1 interval: 30s timeout: 5s - retries: 2 + retries: 2 \ No newline at end of file diff --git a/pages/about.go b/pages/about.go index dcc8efa..fde51c4 100644 --- a/pages/about.go +++ b/pages/about.go @@ -41,6 +41,7 @@ func HandleAbout(c *fiber.Ctx) error { return c.Render("about", fiber.Map{ "title": "About this instance", + "branch": utils.Branch, "privacyInformation": privacyInfoArray, }) } diff --git a/pages/dirview.go b/pages/dirview.go index 31cebf7..baf4c7f 100644 --- a/pages/dirview.go +++ b/pages/dirview.go @@ -88,6 +88,7 @@ func DirView(c *fiber.Ctx) error { dirArray = append(dirArray, Scrape) return c.Render("dir", fiber.Map{ "title": "Directory " + c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"), + "branch": utils.Branch, "dir": dirArray, "files": dirFilesArray, "readme": string(readmeOutput), diff --git a/pages/explore.go b/pages/explore.go index a425673..0606011 100644 --- a/pages/explore.go +++ b/pages/explore.go @@ -36,7 +36,8 @@ func HandleExplore(c *fiber.Ctx) error { } return c.Render("explore", fiber.Map{ - "title": "Explore", - "repos": trendingReposArray, + "title": "Explore", + "branch": utils.Branch, + "repos": trendingReposArray, }) } diff --git a/pages/fileview.go b/pages/fileview.go index 514003e..0f46016 100644 --- a/pages/fileview.go +++ b/pages/fileview.go @@ -3,14 +3,14 @@ package pages import ( "bufio" "bytes" + "codeberg.org/gothub/gothub/utils" "context" - "html/template" - htmlfmt "github.com/alecthomas/chroma/v2/formatters/html" "github.com/alecthomas/chroma/v2/lexers" "github.com/alecthomas/chroma/v2/styles" "github.com/carlmjohnson/requests" "github.com/gofiber/fiber/v2" + "html/template" ) // FileView is the file view page @@ -57,11 +57,12 @@ func FileView(c *fiber.Ctx) error { writer.Flush() cssw.Flush() return c.Render("file", fiber.Map{ - "title": c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"), - "file": template.HTML(buf.String()), - "css": template.CSS(cssbuf.String()), - "fullname": c.Params("user") + "/" + c.Params("repo"), - "name": c.Params("+"), - "branch": c.Params("branch"), + "title": c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"), + "branch": utils.Branch, + "file": template.HTML(buf.String()), + "css": template.CSS(cssbuf.String()), + "fullname": c.Params("user") + "/" + c.Params("repo"), + "name": c.Params("+"), + "fileBranch": c.Params("branch"), }) } diff --git a/pages/gist.go b/pages/gist.go index 71d755b..350800c 100644 --- a/pages/gist.go +++ b/pages/gist.go @@ -3,6 +3,7 @@ package pages import ( "bufio" "bytes" + "codeberg.org/gothub/gothub/utils" "context" htmlfmt "github.com/alecthomas/chroma/v2/formatters/html" "github.com/alecthomas/chroma/v2/lexers" @@ -131,8 +132,9 @@ func HandleGist(c *fiber.Ctx) error { gistArray = append(gistArray, Scrape) return c.Render("gist", fiber.Map{ - "title": "Repository " + c.Params("user") + "/" + c.Params("gistID"), - "gist": gistArray, - "files": gistFilesArray, + "title": "Repository " + c.Params("user") + "/" + c.Params("gistID"), + "branch": utils.Branch, + "gist": gistArray, + "files": gistFilesArray, }) } diff --git a/pages/index.go b/pages/index.go index d3c5fab..6796c61 100644 --- a/pages/index.go +++ b/pages/index.go @@ -11,6 +11,7 @@ import ( func HandleIndex(c *fiber.Ctx) error { return c.Render("index", fiber.Map{ "host": c.Hostname(), + "branch": utils.Branch, "version": utils.Version(), "fiberversion": fiber.Version, "goversion": runtime.Version(), diff --git a/pages/repo.go b/pages/repo.go index 858397c..c7dc8d6 100644 --- a/pages/repo.go +++ b/pages/repo.go @@ -121,6 +121,7 @@ func HandleRepo(c *fiber.Ctx) error { repoArray = append(repoArray, Scrape) return c.Render("repo", fiber.Map{ "title": c.Params("user") + "/" + repoUrl + branchExists, + "branch": utils.Branch, "repo": repoArray, "files": repoFilesArray, "readme": readmeOutput, diff --git a/pages/user.go b/pages/user.go index bff5636..a96b2ce 100644 --- a/pages/user.go +++ b/pages/user.go @@ -181,7 +181,8 @@ func HandleUser(c *fiber.Ctx) error { userArray = append(userArray, Scrape) return c.Render("user", fiber.Map{ - "title": c.Params("user"), - "user": userArray, + "title": c.Params("user"), + "branch": utils.Branch, + "user": userArray, }) } diff --git a/serve/serve.go b/serve/serve.go index e25b4d6..58dd360 100644 --- a/serve/serve.go +++ b/serve/serve.go @@ -4,8 +4,8 @@ import ( "html/template" "log" "os" - "regexp" "runtime" + "strings" "time" "codeberg.org/gothub/gothub/pages" @@ -45,10 +45,11 @@ func Serve(port string) { if e, ok := err.(*fiber.Error); ok { code = e.Code } - _, link := regexp.MatchString(`\/.*\ `, err.Error()) + link := strings.TrimPrefix(err.Error(), "Cannot GET ") err = ctx.Status(code).Render("error", fiber.Map{ - "error": err, - "link": link, + "error": err, + "link": link, + "branch": utils.Branch, }) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") @@ -73,7 +74,8 @@ func Serve(port string) { Expiration: 5 * time.Minute, LimitReached: func(c *fiber.Ctx) error { return c.Status(429).Render("ratelimit_gt", fiber.Map{ - "Title": "Rate limit exceeded", + "Title": "Rate limit exceeded", + "branch": utils.Branch, }) }, }) diff --git a/utils/version.go b/utils/version.go index a45512a..39b6090 100644 --- a/utils/version.go +++ b/utils/version.go @@ -4,6 +4,8 @@ import ( "runtime/debug" ) +var Branch = "Alpha" + // Version returns the git commit hash of the current build. Taken from https://git.vern.cc/pjals/bestofbot. func Version() string { if info, ok := debug.ReadBuildInfo(); ok { diff --git a/views/error.html b/views/error.html index 3a5f3a4..f7b72e7 100644 --- a/views/error.html +++ b/views/error.html @@ -12,6 +12,8 @@ Create an issue on Codeberg. + {{ if .link }} Or view this page on + GitHub {{end}} diff --git a/views/file.html b/views/file.html index 7f178a4..75be538 100644 --- a/views/file.html +++ b/views/file.html @@ -11,7 +11,7 @@ }
- Back to {{.fullname}}
diff --git a/views/header.html b/views/header.html index 57dd5d3..8d28837 100644 --- a/views/header.html +++ b/views/header.html @@ -20,7 +20,7 @@ height="30" width="30" alt="" - >GotHub (alpha)GotHub ({{.branch}})