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

Ensuring container services having the correct init process and other improvements related to container services #284

Merged
merged 6 commits into from
Jan 4, 2024

Conversation

candleindark
Copy link
Collaborator

This PR contains the following improvements in container services specification.

  1. Container services are now utilizing the init process provided by https://github.com/phusion/baseimage-docker to ensure all orphaned processes are reaped. Thus, this PR closes Ensure all all orphaned child processes are reaped in the worker service #283.
  2. Elimination of the calls to bash in invoking the command to be executed for a container when the calls can be avoided.
  3. The use of exec to ensure a SIGTERM signal is received by the target process of a container when docker/podman stop are used.
  4. Upgrading the operating system inside the container when building the container images. This improve the security of the container. See https://github.com/phusion/baseimage-docker?tab=readme-ov-file#upgrading-the-operating-system-inside-the-container for more information

For all services that are based on the project
Docker image. This will ensure all orphaned
child processes are reaped.
So that SIGTERM can be passed to the process
correctly in events such as `podman stop`
Call to bash is not really needed if the service
starts only with one command
Copy link

codecov bot commented Jan 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (260f7ae) 98.75% compared to head (5d1850c) 98.75%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #284   +/-   ##
=======================================
  Coverage   98.75%   98.75%           
=======================================
  Files          48       48           
  Lines        2242     2242           
=======================================
  Hits         2214     2214           
  Misses         28       28           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

command: [ "bash", "-c",
"git config --global --add safe.directory /app && pip3 install -U -e . && flask init-db && flask run --host=0.0.0.0 --debug" ]
command: [
"/sbin/my_init", "--",
Copy link
Member

Choose a reason for hiding this comment

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

why just not to retain the same ENTRYPOINT of docker.io/phusion/baseimage:jammy-1.0.1 which is the /sbin/my_init AFAIK and then just have here the "bash", "-c", ...?

Copy link
Member

Choose a reason for hiding this comment

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

but otherwise -- looks good if that works ;) please make it sweat (run the population script again) and see if pids are staying under control with no zombies

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why just not to retain the same ENTRYPOINT of docker.io/phusion/baseimage:jammy-1.0.1 which is the /sbin/my_init AFAIK and then just have here the "bash", "-c", ...?

The docker.io/phusion/baseimage:jammy-1.0.1 image actually doesn't have an ENTRYPOINT of "/sbin/my_init". It only have CMD ["/sbin/my_init"] as the default command to execute, which is to be overridden.

I have considered adding ENTRYPOINT ["/sbin/my_init"] to our project image, but that would require starting each command to be executed with "--". For example, the command you referenced above would have to be command: [ "--", "bash", "-c", "git config --global --add safe.directory /app && pip3 install -U -e . && flask init-db && exec flask run --host=0.0.0.0 --debug" ]. I think that makes the code less clear for it is not immediately clear what the "--" is for, and one has to remember to use "--" before specifying any command to be executed because of a hidden context (the entry point) in the project Docker image.

On the other hand, we can add ``ENTRYPOINT ["/sbin/my_init", "--"]to our project image and specify commands to be executed the way you suggested. However, doing so makes passing options to"/sbin/my_init"` much less convenient (one has to override the entry point to pass any options to `"/sbin/my_init"` itself).

Because of the above considerations, I think we should keep the current arrangement. It is a bit longer, but it is explicit and convenient to pass options to "/sbin/my_init" itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

please make it sweat (run the population script again) and see if pids are staying under control with no zombies

I want to sweat the server by deploying a solution for #271 instead. I think we can see zombies if this PR doesn't work when adding all the gin datasets to the registry (the worker process has already accumulated some zombies over the vacation, about 40, just by updating the registered datasets).

Copy link
Member

Choose a reason for hiding this comment

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

ok

@yarikoptic yarikoptic merged commit 92b9f91 into datalad:master Jan 4, 2024
6 checks passed
@candleindark candleindark deleted the adjust-dockerfile branch January 4, 2024 19:02
@candleindark
Copy link
Collaborator Author

Attached is a snapshot of output of podman stats (note the PIDS column) and a snapshot of the top output inside the worker container after the changes in the PR is put is put in place.

Screenshot 2024-01-04 at 4 11 18 PM

Screenshot 2024-01-04 at 4 18 24 PM

These images can be used to as a reference for comparison in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure all all orphaned child processes are reaped in the worker service
2 participants