[#55176] Cleanup Rails's tmp/pid/server.pid file for docker based development
https://community.openproject.org/work_packages/55176
When developing with Rails it happens frequently that a PID file does not get cleaned up. Debugging why a local dev environment did not boot slows down development and increases developer frustration.
This PR aims to ensure that all former PID files are gone when calling docker compose up -d backend next time.
Implementation details:
There are multiple approaches on how to make that happen.
- @oliverguenther for example chose a solution that removes such files from within the
docker/prod/webfile. That was inspired by an existing solution indocker/prod/entrypoint.sh - At least for development I prefer the solution promoted in this blog post, as it hands over the complexity of having temporary files to specialized volumes (tmpfs, which lives in memory only), makes it transparent in the
docker-compose.ymlfile and also allows individual developers to easily override it at need.
Really cool approach, learned about tmpfs for Docker compose. 👍
One question, why is this PR against the release branch?
True, right now the target should be dev
One question, why is this PR against the release branch?
Because we run into that problem also when debugging or bug fixing on the release branch. So my intention is to get rid of the problem as soon as possible. And it only affects the developer setup.
A question to the Mac users: Does tmpfs work for you? I just read here that this is only available for Linux hosts.
Let me check
$ docker-compose exec backend sh
WARN[0000] The "OPENPROJECT_DEV_URL" variable is not set. Defaulting to a blank string.
$ echo $PIDFILE
/home/dev/openproject/tmpfs/pids/server.pid
$ cat /home/dev/openproject/tmpfs/pids/server.pid
1
$ ps aux | grep puma
dev 1 2.4 7.3 2853212 589088 pts/0 Ssl+ 13:53 0:11 puma 6.4.2 (tcp://0.0.0.0:3000) [openproject]
dev 61 0.0 0.0 4796 1920 pts/1 S+ 14:01 0:00 grep puma
$ kill $(cat $PIDFILE)
$ %
This worked and after stopping with Ctrl+C, I did not have a PIDfile remain
Also checked to run docker directly with --tmpfs option and this also properly worked:
$ docker run -it --tmpfs /foo alpine sh
/ # ls /foo
/ # touch /foo/hello.txt
/ # ls /foo
hello.txt
/ # exit