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

Update "RUN Instruction Using 'cd' Instead of WORKDIR" query for Docker, allow cd when not at the beginning #5116

Closed
malte-laukoetter opened this issue Apr 2, 2022 · 1 comment · Fixed by #5295
Assignees
Labels
community Community contribution query New query feature

Comments

@malte-laukoetter
Copy link

Platform

Docker

Query

f4a6bcd3-e231-4acf-993c-aa027be50d2e

Description

In long RUN commands there sometimes exists cds in the middle of the Instruction to change a directory. It is not helpful to replace such a cd with a WORKDIR instruction as this would create an additional layer. Therefore only cds that are at the beginning of a RUN instruction should be reported.

Example

The official docker image for fluentd uses such a construct in the Dockerfile for its debian image: https://github.com/fluent/fluentd-docker-image/blob/a9e4cee765c7aaf7876d6fe3282aa565dbcdc2a4/v1.14/debian/Dockerfile

@cxAndreFelicidade
Copy link
Contributor

Hello @Lergin, thank you very much for raising this issue! This query is a tough one.
We would have 2 options:
1 - A way to go around this would be using the full path instead of cd + relative path, and I would update the query description.
2 - Compromising like you suggested, only looking for cd at the start of the command, which can be a good compromise to ensure image optimization and readability.

After looking around in dockerfiles, it seems most use full paths, so we are inclined to going with the first option.

This PR aims to fix this and other issues you have very attentively raised! Thank you once again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution query New query feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants