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

Conversation

smainz
Copy link
Contributor

@smainz smainz commented Feb 17, 2024

fixes #3389

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

The location of the sqlite3 database file is defined in a config file.
The location of the config file is provided to the woodpecker-server in
an ENV var.
This is done instead of providing the location directly inside an ENV var, as
the config file has the least precedence, so it can be overriden in a
docker-compose.yml file.

Remember: The config file must not have a line break at the end!
@qwerty287 qwerty287 added bug Something isn't working server labels Feb 18, 2024
@qwerty287 qwerty287 added this to the 2.4.0 milestone Feb 18, 2024
Copy link
Contributor

@zc-devs zc-devs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if get rid of WOODPECKER_DATABASE_DRIVER and WOODPECKER_DATABASE_DATASOURCE in Dockerfiles?
There are default values sqlite3 and woodpecker.sqlite respectively. It covers default "test" deployment. If you want sqlite "prod" deployment you should mount volume anyway (set the path) in Docker and Kubernetes. So, there should not be a problem to set it twice. It increase transparency and you can write config in your preferred way (*_FILE or not).

docker/Dockerfile.server.alpine.multiarch Outdated Show resolved Hide resolved
@xoxys
Copy link
Member

xoxys commented Feb 18, 2024

What if get rid of WOODPECKER_DATABASE_DRIVER and WOODPECKER_DATABASE_DATASOURCE in Dockerfiles?

I would prefer this way as well.

@smainz
Copy link
Contributor Author

smainz commented Feb 18, 2024

Lets see, what the options are:

  1. Do not change the code and just document, that you have to unset the env var WOODPECKER_DATABASE_DATASOURCE if you want to provide the datasource via _FILE: non breaking, but a bit ugly
  2. Change the way the default datasource config woodpecker.sqlite is overriden in the docker image as show in the first commit: non breaking, not totaly obvious why the config is done in that way, leaves garbage file in the image, if not used
  3. Remove the env vars WOODPECKER_DATABASE_DRIVER and WOODPECKER_DATABASE_DATASOURCE completely in the Dockerfile: probably breaks existing installs which did rely on this, Potential to loose data in this situation (new woodpecker.sqlite file wil be created in current directory), Possibly some frustration with new users which mount a volume to /var/lib/woodpecker, but do not define WOODPECKER_DATABASE_DATASOURCE or WOODPECKER_DATABASE_DATASOURCE_FILE
  4. Remove the env vars WOODPECKER_DATABASE_DRIVER and WOODPECKER_DATABASE_DATASOURCE completely in the Dockerfile and change the hard coded default from woodpecker.sqlite to /var/lib/woodpecker/woodpecker.sqlite: Will break installs not running in the container and relying on the default config (development and testing most probably)

Number 3. would make the docker install compatible with the docs:

### `WOODPECKER_DATABASE_DATASOURCE`
> Default: `woodpecker.sqlite`

As it looks, the intended place for a volume to be mounted is /var/lib/woodpecker as XDG_CACHE_HOME and
ENV XDG_DATA_HOME also point to it.

Did I miss another option?

@smainz
Copy link
Contributor Author

smainz commented Feb 19, 2024

Any ideas about the direction?

As it is planned for 2.4 it should not be breaking (for end-users) which makes it 2. or 4.

@zc-devs
Copy link
Contributor

zc-devs commented Feb 19, 2024

another option?

  1. Make FR/PR/fork into/of urfave/cli with adjustable priorities and prefer *_FILE here :)

Edit 1

As it is planned for 2.4 it should not be breaking (for end-users) which makes it 2. or 4.
4. Will break installs not running in the container and relying on the default config

There is non-breaking 1.

Edit 2
However, documentation says
Keep in mind that when the original environment variable gets specified at the same time it will override the value read from the file.
So, works as intended :)

Edit 3
I'm for moving to the 3.x milestone and option 3. For now there is a workaround (option 1).

@smainz
Copy link
Contributor Author

