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

Optimize Recursive chown Execution Time on WORKDIR with Many Files #5118

Open
giant995 opened this issue Jun 3, 2024 · 0 comments
Open

Optimize Recursive chown Execution Time on WORKDIR with Many Files #5118

giant995 opened this issue Jun 3, 2024 · 0 comments

Comments

@giant995
Copy link

giant995 commented Jun 3, 2024

Description

The production Dockerfile uses a chown command to recursively change the owner of the WORKDIR directory:

When starting a new project, this command runs relatively fast. As the project grows, the quantity of files inevitably grows, increasing the execution time.

The recursive flag -R should be removed and the same result would be achieved:

RUN chown django:django ${APP_HOME}

Rationale

I currently maintain a mature project that was started with an earlier version of this cookiecutter. I often update the project with the patterns found in the upstream, to keep up with the current standards. Now, recursively changing the owner of the WORKDIR directory takes 2 minutes to complete.

On the preceding lines, both commands use the --chown=django:django argument to copy all files and directories with the django user as the owner:

{%- if cookiecutter.frontend_pipeline in ['Gulp', 'Webpack'] %}
COPY --from=client-builder --chown=django:django ${APP_HOME} ${APP_HOME}
{% else %}
COPY --chown=django:django . ${APP_HOME}
{%- endif %}

In both cases, the /app directory itself is owned by root while its subdirectories and subfiles are all owned by the django user. Removing the recursive flag -R to only change the owner of /app will drastically reduce the execution time and achieve the same result as before.

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

No branches or pull requests

1 participant