mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-25 19:31:05 +00: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:
parent
c3e4c14c23
commit
65a429d24a
4 changed files with 16 additions and 6 deletions
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in a new issue