Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of WOODPECKER_DATABASE_DATASOURCE_FILE #3404

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 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,14 @@ 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.
anbraten marked this conversation as resolved.
Show resolved Hide resolved
func datasourceDefaultValue() string {
_, found := os.LookupEnv("WOODPECKER_IN_CONTAINER")
anbraten marked this conversation as resolved.
Show resolved Hide resolved
if found {
return "/var/lib/woodpecker/woodpecker.sqlite"
anbraten marked this conversation as resolved.
Show resolved Hide resolved
} else {
return "woodpecker.sqlite"
anbraten marked this conversation as resolved.
Show resolved Hide resolved
}
}
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
anbraten marked this conversation as resolved.
Show resolved Hide resolved
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