-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat[closes #38]: add workdir instruction support #57
feat[closes #38]: add workdir instruction support #57
Conversation
Thanks for contributing. Please explain why you think that this feature requires breaking chages. Also, I think that adding state here adds unecessary complexity. I would prefer a solution that just resets the working directory to a default value (probably "/") since changing the working directory is not a costly operation. |
Hello @taukakao.
I was trying to stay as close as possible to how an actual Dockerfile works. Each supported command can optionally specify its working directory before it executes. For each command to keep track of the working directory a new structure is needed. Furthermore, without attaching workdir to a command state how we will know when to switch working directories? I mean YAML does not allow for duplicated keys so using workdir multiple times at the top level is not feasible. Originally I was thinking to only have a module/stage level workdir but then the workdir can only be changed once. I guess we could use other naming schemes maybe workdir+number to specify multiple workdirs at the top level but then we will need to keep track of what comes after that.
Indeed, I originally had a restore flag that would optionally restore the working directory back to root after the command is executed. I am not sure if it required, but we could re-introduce it. Regarding state itself, again as mentioned above it is needed to know for which command to switch the workdir for. I am not sure how you intend to use this feature. For example, I am not sure if it is needed for all supported commands or if you want to set a working directory multiple times in a recipe. This is just a draft implementation of how I pictured it working, and I was a bit worried about the breaking changes but of course I am open to suggestions/feedback and will be happy to adjust as necessary. We just need to keep in mind that keeping things a bit separate will allow us to further extend Vib's feature set down the line if needed. For example having separate states for each command will allow us to add more of their options like copy has from etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I like the idea of having WORKDIR in all the available commands. Personally I do not understand where this is a breaking change. Can't we simply keep WORKDIR empty if not defined? From my understanding this would make existing recipes just works as before, correct me if I am wrong.
Hello Mirko. Thank you very much for the feedback.
Unfortunately, that is not the case. This means that any recipe using entrypoint for example the chronos-fe recipe will need to be updated from: entrypoint:
- /bin/sh
- '-c'
- cd /app && npm run publish to entrypoint:
exec:
- /bin/sh
- '-c'
- cd /app && npm run publish otherwise: I am wondering if there is an easy way to avoid breaking changes by using generics. Ideally what we want for the entrypoint example is that it can either be a string[] or an EntryPoint type. This will complicate the state and the checks we need to do, but I guess it is possible. It depends on how far we want to go. I will see if I can find any other workarounds. |
Oh, got it. I think it's fine, we already introduced breaking changes in the past, this just needs to be documented in our documentation. |
I find it very important that the individual commands stay modular, so I would prefer if: copy:
- workdir: /tmp
paths:
- src: /app/awesome.txt
dst: . would create WORKDIR /tmp
COPY /app/awesome.txt .
WORKDIR / That would cause a lot of duplicate WORKDIR instructions but I don't think that's really a problem and it would remove the need for the state and guarantees that following instructions will not be affected by the workdir. |
Also, if it only breaks the entrypoint then I think it would be reasonable. |
Thank you everyone for the feedback.
The new RUNbefore runs:
- echo "hello" after: runs:
comands:
- echo "hello" CMDbefore cmd:
- echo "hello" after: cmd:
exec:
- echo "hello" ENTRYPOINTbefore entrypoint:
- echo "hello" after: entrypoint:
exec:
- echo "hello" ADDbefore adds:
myfile:/tmp after: adds:
srcdst:
myfile:/tmp
srcdst:
myotherfile:/tmp Now each of the commands above (including COPY) also takes an optional workdir to specify the working directory before each action is executed. Can one of you please clarify the following points so that I can proceed:
will generate WORKDIR /tmp
RUN echo "hello"
# WORKDIR / -> if we always revent back to root
WORKDIR /tmp
CMD [echo "world"]
# WORKDIR / -> if we always revent back to root
Let me know when you get a chance. Thank you! |
Yeah, it's unfortunate but I see why it's necessary. At least it will make it easier in the future. @mirkobrombin for the other questions
I think that would be sensible, but it should be done in two different commits or maybe even two different PRs.
I think that's a reasonable approach. |
it is fine
it is fine if necessary |
f4cd7fa
to
683dd07
Compare
Updated the PR with the requested changes. Thank you! Edit: Example and generated container file in the original description have also been updated for your reference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with the Containerfile in the first comment. Looks good to me, nice job!
Waiting for at least another reviewer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one tiny note. Otherwise it looks really good.
Also tested building the desktop image. Just had to rebuild fsguard with the new api and change one line in the recipe and it worked.
Latest commits:
Please note that CMD and ENTRYPOINT uses the exec form ["", ""] so we need to pass each command as a list which is why I used exec as a field name entrypoint:
exec:
- npm run build
entrypoint:
exec:
- npm
- run
- build
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks for your contribution. Tested the changes and checked the docs additions.
Mirko already approved it, so I'm gonna merge it. |
Thanks for your contribution @lambdaclan |
(And yes, I just realized that those commits weren't squashed yet, we will decide how to deal with that) |
Add
WORKDIR
instruction supportCloses #38
Description
This PR adds support for the
WORKDIR
instruction to various commands. It also checks to ensure that unnecessaryWORKDIR
instructions are ignored when the requested working directory is already the present working directory by having a recipe level PWD.Proposed Changes
WORKDIR
instruction support for all possible commands:Use a recipe wide PWD variable to keep track of the present working directory to avoid unnecessary (albeit harmless) instructions-
Always set the recipe's initial PWD to root (/) like default Dockersinglelayer: true
WORKDIR
mismatches do not occur (not sure if the check is needed so TBD)Local Testing
Using the following
vib.yml
recipe (based on the original chronos-fe recipe):Generated Containerfile: