diff --git a/cmd/server/flags.go b/cmd/server/flags.go index d90f14f67..d3356ac73 100644 --- a/cmd/server/flags.go +++ b/cmd/server/flags.go @@ -219,7 +219,7 @@ var flags = append([]cli.Flag{ EnvVars: []string{"WOODPECKER_DATABASE_DATASOURCE"}, Name: "datasource", Usage: "database driver configuration string", - Value: "woodpecker.sqlite", + Value: datasourceDefaultValue(), FilePath: os.Getenv("WOODPECKER_DATABASE_DATASOURCE_FILE"), }, &cli.StringFlag{ @@ -510,3 +510,13 @@ var flags = append([]cli.Flag{ Usage: "Flag to decrypt all encrypted data and disable encryption on server", }, }, logger.GlobalLoggerFlags...) + +// If woodpecker is running inside a container the default value for +// the datasource is different from running outside a container. +func datasourceDefaultValue() string { + _, found := os.LookupEnv("WOODPECKER_IN_CONTAINER") + if found { + return "/var/lib/woodpecker/woodpecker.sqlite" + } + return "woodpecker.sqlite" +} diff --git a/docker/Dockerfile.server.alpine.multiarch b/docker/Dockerfile.server.alpine.multiarch index c2513ab35..2454b557d 100644 --- a/docker/Dockerfile.server.alpine.multiarch +++ b/docker/Dockerfile.server.alpine.multiarch @@ -6,8 +6,8 @@ ENV CA_CERTIFICATES_VERSION="20230506-r0" ARG TARGETOS TARGETARCH RUN apk add -U --no-cache ca-certificates=${CA_CERTIFICATES_VERSION} ENV GODEBUG=netdns=go -ENV WOODPECKER_DATABASE_DATASOURCE=/var/lib/woodpecker/woodpecker.sqlite -ENV WOODPECKER_DATABASE_DRIVER=sqlite3 +# Internal setting do NOT change! Signals that woodpecker is running inside a container +ENV WOODPECKER_IN_CONTAINER=true ENV XDG_CACHE_HOME=/var/lib/woodpecker ENV XDG_DATA_HOME=/var/lib/woodpecker EXPOSE 8000 9000 80 443 diff --git a/docker/Dockerfile.server.multiarch b/docker/Dockerfile.server.multiarch index 28afba519..3bf86a3be 100644 --- a/docker/Dockerfile.server.multiarch +++ b/docker/Dockerfile.server.multiarch @@ -3,8 +3,8 @@ FROM --platform=$BUILDPLATFORM docker.io/golang:1.22 AS certs FROM scratch ARG TARGETOS TARGETARCH ENV GODEBUG=netdns=go -ENV WOODPECKER_DATABASE_DATASOURCE=/var/lib/woodpecker/woodpecker.sqlite -ENV WOODPECKER_DATABASE_DRIVER=sqlite3 +# Internal setting do NOT change! Signals that woodpecker is running inside a container +ENV WOODPECKER_IN_CONTAINER=true ENV XDG_CACHE_HOME=/var/lib/woodpecker ENV XDG_DATA_HOME=/var/lib/woodpecker EXPOSE 8000 9000 80 443 diff --git a/docs/docs/30-administration/10-server-config.md b/docs/docs/30-administration/10-server-config.md index 7d38c75a2..f9cf1fe94 100644 --- a/docs/docs/30-administration/10-server-config.md +++ b/docs/docs/30-administration/10-server-config.md @@ -419,7 +419,7 @@ The database driver name. Possible values are `sqlite3`, `mysql` or `postgres`. ### `WOODPECKER_DATABASE_DATASOURCE` -> Default: `woodpecker.sqlite` +> Default: `woodpecker.sqlite` if not running inside a container, `/var/lib/woodpecker/woodpecker.sqlite` if running inside a container The database connection string. The default value is the path of the embedded SQLite database file.