1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00

Fix usage of WOODPECKER_DATABASE_DATASOURCE_FILE (#3404)

fixes #3389

Set variable to let server detect if it's deployed within a container
image.
Set the default database connection based on this.

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com>
This commit is contained in:
smainz 2024-02-26 20:12:41 +01:00 committed by GitHub
parent c3e4c14c23
commit 65a429d24a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 6 deletions

View File

@ -219,7 +219,7 @@ var flags = append([]cli.Flag{
EnvVars: []string{"WOODPECKER_DATABASE_DATASOURCE"}, EnvVars: []string{"WOODPECKER_DATABASE_DATASOURCE"},
Name: "datasource", Name: "datasource",
Usage: "database driver configuration string", Usage: "database driver configuration string",
Value: "woodpecker.sqlite", Value: datasourceDefaultValue(),
FilePath: os.Getenv("WOODPECKER_DATABASE_DATASOURCE_FILE"), FilePath: os.Getenv("WOODPECKER_DATABASE_DATASOURCE_FILE"),
}, },
&cli.StringFlag{ &cli.StringFlag{
@ -510,3 +510,13 @@ var flags = append([]cli.Flag{
Usage: "Flag to decrypt all encrypted data and disable encryption on server", Usage: "Flag to decrypt all encrypted data and disable encryption on server",
}, },
}, logger.GlobalLoggerFlags...) }, 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"
}

View File

@ -6,8 +6,8 @@ ENV CA_CERTIFICATES_VERSION="20230506-r0"
ARG TARGETOS TARGETARCH ARG TARGETOS TARGETARCH
RUN apk add -U --no-cache ca-certificates=${CA_CERTIFICATES_VERSION} RUN apk add -U --no-cache ca-certificates=${CA_CERTIFICATES_VERSION}
ENV GODEBUG=netdns=go ENV GODEBUG=netdns=go
ENV WOODPECKER_DATABASE_DATASOURCE=/var/lib/woodpecker/woodpecker.sqlite # Internal setting do NOT change! Signals that woodpecker is running inside a container
ENV WOODPECKER_DATABASE_DRIVER=sqlite3 ENV WOODPECKER_IN_CONTAINER=true
ENV XDG_CACHE_HOME=/var/lib/woodpecker ENV XDG_CACHE_HOME=/var/lib/woodpecker
ENV XDG_DATA_HOME=/var/lib/woodpecker ENV XDG_DATA_HOME=/var/lib/woodpecker
EXPOSE 8000 9000 80 443 EXPOSE 8000 9000 80 443

View File

@ -3,8 +3,8 @@ FROM --platform=$BUILDPLATFORM docker.io/golang:1.22 AS certs
FROM scratch FROM scratch
ARG TARGETOS TARGETARCH ARG TARGETOS TARGETARCH
ENV GODEBUG=netdns=go ENV GODEBUG=netdns=go
ENV WOODPECKER_DATABASE_DATASOURCE=/var/lib/woodpecker/woodpecker.sqlite # Internal setting do NOT change! Signals that woodpecker is running inside a container
ENV WOODPECKER_DATABASE_DRIVER=sqlite3 ENV WOODPECKER_IN_CONTAINER=true
ENV XDG_CACHE_HOME=/var/lib/woodpecker ENV XDG_CACHE_HOME=/var/lib/woodpecker
ENV XDG_DATA_HOME=/var/lib/woodpecker ENV XDG_DATA_HOME=/var/lib/woodpecker
EXPOSE 8000 9000 80 443 EXPOSE 8000 9000 80 443

View File

@ -419,7 +419,7 @@ The database driver name. Possible values are `sqlite3`, `mysql` or `postgres`.
### `WOODPECKER_DATABASE_DATASOURCE` ### `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. The database connection string. The default value is the path of the embedded SQLite database file.