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

Inconsistent value for [repository].ROOT causes errors on git push #25107

Closed
DavidGregory084 opened this issue Jun 6, 2023 · 3 comments · Fixed by #25330
Closed

Inconsistent value for [repository].ROOT causes errors on git push #25107

DavidGregory084 opened this issue Jun 6, 2023 · 3 comments · Fixed by #25330
Labels

Comments

@DavidGregory084
Copy link

Description

I am running gitea via the snap package, and have overridden the systemd unit file to set the --work-path and --custom-path to a mounted volume on my server, since there is no other way that I know about to override the environment variables in the snapcraft.yml.

In /etc/systemd/system/snap.gitea.web.service.d/override.conf:

[Service]
ExecStart=
ExecStart=/usr/bin/snap run gitea.web --config /mnt/mina-gitea-data/custom/conf/app.ini --work-path /mnt/mina-gitea-data --custom-path /mnt/mina-gitea-data/custom
User=git

In the logs for gitea I see the values that I expect:

34 cmd/web.go:105:runWeb() [I] Starting Gitea on PID: 1653
:34 ...ules/setting/time.go:58:loadTimeFrom() [I] Default UI Location is Europe/London
:34 cmd/web.go:159:runWeb() [I] Global init
:34 ...ules/setting/time.go:58:loadTimeFrom() [I] Default UI Location is Europe/London
:34 routers/init.go:118:GlobalInitInstalled() [I] Git Version: 2.17.1 (home: /mnt/mina-gitea-data/data/home)
:34 routers/init.go:119:GlobalInitInstalled() [I] AppPath: /snap/gitea/6474/gitea
:34 routers/init.go:120:GlobalInitInstalled() [I] AppWorkPath: /mnt/mina-gitea-data
:34 routers/init.go:121:GlobalInitInstalled() [I] Custom path: /mnt/mina-gitea-data/custom
:34 routers/init.go:122:GlobalInitInstalled() [I] Log path: /mnt/mina-gitea-data/log
:34 routers/init.go:123:GlobalInitInstalled() [I] Configuration file: /mnt/mina-gitea-data/custom/conf/app.ini
:34 routers/init.go:124:GlobalInitInstalled() [I] Run Mode: Dev
:34 routers/init.go:125:GlobalInitInstalled() [I] Gitea v1.19.3 built with GNU Make 4.1, go1.20.4 : bindata, sqlite, sqlite_unlock_notify, pam, cert

The doctor command shows the Repository Root Path that I expect:

gregory@mina-gitea:~$ sudo runuser -u git -- gitea --config /mnt/mina-gitea-data/custom/conf/app.ini --work-path /mnt/mina-gitea-data/ --custom-path /mnt/mina-gitea-data/custom/ doctor
ERROR: Unable to write logs to provided file due to permissions error: doctor.log
       failed to create sublogger (doctor): open doctor.log: permission denied
WARN: Logging will be disabled
       Use `--log-file` to configure log file location
[1] Check paths and basic configuration
 - [I] Configuration File Path:    "/mnt/mina-gitea-data/custom/conf/app.ini"
 - [I] Repository Root Path:       "/mnt/mina-gitea-data/data/gitea-repositories"
 - [I] Data Root Path:             "/mnt/mina-gitea-data/data"
 - [I] Custom File Root Path:      "/mnt/mina-gitea-data/custom/"
 - [I] Work directory:             "/mnt/mina-gitea-data/"
 - [I] Log Root Path:              "/mnt/mina-gitea-data/log"
OK

However when I push commits to a repository, I receive the following error:

remote: Gitea: Incorrect configuration, no repository directory.
remote: Directory `[repository].ROOT` "/var/snap/gitea/common/data/gitea-repositories" was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository].ROOT` an absolute value.
remote: panic: cannot create context from nil parent

It seems like different bits of gitea disagree about the value of this configuration setting?

Happy to provide more logs/info if needed!

Gitea Version

1.19.3

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.34.1

Operating System

Ubuntu 22.04

How are you running Gitea?

The Gitea server is provisioned using cloud-init and gitea is started using the systemd unit file.

The unit file has been overridden to specify the data paths and user:

[Service]
ExecStart=
ExecStart=/usr/bin/snap run gitea.web --config /mnt/mina-gitea-data/custom/conf/app.ini --work-path /mnt/mina-gitea-data --custom-path /mnt/mina-gitea-data/custom
User=git

It has been given the removable-media permission via snap connect gitea:removable-media before launching.

The entire app.ini can be viewed as part of the cloud-init configuration here.

Database

SQLite

@techknowlogick
Copy link
Member

You may need to run the resync hooks task in the admin dashboard.

@DavidGregory084
Copy link
Author

Hmm I've tried that, but unfortunately it didn't resolve the issue and I still receive the same error when pushing to repositories.

@DavidGregory084
Copy link
Author

DavidGregory084 commented Jun 7, 2023

Looked into this a little further - I think this is because the pre-receive hooks that are generated only apply the --config flag to the gitea binary, which means that they inherit AppWorkPath and CustomPath from the GITEA_WORK_DIR and GITEA_CUSTOM environment variables that are built into in the snap here.

Here's a pre-receive hook from my repository:

#!/usr/bin/env bash
# AUTO GENERATED BY GITEA, DO NOT MODIFY
/snap/gitea/6474/gitea hook --config=/mnt/mina-gitea-data/custom/conf/app.ini pre-receive

@lunny lunny closed this as completed in 2cdf260 Jun 21, 2023
wxiaoguang added a commit to wxiaoguang/gitea that referenced this issue Jun 21, 2023
# The problem

There were many "path tricks":

* By default, Gitea uses its program directory as its work path
* Gitea tries to use the "work path" to guess its "custom path" and
"custom conf (app.ini)"
* Users might want to use other directories as work path
* The non-default work path should be passed to Gitea by GITEA_WORK_DIR
or "--work-path"
* But some Gitea processes are started without these values
    * The "serv" process started by OpenSSH server
    * The CLI sub-commands started by site admin
* The paths are guessed by SetCustomPathAndConf again and again
* The default values of "work path / custom path / custom conf" can be
changed when compiling

# The solution

* Use `InitWorkPathAndCommonConfig` to handle these path tricks, and use
test code to cover its behaviors.
* When Gitea's web server runs, write the WORK_PATH to "app.ini", this
value must be the most correct one, because if this value is not right,
users would find that the web UI doesn't work and then they should be
able to fix it.
* Then all other sub-commands can use the WORK_PATH in app.ini to
initialize their paths.
* By the way, when Gitea starts for git protocol, it shouldn't output
any log, otherwise the git protocol gets broken and client blocks
forever.

The "work path" priority is: WORK_PATH in app.ini > cmd arg --work-path
> env var GITEA_WORK_DIR > builtin default

The "app.ini" searching order is: cmd arg --config > cmd arg "work path
/ custom path" > env var "work path / custom path" > builtin default

## ⚠️ BREAKING

If your instance's "work path / custom path / custom conf" doesn't meet
the requirements (eg: work path must be absolute), Gitea will report a
fatal error and exit. You need to set these values according to the
error log.

----

Close go-gitea#24818
Close go-gitea#24222
Close go-gitea#21606
Close go-gitea#21498
Close go-gitea#25107
Close go-gitea#24981
Maybe close go-gitea#24503

Replace go-gitea#23301
Replace go-gitea#22754

And maybe more
# Conflicts:
#	cmd/web.go
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants