openproject icon indicating copy to clipboard operation
openproject copied to clipboard

[#55176] Cleanup Rails's tmp/pid/server.pid file for docker based development

Open wielinde opened this issue 1 year ago • 6 comments

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/web file. That was inspired by an existing solution in docker/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.yml file and also allows individual developers to easily override it at need.

wielinde avatar May 21 '24 11:05 wielinde

Really cool approach, learned about tmpfs for Docker compose. 👍

One question, why is this PR against the release branch?

klaustopher avatar May 23 '24 08:05 klaustopher

True, right now the target should be dev

Kharonus avatar May 23 '24 09:05 Kharonus

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.

wielinde avatar May 23 '24 11:05 wielinde

A question to the Mac users: Does tmpfs work for you? I just read here that this is only available for Linux hosts.

wielinde avatar May 23 '24 11:05 wielinde

Let me check

klaustopher avatar May 23 '24 13:05 klaustopher

$ 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

klaustopher avatar May 23 '24 14:05 klaustopher