smainz commented Feb 19, 2024

Just collecting what needs to be done for 3.:

  • Update documentation for docker install
  • Update dockercompose.example.yml
  • Create PR for woodpecker/helm to add ENV vars in values.yml
  • Add info to migrations.md docs
  • Change Dockerfile.server.xxx (2 files)

All but the last are non breaking and could be done right now

Copy link
Member

@6543 6543 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm against the current change!

this will end in each "important" setting being it's own file :/

we should rather switch to a lib that supports config files written in yaml, toml or json...

@smainz smainz changed the title Read datasource config from file when run in docker WIP: Read datasource config from file when run in docker Feb 20, 2024
@smainz
Copy link
Contributor Author

smainz commented Feb 20, 2024

this will end in each "important" setting being it's own file :/

we should rather switch to a lib that supports config files written in yaml, toml or json...

It is not about having a config file for settings, the existing means are well suited. The only thing I want to achieve is to be able to keep secrets out of the docker-compose or .env file (kept in a git repo) but to mount them into the container.

Could be compared to

  environment:
    DOCKER_PASSWORD:
       from_secret docker_password

in a pipeline.

@6543
Copy link
Member

6543 commented Feb 20, 2024

well that is all fine ... but I would then implement the WOODPECKER_DATABASE_DATASOURCE_FILE as how all other_FILE things are implemented and dont change the dockerfile ...

@6543
Copy link
Member

6543 commented Feb 20, 2024

#3419

@6543
Copy link
Member

6543 commented Feb 20, 2024

PS: still thanks for contributing you valuable time and try to fix it! :)

@smainz
Copy link
Contributor Author

smainz commented Feb 21, 2024

PS: still thanks for contributing you valuable time and try to fix it! :)

I should say thank you for woodpecker-ci.

@smainz
Copy link
Contributor Author

smainz commented Feb 22, 2024

PR updated to use the same config file location as the agent does.

I still prefere this PR over #3419, as it keeps the same semantic as all other "_FILE" env vars which is:

Keep in mind that when the original environment variable gets specified at the same time it will override the value read from the file.

@smainz smainz changed the title WIP: Read datasource config from file when run in docker Read datasource config from file when run in docker Feb 22, 2024
@anbraten
Copy link
Member

anbraten commented Feb 22, 2024

I would also stick to not adding the _FILE cli-argument again. Creating the folder is a bit "ugly" on the other hand. What do you think about setting sth like ENV IN_CONTAINER=true and in case of that use a different default in go?

@smainz
Copy link
Contributor Author

smainz commented Feb 22, 2024

I would also stick to not adding the _FILE cli-argument again. Creating the folder is a bit "ugly" on the other hand. What do you think about setting sth like ENV IN_CONTAINER=true and in case of that use a different default in go?

If this is the option everyone agrees to, i can implement it that way:
If IN_CONTAINER is set, the default will be /var/lib/woodpecker/woodpecker.sqlite, otherwise it will be woodpecker.sqlite.

@anbraten
Copy link
Member

Yes that's what I had in mind. @6543 What do you think?

@6543
Copy link
Member

6543 commented Feb 22, 2024

Ack

@smainz
Copy link
Contributor Author

smainz commented Feb 22, 2024

WOODPECKER_IN_CONTAINER is not documented in server settings as I consider this an implementation detail.

cmd/server/flags.go Show resolved Hide resolved
cmd/server/flags.go Outdated Show resolved Hide resolved
cmd/server/flags.go Show resolved Hide resolved
cmd/server/flags.go Show resolved Hide resolved
@6543
Copy link
Member

6543 commented Feb 22, 2024

WOODPECKER_IN_CONTAINER is not documented in server settings as I consider this an implementation detail.

you can even "hide" it in the cli help menue too ... (flag option) ... and document it in code why it's hidden

it's done outside of urfave/cli 👍

@woodpecker-bot
Copy link
Collaborator

woodpecker-bot commented Feb 23, 2024

