mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 14:26:58 +00:00
Merge branch 'main' into issue115
This commit is contained in:
commit
06bde50161
6 changed files with 21 additions and 12 deletions
|
@ -1,5 +1,3 @@
|
||||||
branches: main
|
|
||||||
|
|
||||||
pipeline:
|
pipeline:
|
||||||
# use vendor to cache dependencies
|
# use vendor to cache dependencies
|
||||||
vendor:
|
vendor:
|
||||||
|
@ -19,7 +17,7 @@ pipeline:
|
||||||
|
|
||||||
build:
|
build:
|
||||||
group: compliant
|
group: compliant
|
||||||
image: a6543/golang_just
|
image: codeberg.org/6543/docker-images/golang_just
|
||||||
commands:
|
commands:
|
||||||
- go version
|
- go version
|
||||||
- just build
|
- just build
|
||||||
|
@ -39,7 +37,7 @@ pipeline:
|
||||||
|
|
||||||
build-tag:
|
build-tag:
|
||||||
group: compliant
|
group: compliant
|
||||||
image: a6543/golang_just
|
image: codeberg.org/6543/docker-images/golang_just
|
||||||
commands:
|
commands:
|
||||||
- go version
|
- go version
|
||||||
- just build-tag ${CI_COMMIT_TAG##v}
|
- just build-tag ${CI_COMMIT_TAG##v}
|
||||||
|
@ -48,13 +46,13 @@ pipeline:
|
||||||
|
|
||||||
test:
|
test:
|
||||||
group: test
|
group: test
|
||||||
image: a6543/golang_just
|
image: codeberg.org/6543/docker-images/golang_just
|
||||||
commands:
|
commands:
|
||||||
- just test
|
- just test
|
||||||
|
|
||||||
integration-tests:
|
integration-tests:
|
||||||
group: test
|
group: test
|
||||||
image: a6543/golang_just
|
image: codeberg.org/6543/docker-images/golang_just
|
||||||
commands:
|
commands:
|
||||||
- just integration
|
- just integration
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -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.
|
- `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.
|
- `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.
|
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
|
## Contributing to the development
|
||||||
|
|
|
@ -415,7 +415,7 @@ func SetupCertificates(mainDomainSuffix []byte, dnsProvider string, acmeConfig *
|
||||||
|
|
||||||
acmeClient, err = lego.NewClient(acmeConfig)
|
acmeClient, err = lego.NewClient(acmeConfig)
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
err = acmeClient.Challenge.SetTLSALPN01Provider(AcmeTLSChallengeProvider{challengeCache})
|
err = acmeClient.Challenge.SetTLSALPN01Provider(AcmeTLSChallengeProvider{challengeCache})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -86,7 +86,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
|
||||||
// also disallow search indexing and add a Link header to the canonical URL.
|
// 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 {
|
tryBranch := func(log zerolog.Logger, repo, branch string, path []string, canonicalLink string) bool {
|
||||||
if repo == "" {
|
if repo == "" {
|
||||||
log.Debug().Msg("tryBranch: repo is empty")
|
log.Warn().Msg("tryBranch: repo is empty")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
|
||||||
// Check if the branch exists, otherwise treat it as a file path
|
// Check if the branch exists, otherwise treat it as a file path
|
||||||
branchTimestampResult := upstream.GetBranchTimestamp(giteaClient, targetOwner, repo, branch, branchTimestampCache)
|
branchTimestampResult := upstream.GetBranchTimestamp(giteaClient, targetOwner, repo, branch, branchTimestampCache)
|
||||||
if branchTimestampResult == nil {
|
if branchTimestampResult == nil {
|
||||||
log.Debug().Msg("tryBranch: branch doesn't exist")
|
log.Warn().Msg("tryBranch: branch doesn't exist")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Msg("tryBranch, now trying upstream 7 %s")
|
log.Info().Msg("tryBranch, now trying upstream 7")
|
||||||
tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost,
|
tryUpstream(ctx, giteaClient, mainDomainSuffix, trimmedHost,
|
||||||
targetOptions, targetOwner, targetRepo, targetBranch, targetPath,
|
targetOptions, targetOwner, targetRepo, targetBranch, targetPath,
|
||||||
canonicalDomainCache, branchTimestampCache, fileResponseCache)
|
canonicalDomainCache, branchTimestampCache, fileResponseCache)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"codeberg.org/codeberg/pages/server/cache"
|
"codeberg.org/codeberg/pages/server/cache"
|
||||||
"codeberg.org/codeberg/pages/server/gitea"
|
"codeberg.org/codeberg/pages/server/gitea"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type branchTimestamp struct {
|
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
|
// 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)
|
// (or nil if the branch doesn't exist)
|
||||||
func GetBranchTimestamp(giteaClient *gitea.Client, owner, repo, branch string, branchTimestampCache cache.SetGetKey) *branchTimestamp {
|
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, ok := branchTimestampCache.Get(owner + "/" + repo + "/" + branch); ok {
|
||||||
if result == nil {
|
if result == nil {
|
||||||
|
log.Debug().Msg("branchTimestampCache found item, but result is empty")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
log.Debug().Msg("branchTimestampCache found item, returning result")
|
||||||
return result.(*branchTimestamp)
|
return result.(*branchTimestamp)
|
||||||
}
|
}
|
||||||
result := &branchTimestamp{
|
result := &branchTimestamp{
|
||||||
|
@ -32,16 +36,20 @@ func GetBranchTimestamp(giteaClient *gitea.Client, owner, repo, branch string, b
|
||||||
// Get default branch
|
// Get default branch
|
||||||
defaultBranch, err := giteaClient.GiteaGetRepoDefaultBranch(owner, repo)
|
defaultBranch, err := giteaClient.GiteaGetRepoDefaultBranch(owner, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Err(err).Msg("Could't fetch default branch from repository")
|
||||||
_ = branchTimestampCache.Set(owner+"/"+repo+"/", nil, defaultBranchCacheTimeout)
|
_ = branchTimestampCache.Set(owner+"/"+repo+"/", nil, defaultBranchCacheTimeout)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
log.Debug().Msg("Succesfully fetched default branch from Gitea")
|
||||||
result.Branch = defaultBranch
|
result.Branch = defaultBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
timestamp, err := giteaClient.GiteaGetRepoBranchTimestamp(owner, repo, result.Branch)
|
timestamp, err := giteaClient.GiteaGetRepoBranchTimestamp(owner, repo, result.Branch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Err(err).Msg("Could not get latest commit's timestamp from branch")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
log.Debug().Msg("Succesfully fetched latest commit's timestamp from branch, adding to cache")
|
||||||
result.Timestamp = timestamp
|
result.Timestamp = timestamp
|
||||||
_ = branchTimestampCache.Set(owner+"/"+repo+"/"+branch, result, branchExistenceCacheTimeout)
|
_ = branchTimestampCache.Set(owner+"/"+repo+"/"+branch, result, branchExistenceCacheTimeout)
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -85,6 +85,7 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaClient *gitea.Client,
|
||||||
} else {
|
} else {
|
||||||
res, err = giteaClient.ServeRawContent(o.generateUriClientArgs())
|
res, err = giteaClient.ServeRawContent(o.generateUriClientArgs())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Msg("Aquisting")
|
log.Debug().Msg("Aquisting")
|
||||||
|
|
||||||
// Handle errors
|
// Handle errors
|
||||||
|
@ -158,6 +159,7 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaClient *gitea.Client,
|
||||||
ctx.Redirect(o.redirectIfExists, fasthttp.StatusTemporaryRedirect)
|
ctx.Redirect(o.redirectIfExists, fasthttp.StatusTemporaryRedirect)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Msg("Handling error")
|
log.Debug().Msg("Handling error")
|
||||||
|
|
||||||
// Set the MIME type
|
// Set the MIME type
|
||||||
|
@ -200,6 +202,7 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaClient *gitea.Client,
|
||||||
html.ReturnErrorPage(ctx, fasthttp.StatusInternalServerError)
|
html.ReturnErrorPage(ctx, fasthttp.StatusInternalServerError)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Msg("Sending response")
|
log.Debug().Msg("Sending response")
|
||||||
|
|
||||||
if res != nil && res.Header.ContentLength() <= fileCacheSizeLimit && ctx.Err() == nil {
|
if res != nil && res.Header.ContentLength() <= fileCacheSizeLimit && ctx.Err() == nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue