Skip to content

Cannot boot docker image when mount a custom app.ini configuration #2197

Closed
@twang2218

Description

@twang2218
  • Gitea version (or commit ref): Since 2eeae84 (master branch)
  • Git version: 2.8.5
  • Operating system: macOS 10.12.5 + Docker for Mac (17.06)
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

Since commit 2eeae84, which belongs to #1471, the docker image, which I built with TAGS="sqlite" make docker, cannot be booted with an app.ini file mounted, and following error will be shown:

$ docker run -it --rm -p 3001:3000 -v $PWD/conf/sqlite/app.ini:/data/gitea/conf/app.ini gitea/gitea:latest
Generating /data/ssh/ssh_host_ed25519_key...
Jul 22 16:58:03 syslogd started: BusyBox v1.24.2
Generating /data/ssh/ssh_host_rsa_key...
Generating /data/ssh/ssh_host_dsa_key...
Generating /data/ssh/ssh_host_ecdsa_key...
Jul 22 16:58:03 sshd[12]: Server listening on :: port 22.
Jul 22 16:58:03 sshd[12]: Server listening on 0.0.0.0 port 22.
2017/07/22 16:58:03 [...s/setting/setting.go:803 NewContext()] [E] Error saving generated JWT Secret to custom config: rename /data/gitea/conf/app.ini.821764490.tmp /data/gitea/conf/app.ini: device or resource busy
2017/07/22 16:58:04 [...s/setting/setting.go:803 NewContext()] [E] Error saving generated JWT Secret to custom config: rename /data/gitea/conf/app.ini.342639761.tmp /data/gitea/conf/app.ini: device or resource busy
...

After dig into the code, I found it's related to this part of code:

https://github.com/go-gitea/gitea/blob/master/modules/setting/setting.go#L831-L838

		cfgSave.Section("security").Key("INTERNAL_TOKEN").SetValue(InternalToken)

		if err := os.MkdirAll(filepath.Dir(CustomConf), os.ModePerm); err != nil {
			log.Fatal(4, "Failed to create '%s': %v", CustomConf, err)
		}
		if err := cfgSave.SaveTo(CustomConf); err != nil {
			log.Fatal(4, "Error saving generated JWT Secret to custom config: %v", err)
		}

cfgSave.SaveTo() is actually create a temporary file first, then write to the temporary file, after that, it then delete the old file, and rename the temporary file to the deleted file name.

I think this kind of operation causes the problem, as we mount the /data/gitea/conf/app.ini file inside the docker, so rm or rename operation will not be allowed. Here is what I tried to manually rm or rename the file:

$ docker run -it --rm -p 3001:3000 -v $PWD/conf/sqlite/app.ini:/data/gitea/conf/app.ini gitea/gitea:latest bash
bash-4.3# cd /data/gitea/conf/
bash-4.3# mount | grep app
osxfs on /data/gitea/conf/app.ini type fuse.osxfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other,max_read=1048576)
bash-4.3# rm app.ini
rm: can't remove 'app.ini': Resource busy
bash-4.3# mv app.ini app.ini.tmp
mv: can't rename 'app.ini': Resource busy

The docker image of current version, v1.1.2, can be booted without any problem:

$ docker run -it --rm -p 3001:3000 -v $PWD/conf/sqlite/app.ini:/data/gitea/conf/app.ini gitea/gitea:1.1.2
Jul 22 17:31:02 syslogd started: BusyBox v1.24.2
Generating /data/ssh/ssh_host_ed25519_key...
Generating /data/ssh/ssh_host_rsa_key...
Generating /data/ssh/ssh_host_dsa_key...
Generating /data/ssh/ssh_host_ecdsa_key...
Jul 22 17:31:03 sshd[14]: Server listening on :: port 22.
Jul 22 17:31:03 sshd[14]: Server listening on 0.0.0.0 port 22.
2017/07/22 17:31:03 [T] Custom path: /data/gitea
2017/07/22 17:31:03 [T] Log path: /data/gitea/log
2017/07/22 17:31:03 [I] Gitea v1.1.2 built with: bindata, sqlite
2017/07/22 17:31:03 [I] Log Mode: Console(Trace)
2017/07/22 17:31:03 [I] XORM Log Mode: Console(Trace)
2017/07/22 17:31:03 [I] Cache Service Enabled
2017/07/22 17:31:03 [I] Session Service Enabled
2017/07/22 17:31:03 [I] PING DATABASE sqlite3
2017/07/22 17:31:03 [I] [sql] SELECT name FROM sqlite_master WHERE type='table' and name = ? [args] [version]
...
2017/07/22 17:31:11 Serving [::]:3000 with pid 13
2017/07/22 17:31:11 [I] Listen: http://0.0.0.0:3000

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions