Skip to content

Commit

Permalink
Fix usage of WOODPECKER_DATABASE_DATASOURCE_FILE (#3404)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
3 people committed Feb 26, 2024
1 parent c3e4c14 commit 65a429d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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"
}
4 changes: 2 additions & 2 deletions docker/Dockerfile.server.alpine.multiarch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.server.multiarch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/30-administration/10-server-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 65a429d

Please sign in to comment.