mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2024-06-09 12:40:53 +02:00
Compare commits
5 Commits
5806277863
...
368b7c9f41
Author | SHA1 | Date | |
---|---|---|---|
|
368b7c9f41 | ||
|
52bc59aee9 | ||
|
ca9433e0ea | ||
|
d09c6e1218 | ||
|
8cba7f9c8a |
|
@ -29,10 +29,11 @@ steps:
|
||||||
|
|
||||||
docker-dryrun:
|
docker-dryrun:
|
||||||
depends_on: vendor
|
depends_on: vendor
|
||||||
image: plugins/kaniko:1.8.8
|
image: woodpeckerci/plugin-docker-buildx:3.2.1
|
||||||
settings:
|
settings:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
no_push: true
|
platforms: linux/amd64
|
||||||
|
dry-run: true
|
||||||
tags: latest
|
tags: latest
|
||||||
when:
|
when:
|
||||||
- event: [push, pull_request]
|
- event: [push, pull_request]
|
||||||
|
@ -98,10 +99,11 @@ steps:
|
||||||
|
|
||||||
docker-next:
|
docker-next:
|
||||||
depends_on: vendor
|
depends_on: vendor
|
||||||
image: plugins/kaniko:1.8.8
|
image: woodpeckerci/plugin-docker-buildx:3.2.1
|
||||||
settings:
|
settings:
|
||||||
registry: codeberg.org
|
registry: codeberg.org
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
platforms: linux/amd64,arm64
|
||||||
repo: codeberg.org/codeberg/pages-server
|
repo: codeberg.org/codeberg/pages-server
|
||||||
tags: next
|
tags: next
|
||||||
username:
|
username:
|
||||||
|
@ -114,10 +116,11 @@ steps:
|
||||||
|
|
||||||
docker-tag:
|
docker-tag:
|
||||||
depends_on: vendor
|
depends_on: vendor
|
||||||
image: plugins/kaniko:1.8.8
|
image: woodpeckerci/plugin-docker-buildx:3.2.1
|
||||||
settings:
|
settings:
|
||||||
registry: codeberg.org
|
registry: codeberg.org
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
platforms: linux/amd64,arm64
|
||||||
repo: codeberg.org/codeberg/pages-server
|
repo: codeberg.org/codeberg/pages-server
|
||||||
tags: [latest, '${CI_COMMIT_TAG}']
|
tags: [latest, '${CI_COMMIT_TAG}']
|
||||||
username:
|
username:
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
when:
|
when:
|
||||||
- event: pull_request
|
- event: pull_request
|
||||||
- event: push
|
- event: push
|
||||||
branch: renovate/*
|
branch:
|
||||||
|
- ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
- renovate/**
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
lint:
|
lint:
|
||||||
|
@ -25,6 +27,16 @@ steps:
|
||||||
- event: push
|
- event: push
|
||||||
branch: renovate/*
|
branch: renovate/*
|
||||||
|
|
||||||
|
yamllint:
|
||||||
|
image: pipelinecomponents/yamllint:0.31.1
|
||||||
|
depends_on: []
|
||||||
|
commands:
|
||||||
|
- yamllint .
|
||||||
|
when:
|
||||||
|
- event: pull_request
|
||||||
|
- event: push
|
||||||
|
branch: renovate/*
|
||||||
|
|
||||||
prettier:
|
prettier:
|
||||||
image: docker.io/woodpeckerci/plugin-prettier:0.1.0
|
image: docker.io/woodpeckerci/plugin-prettier:0.1.0
|
||||||
depends_on: []
|
depends_on: []
|
||||||
|
|
19
.yamllint.yaml
Normal file
19
.yamllint.yaml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
comments:
|
||||||
|
require-starting-space: false
|
||||||
|
ignore-shebangs: true
|
||||||
|
min-spaces-from-content: 1
|
||||||
|
braces:
|
||||||
|
min-spaces-inside: 1
|
||||||
|
max-spaces-inside: 1
|
||||||
|
document-start:
|
||||||
|
present: false
|
||||||
|
indentation:
|
||||||
|
spaces: 2
|
||||||
|
indent-sequences: true
|
||||||
|
line-length:
|
||||||
|
max: 256
|
||||||
|
new-lines:
|
||||||
|
type: unix
|
31
Dockerfile
31
Dockerfile
|
@ -1,14 +1,35 @@
|
||||||
FROM techknowlogick/xgo as build
|
# Set the default Go version as a build argument
|
||||||
|
ARG XGO="go-1.21.x"
|
||||||
|
|
||||||
WORKDIR /workspace
|
# Use xgo (a Go cross-compiler tool) as build image
|
||||||
|
FROM --platform=$BUILDPLATFORM techknowlogick/xgo:${XGO} as build
|
||||||
|
|
||||||
COPY . .
|
# Set the working directory and copy the source code
|
||||||
RUN CGO_ENABLED=1 go build -tags 'sqlite sqlite_unlock_notify netgo' -ldflags '-s -w -extldflags "-static" -linkmode external' .
|
WORKDIR /go/src/codeberg.org/codeberg/pages
|
||||||
|
COPY . /go/src/codeberg.org/codeberg/pages
|
||||||
|
|
||||||
|
# Set the target architecture (can be set using --build-arg), buildx set it automatically
|
||||||
|
ARG TARGETOS TARGETARCH
|
||||||
|
|
||||||
|
# Build the binary using xgo
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
--mount=type=cache,target=/go/pkg \
|
||||||
|
GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=1 \
|
||||||
|
xgo -x -v --targets=${TARGETOS}/${TARGETARCH} -tags='sqlite sqlite_unlock_notify netgo' -ldflags='-s -w -extldflags "-static" -linkmode external' -out pages .
|
||||||
|
|
||||||
|
# Use a scratch image as the base image for the final container,
|
||||||
|
# which will contain only the built binary and the CA certificates
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=build /workspace/pages /pages
|
|
||||||
|
# Copy the built binary and the CA certificates from the build container to the final container
|
||||||
|
COPY --from=build /go/src/codeberg.org/codeberg/pages/ /pages
|
||||||
COPY --from=build \
|
COPY --from=build \
|
||||||
/etc/ssl/certs/ca-certificates.crt \
|
/etc/ssl/certs/ca-certificates.crt \
|
||||||
/etc/ssl/certs/ca-certificates.crt
|
/etc/ssl/certs/ca-certificates.crt
|
||||||
|
|
||||||
|
# Expose ports 80 and 443 for the built binary to listen on
|
||||||
|
EXPOSE 80/tcp
|
||||||
|
EXPOSE 443/tcp
|
||||||
|
|
||||||
|
# Set the entrypoint for the container to the built binary
|
||||||
ENTRYPOINT ["/pages"]
|
ENTRYPOINT ["/pages"]
|
||||||
|
|
4
Justfile
4
Justfile
|
@ -1,13 +1,13 @@
|
||||||
CGO_FLAGS := '-extldflags "-static" -linkmode external'
|
CGO_FLAGS := '-extldflags "-static" -linkmode external'
|
||||||
TAGS := 'sqlite sqlite_unlock_notify netgo'
|
TAGS := 'sqlite sqlite_unlock_notify netgo'
|
||||||
|
|
||||||
dev:
|
dev *FLAGS:
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
set -a # automatically export all variables
|
set -a # automatically export all variables
|
||||||
source .env-dev
|
source .env-dev
|
||||||
set +a
|
set +a
|
||||||
go run -tags '{{TAGS}}' .
|
go run -tags '{{TAGS}}' . {{FLAGS}}
|
||||||
|
|
||||||
build:
|
build:
|
||||||
CGO_ENABLED=1 go build -tags '{{TAGS}}' -ldflags '-s -w {{CGO_FLAGS}}' -v -o build/codeberg-pages-server ./
|
CGO_ENABLED=1 go build -tags '{{TAGS}}' -ldflags '-s -w {{CGO_FLAGS}}' -v -o build/codeberg-pages-server ./
|
||||||
|
|
15
README.md
15
README.md
|
@ -124,3 +124,18 @@ now these pages should work:
|
||||||
- <https://momar.localhost.mock.directory:4430/ci-testing/>
|
- <https://momar.localhost.mock.directory:4430/ci-testing/>
|
||||||
- <https://momar.localhost.mock.directory:4430/pag/@master/>
|
- <https://momar.localhost.mock.directory:4430/pag/@master/>
|
||||||
- <https://mock-pages.codeberg-test.org:4430/README.md>
|
- <https://mock-pages.codeberg-test.org:4430/README.md>
|
||||||
|
|
||||||
|
### Profiling
|
||||||
|
|
||||||
|
> This section is just a collection of commands for quick reference. If you want to learn more about profiling read [this](https://go.dev/doc/diagnostics) article or google `golang profiling`.
|
||||||
|
|
||||||
|
First enable profiling by supplying the cli arg `--enable-profiling` or using the environment variable `EENABLE_PROFILING`.
|
||||||
|
|
||||||
|
Get cpu and mem stats:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go tool pprof -raw -output=cpu.txt 'http://localhost:9999/debug/pprof/profile?seconds=60' &
|
||||||
|
curl -so mem.txt 'http://localhost:9999/debug/pprof/heap?seconds=60'
|
||||||
|
```
|
||||||
|
|
||||||
|
More endpoints are documented here: <https://pkg.go.dev/net/http/pprof>
|
||||||
|
|
12
cli/flags.go
12
cli/flags.go
|
@ -139,6 +139,18 @@ var (
|
||||||
EnvVars: []string{"CONFIG_FILE"},
|
EnvVars: []string{"CONFIG_FILE"},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "enable-profiling",
|
||||||
|
Usage: "enables the go http profiling endpoints",
|
||||||
|
EnvVars: []string{"ENABLE_PROFILING"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "profiling-address",
|
||||||
|
Usage: "specify ip address and port the profiling server should listen on",
|
||||||
|
EnvVars: []string{"PROFILING_ADDRESS"},
|
||||||
|
Value: "localhost:9999",
|
||||||
|
},
|
||||||
|
|
||||||
// ############################
|
// ############################
|
||||||
// ### ACME Client Settings ###
|
// ### ACME Client Settings ###
|
||||||
// ############################
|
// ############################
|
||||||
|
|
21
server/profiling.go
Normal file
21
server/profiling.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func StartProfilingServer(listeningAddress string) {
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: listeningAddress,
|
||||||
|
Handler: http.DefaultServeMux,
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info().Msgf("Starting debug server on %s", listeningAddress)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
log.Fatal().Err(server.ListenAndServe()).Msg("Failed to start debug server")
|
||||||
|
}()
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ package server
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -43,9 +42,6 @@ func Serve(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger().Level(logLevel)
|
log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger().Level(logLevel)
|
||||||
|
|
||||||
foo, _ := json.Marshal(cfg)
|
|
||||||
log.Trace().RawJSON("config", foo).Msg("starting server with config")
|
|
||||||
|
|
||||||
listeningSSLAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)
|
listeningSSLAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)
|
||||||
listeningHTTPAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.HttpPort)
|
listeningHTTPAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.HttpPort)
|
||||||
|
|
||||||
|
@ -133,6 +129,10 @@ func Serve(ctx *cli.Context) error {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.IsSet("enable-profiling") {
|
||||||
|
StartProfilingServer(ctx.String("profiling-address"))
|
||||||
|
}
|
||||||
|
|
||||||
// Create ssl handler based on settings
|
// Create ssl handler based on settings
|
||||||
sslHandler := handler.Handler(cfg.Server, giteaClient, dnsLookupCache, canonicalDomainCache, redirectsCache)
|
sslHandler := handler.Handler(cfg.Server, giteaClient, dnsLookupCache, canonicalDomainCache, redirectsCache)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user