Deployment of preview was torn down

docker/Dockerfile.server.alpine.multiarch Outdated Show resolved Hide resolved
docker/Dockerfile.server.multiarch Outdated Show resolved Hide resolved
docker/Dockerfile.server.alpine.multiarch Show resolved Hide resolved
cmd/server/flags.go Outdated Show resolved Hide resolved
6543 and others added 2 commits February 26, 2024 19:35
Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com>
@6543 6543 changed the title Read datasource config from file when run in docker determine default datababase connection based if in or outside container deployment Feb 26, 2024
@6543 6543 changed the title determine default datababase connection based if in or outside container deployment Determining default database connection based on deployment method Feb 26, 2024
@anbraten anbraten changed the title Determining default database connection based on deployment method Fix usage of WOODPECKER_DATABASE_DATASOURCE_FILE Feb 26, 2024
@6543 6543 enabled auto-merge (squash) February 26, 2024 19:08
@6543 6543 disabled auto-merge February 26, 2024 19:12
@6543 6543 merged commit 65a429d into woodpecker-ci:main Feb 26, 2024
6 of 7 checks passed
@woodpecker-bot woodpecker-bot mentioned this pull request Feb 26, 2024
1 task
anbraten added a commit that referenced this pull request Mar 19, 2024
## [2.4.0](https://github.com/woodpecker-ci/woodpecker/releases/tag/2.4.0) - 2024-03-19

### 🔒 Security

