From 8f2699407d5c452e04bd0de8bbb367a60b4a88b8 Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 13 Sep 2022 23:06:31 +0200 Subject: [PATCH 1/7] Make verbose checks in tryBranch (#127) - It's likely that the tryBranch is returning false when it should be returning true, make these logs more verbose so they show up on production logs. Co-authored-by: Gusted Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/127 Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Gusted Co-committed-by: Gusted --- server/handler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/handler.go b/server/handler.go index cd67aa7..ed06659 100644 --- a/server/handler.go +++ b/server/handler.go @@ -85,7 +85,7 @@ func Handler(mainDomainSuffix, rawDomain []byte, // also disallow search indexing and add a Link header to the canonical URL. tryBranch := func(log zerolog.Logger, repo, branch string, path []string, canonicalLink string) bool { if repo == "" { - log.Debug().Msg("tryBranch: repo is empty") + log.Warn().Msg("tryBranch: repo is empty") return false } @@ -96,7 +96,7 @@ func Handler(mainDomainSuffix, rawDomain []byte, // Check if the branch exists, otherwise treat it as a file path branchTimestampResult := upstream.GetBranchTimestamp(giteaClient, targetOwner, repo, branch, branchTimestampCache) if branchTimestampResult == nil { - log.Debug().Msg("tryBranch: branch doesn't exist") + log.Warn().Msg("tryBranch: branch doesn't exist") return false } From 2a730b2439cae5ebd17d90e38b4ff27e4154a651 Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 13 Sep 2022 23:26:45 +0200 Subject: [PATCH 2/7] Update README (#128) - Update readme accordingly to the https://codeberg.org/Codeberg/pages-server/commit/876a53d9a245c11c58b61617052f7f2281d16358 Co-authored-by: Gusted Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/128 Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Gusted Co-committed-by: Gusted --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 700f279..c4758ac 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ and especially have a look at [this section of the haproxy.cfg](https://codeberg - `ENABLE_HTTP_SERVER` (default: false): Set this to true to enable the HTTP-01 challenge and redirect all other HTTP requests to HTTPS. Currently only works with port 80. - `DNS_PROVIDER` (default: use self-signed certificate): Code of the ACME DNS provider for the main domain wildcard. See https://go-acme.github.io/lego/dns/ for available values & additional environment variables. -- `DEBUG` (default: false): Set this to true to enable debug logging. +- `LOG_LEVEL` (default: warn): Set this to specify the level of logging. ## Contributing to the development @@ -106,4 +106,4 @@ run `just dev` now this pages should work: - https://magiclike.localhost.mock.directory:4430/ - https://momar.localhost.mock.directory:4430/ci-testing/ - - https://momar.localhost.mock.directory:4430/pag/@master/ \ No newline at end of file + - https://momar.localhost.mock.directory:4430/pag/@master/ From 091e6c8ed9f737b3b84a3610c5836953677d122c Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 18 Sep 2022 16:13:27 +0200 Subject: [PATCH 3/7] Add explicit logging in `GetBranchTimestamp` (#130) - Logs are currently indicating that it's returning `nil` in valid scenarios, therefor this patch adds extra logging in this code to better understand what it is doing in this function. Co-authored-by: Gusted Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/130 Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Gusted Co-committed-by: Gusted --- server/handler.go | 2 +- server/upstream/helper.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/handler.go b/server/handler.go index ed06659..fb8b419 100644 --- a/server/handler.go +++ b/server/handler.go @@ -296,7 +296,7 @@ func Handler(mainDomainSuffix, rawDomain []byte, return } - log.Info().Msg("tryBranch, now trying upstream 7 %s") + log.Info().Msg("tryBranch, now trying upstream 7") tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOptions, targetOwner, targetRepo, targetBranch, targetPath, canonicalDomainCache, branchTimestampCache, fileResponseCache) diff --git a/server/upstream/helper.go b/server/upstream/helper.go index 0714dcd..28f4474 100644 --- a/server/upstream/helper.go +++ b/server/upstream/helper.go @@ -9,6 +9,7 @@ import ( "codeberg.org/codeberg/pages/server/cache" "codeberg.org/codeberg/pages/server/gitea" + "github.com/rs/zerolog/log" ) type branchTimestamp struct { @@ -19,10 +20,13 @@ type branchTimestamp struct { // GetBranchTimestamp finds the default branch (if branch is "") and returns the last modification time of the branch // (or nil if the branch doesn't exist) func GetBranchTimestamp(giteaClient *gitea.Client, owner, repo, branch string, branchTimestampCache cache.SetGetKey) *branchTimestamp { + log := log.With().Strs("BranchInfo", []string{owner, repo, branch}).Logger() if result, ok := branchTimestampCache.Get(owner + "/" + repo + "/" + branch); ok { if result == nil { + log.Debug().Msg("branchTimestampCache found item, but result is empty") return nil } + log.Debug().Msg("branchTimestampCache found item, returning result") return result.(*branchTimestamp) } result := &branchTimestamp{ @@ -32,16 +36,20 @@ func GetBranchTimestamp(giteaClient *gitea.Client, owner, repo, branch string, b // Get default branch defaultBranch, err := giteaClient.GiteaGetRepoDefaultBranch(owner, repo) if err != nil { + log.Err(err).Msg("Could't fetch default branch from repository") _ = branchTimestampCache.Set(owner+"/"+repo+"/", nil, defaultBranchCacheTimeout) return nil } + log.Debug().Msg("Succesfully fetched default branch from Gitea") result.Branch = defaultBranch } timestamp, err := giteaClient.GiteaGetRepoBranchTimestamp(owner, repo, result.Branch) if err != nil { + log.Err(err).Msg("Could not get latest commit's timestamp from branch") return nil } + log.Debug().Msg("Succesfully fetched latest commit's timestamp from branch, adding to cache") result.Timestamp = timestamp _ = branchTimestampCache.Set(owner+"/"+repo+"/"+branch, result, branchExistenceCacheTimeout) return result From df2228b6d59b175df87b8849391b4a8d317e7eb3 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 10 Oct 2022 23:25:21 +0200 Subject: [PATCH 4/7] ci: let tag run pipeline --- .woodpecker.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 2674e9b..198648f 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,5 +1,3 @@ -branches: main - pipeline: # use vendor to cache dependencies vendor: From b9e9f1420954d1a352f7e9e7e799b160bd224eb1 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 10 Oct 2022 23:27:33 +0200 Subject: [PATCH 5/7] use codeberg.org/6543/docker-images/golang_just Signed-off-by: 6543 <6543@obermui.de> --- .woodpecker.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 198648f..db51eba 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -17,7 +17,7 @@ pipeline: build: group: compliant - image: a6543/golang_just + image: codeberg.org/6543/docker-images/golang_just commands: - go version - just build @@ -37,7 +37,7 @@ pipeline: build-tag: group: compliant - image: a6543/golang_just + image: codeberg.org/6543/docker-images/golang_just commands: - go version - just build-tag ${CI_COMMIT_TAG##v} @@ -46,13 +46,13 @@ pipeline: test: group: test - image: a6543/golang_just + image: codeberg.org/6543/docker-images/golang_just commands: - just test integration-tests: group: test - image: a6543/golang_just + image: codeberg.org/6543/docker-images/golang_just commands: - just integration environment: From bf9a08e1fd4107667dc6816e1df0d0ec2c0acbe9 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 7 Nov 2022 16:27:37 +0100 Subject: [PATCH 6/7] Fatal on ACME Client creation failure (#133) - For production(*cough* Codeberg *cough*), it's important to not use mock certs. So fail right from the start if this is the case and not try to "handle it gracefully", as it would break production. - Resolves #131 CC @6543 Co-authored-by: Gusted Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/133 Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Gusted Co-committed-by: Gusted --- server/certificates/certificates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/certificates/certificates.go b/server/certificates/certificates.go index 8944468..2f59fb4 100644 --- a/server/certificates/certificates.go +++ b/server/certificates/certificates.go @@ -414,7 +414,7 @@ func SetupCertificates(mainDomainSuffix []byte, dnsProvider string, acmeConfig * acmeClient, err = lego.NewClient(acmeConfig) if err != nil { - log.Error().Err(err).Msg("Can't create ACME client, continuing with mock certs only") + log.Fatal().Err(err).Msg("Can't create ACME client, continuing with mock certs only") } else { err = acmeClient.Challenge.SetTLSALPN01Provider(AcmeTLSChallengeProvider{challengeCache}) if err != nil { From 91b54bef29ca9e7d3394fad1e44fa4b6f795035c Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 7 Nov 2022 23:09:41 +0100 Subject: [PATCH 7/7] add newline --- server/upstream/upstream.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/upstream/upstream.go b/server/upstream/upstream.go index 0e27727..61c90de 100644 --- a/server/upstream/upstream.go +++ b/server/upstream/upstream.go @@ -85,6 +85,7 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaClient *gitea.Client, } else { res, err = giteaClient.ServeRawContent(o.generateUriClientArgs()) } + log.Debug().Msg("Aquisting") // Handle errors @@ -158,6 +159,7 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaClient *gitea.Client, ctx.Redirect(o.redirectIfExists, fasthttp.StatusTemporaryRedirect) return true } + log.Debug().Msg("Handling error") // Set the MIME type @@ -200,6 +202,7 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaClient *gitea.Client, html.ReturnErrorPage(ctx, fasthttp.StatusInternalServerError) return true } + log.Debug().Msg("Sending response") if res != nil && res.Header.ContentLength() <= fileCacheSizeLimit && ctx.Err() == nil {