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

Updated COPY commands #4094

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft

Updated COPY commands #4094

wants to merge 13 commits into from

Conversation

catorreMC
Copy link

Added the built-in chmod/chown flags to improve build time. Removed standalone chmod and chown RUN commands, and removed all chmod/chown operations from the builder container. Will and I elected to keep the chmod and chown commands in the app stage of the image because they serve as a precautionary measure, and removing them makes no positive or negative impact on performance or space, and do not impact the legibility of the file.

On my machine, this improved build time from 2604 seconds to 309 - an 88 percent decrease. Pending further testing on other machines, as mine appeared to run it dramatically slower than others.

Dockerfile.lite still needs to be updated accordingly.

built in to improve build time
Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated
@@ -11,43 +11,37 @@ USER 0
COPY package.json yarn.lock lerna.json tsconfig.json .prettierrc ./
Copy link
Contributor

Choose a reason for hiding this comment

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

can we explore using 'copy --link' (https://docs.docker.com/engine/reference/builder/#copy---link) to see if we can make these copy layers more independent?

Copy link
Author

Choose a reason for hiding this comment

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

I'll give this a look. Surprised I hadn't seen it before.

Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated
COPY --from=builder --chown= --chmod=0500 /src/apps/backend/node_modules apps/backend/node_modules
COPY --from=builder --chown= --chmod=0500 /src/apps/backend/dist apps/backend/dist
COPY --from=builder --chown= /src/dist/ dist/
COPY --from=builder --chown= --chmod=0500 /src/apps/backend/.sequelizerc /app/apps/backend/
Copy link
Contributor

Choose a reason for hiding this comment

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

why do the copies start doing absolute paths for the copy instead of relative like we have been?

Copy link
Author

Choose a reason for hiding this comment

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

Good question - I didn't change that part of the line, but I don't have any rationale for keeping it that way. That could be changed for consistency.

Dockerfile Outdated Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
@aaronlippold
Copy link
Member

It seems to me that this container should be running as either a heimdall user or a heimdallapp or nodeapp or something like that - and thus in the final build layer there should be commands making sure all the data on the image is owned by that user:

COPY --from=build /usr/bin/dumb-init /usr/bin/dumb-init
USER node
WORKDIR /usr/src/app
COPY --chown=node:node --from=build /usr/src/app/node_modules /usr/src/app/node_modules
COPY --chown=node:node . /usr/src/app

chmod,chwon commands can be joined and they can also be recessive. So I can chown -R user:group <path>
next
The files and folders on the system, I would think, only need at max: 00640 for -type f and 00750 -type d although enabling the stickly bit on all directory structures in the base layers with the right mask may save some time an effort here. However this may be showing a bug that would mean we may have to be more hands on with managing this.

https://forums.docker.com/t/permissions-issue-with-compose-build-vs-docker-build/7775

@Amndeep7
Copy link
Contributor

It seems to me that this container should be running as either a heimdall user or a heimdallapp or nodeapp or something like that - and thus in the final build layer there should be commands making sure all the data on the image is owned by that user:

That's why we have that 'node' user. They've basically done the work to properly create a different user account from root and we can do whatever we want with it now as opposed to having to manually create a 'heimdall' user.

@sonarcloud
Copy link

sonarcloud bot commented Feb 24, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@mergify
Copy link
Contributor

mergify bot commented May 16, 2023

This pull request has a conflict. Could you fix it @catorreMC?

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Jul 4, 2023

This pull request has a conflict. Could you fix it @catorreMC?

@Amndeep7 Amndeep7 marked this pull request as draft July 10, 2023 16:02
@mergify
Copy link
Contributor

mergify bot commented Sep 5, 2023

This pull request has a conflict. Could you fix it @catorreMC?

1 similar comment
Copy link
Contributor

mergify bot commented Feb 6, 2024

This pull request has a conflict. Could you fix it @catorreMC?

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.

None yet

3 participants