- Improve security context handling
[[#3482](#3482)]
- fix(deps): update module github.com/moby/moby to v24.0.9+incompatible
[[#3323](#3323)]

### ✨ Features

- Cli setup command
[[#3384](#3384)]
- Add bitbucket datacenter (server) support
[[#2503](#2503)]
- Cli updater
[[#3382](#3382)]

### 📚 Documentation

- Delete docs for v0.15.x
[[#3508](#3508)]
- Add deployment plugin
[[#3495](#3495)]
- Bump follow-redirects and fix broken anchors
[[#3488](#3488)]
- fix: plugin doc page not found
[[#3480](#3480)]
- Documentation improvements
[[#3376](#3376)]
- fix(deps): update docs npm deps non-major
[[#3455](#3455)]
- Add "Sonatype Nexus" plugin
[[#3446](#3446)]
- Add blog post
[[#3439](#3439)]
- Add "Gradle Wrapper Validation" plugin
[[#3435](#3435)]
- Add blog post
[[#3410](#3410)]
- Extend core ideas documentation
[[#3405](#3405)]
- docs: fix contributions link
[[#3363](#3363)]
- Update/fix some docs
[[#3359](#3359)]
- chore(deps): update dependency marked to v12
[[#3325](#3325)]

### 🐛 Bug Fixes

- Fix skip setup for some general cli commands
[[#3498](#3498)]
- Move generic agent flags to cmd/agent/core
[[#3484](#3484)]
- Fix usage of WOODPECKER_DATABASE_DATASOURCE_FILE
[[#3404](#3404)]
- Set pull-request id and labels on pr-closed event
[[#3442](#3442)]
- Update org name on login
[[#3409](#3409)]
- Do not alter secret key upper-/lowercase
[[#3375](#3375)]
- fix: can't run multiple services on k8s
[[#3395](#3395)]
- Fix agent polling
[[#3378](#3378)]
- Remove empty strings from slice before parsing agent config
[[#3387](#3387)]
- Set correct link for commit
[[#3368](#3368)]
- Fix schema links
[[#3369](#3369)]
- Fix correctly handle gitlab pr closed events
[[#3362](#3362)]
- fix: update schema event_enum to remove error warning when.event
[[#3357](#3357)]
- Fix version check on next
[[#3340](#3340)]
- Ignore gitlab merge request events without code changes
[[#3338](#3338)]
- Ignore gitlab push events without commits
[[#3339](#3339)]
- Consider gitlab inherited permissions
[[#3308](#3308)]
- fix: agent panic when node is terminated during step execution
[[#3331](#3331)]

### 📈 Enhancement

- Enable golangci linter gomnd
[[#3171](#3171)]
- Apply "grpcnotrace" go build tag
[[#3448](#3448)]
- Simplify store interfaces
[[#3437](#3437)]
- Deprecate alternative names on secrets
[[#3406](#3406)]
- Store workflows/steps for blocked pipeline
[[#2757](#2757)]
- Parse email from Gitea webhook
[[#3420](#3420)]
- Replace http types on forge interface
[[#3374](#3374)]
- Prevent agent deletion when it's still running tasks
[[#3377](#3377)]
- Refactor internal services
[[#915](#915)]
- Lint for event filter and deprecate `exclude`
[[#3222](#3222)]
- Allow editing all environment variables in pipeline popups
[[#3314](#3314)]
- Parse backend options in backend
[[#3227](#3227)]
- Make agent usable for external backends
[[#3270](#3270)]
- Add no branches text
[[#3312](#3312)]
- Add loading spinner to repo list
[[#3310](#3310)]

### Misc

- Post on mastodon when releasing a new version
[[#3509](#3509)]
- chore(deps): update dependency alpine_3_18/ca-certificates to
v20240226
[[#3501](#3501)]
- fix(deps): update module github.com/google/go-github/v59 to v60
[[#3493](#3493)]
- fix(deps): update dependency @intlify/unplugin-vue-i18n to v3
[[#3492](#3492)]
- chore(deps): update dependency vue-tsc to v2
[[#3491](#3491)]
- chore(deps): update dependency eslint-config-airbnb-typescript to v18
[[#3490](#3490)]
- chore(deps): update web npm deps non-major
[[#3489](#3489)]
- fix(deps): update golang (packages)
[[#3486](#3486)]
- fix(deps): update module google.golang.org/protobuf to v1.33.0
[security]
[[#3487](#3487)]
- chore(deps): update docker.io/techknowlogick/xgo docker tag to
go-1.22.1
[[#3476](#3476)]
- chore(deps): update docker.io/golang docker tag to v1.22.1
[[#3475](#3475)]
- Update prettier version
[[#3471](#3471)]
- chore(deps): update woodpeckerci/plugin-ready-release-go docker tag to
v1.1.0 [[#3464](#3464)]
- chore(deps): lock file maintenance
[[#3465](#3465)]
- chore(deps): update postgres docker tag to v16.2
[[#3461](#3461)]
- chore(deps): update lycheeverse/lychee docker tag to v0.14.3
[[#3429](#3429)]
- fix(deps): update golang (packages)
[[#3430](#3430)]
- More `when` filters
[[#3407](#3407)]
- Apply `documentation`/`ui` label to corresponding renovate updates
[[#3400](#3400)]
- chore(deps): update dependency eslint-plugin-simple-import-sort to v12
[[#3396](#3396)]
- chore(deps): update typescript-eslint monorepo to v7 (major)
[[#3397](#3397)]
- fix(deps): update module github.com/google/go-github/v58 to v59
[[#3398](#3398)]
- chore(deps): update docker.io/techknowlogick/xgo docker tag to
go-1.22.0
[[#3392](#3392)]
- chore(deps): update docker.io/golang docker tag
[[#3391](#3391)]
- fix(deps): update golang (packages)
[[#3393](#3393)]
- chore(deps): update docker.io/woodpeckerci/plugin-docker-buildx docker
tag to v3.1.0
[[#3394](#3394)]
- Add link checking
[[#3371](#3371)]
- Apply `dependencies` label to all PRs
[[#3358](#3358)]
- chore(deps): update docker.io/woodpeckerci/plugin-docker-buildx docker
tag to v3.0.1
[[#3324](#3324)]

---------

Co-authored-by: 6543 <m.huber@kithara.com>
Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting WOODPECKER_DATABASE_DATASOURCE_FILE does not work as expected when using docker image
7 participants