Skip to content

Conversation

@MisterDA
Copy link
Contributor

@MisterDA MisterDA commented Feb 2, 2023

This is a first attempt at supporting RUN command arguments. I've added types for mounts and networks which are in BuildKit, and security, which is not yet in BuildKit. I've added an escape hatch to RUN as the ?args:string list parameter for later additions (and podman compat?). The security and network types, being relatively simple now, get their own parameters to RUN, but the mount values are serialized to string first.
The crunch function will not crunch shell scripts if their network or security differ, specified or not.
cc #137

@MisterDA
Copy link
Contributor Author

MisterDA commented Feb 3, 2023

@edwintorok I had not read your proposal carefully enough, do you already have code to achieve this? What do you think of this proposal?

@edwintorok
Copy link
Contributor

My code is currently here master...edwintorok:ocaml-dockerfile:caching. I'm not entirely happy with how the API on that looks, and still evolving it as I use it.

@edwintorok
Copy link
Contributor

edwintorok commented Feb 3, 2023

Crunching mounts: I'm undecided what the best way forward is. Crunching commands with different mounts, especially with 'sharing=locked' might result in the build holding the lock for way longer than intended (small individual commands may be faster here even if they create additional layers).
Perhaps there should be an option to crunch to specify whether RUN lines with different mounts can be crunched together or not (in my changes so far I defaulted to no, and in your changes you defaulted to yes, so if we make it configurable it'll work for both of us).

@edwintorok
Copy link
Contributor

@edwintorok I had not read your proposal carefully enough, do you already have code to achieve this? What do you think of this proposal?

I think I can rebase my changes on top of yours, in some areas they are more complete than mine.
Sorry if I made you duplicate some of what I already done (perhaps I should've opened a draft PR sooner).

I have a few more things on my branch (caching support in opam package manager, but that builds on top of this, and some doc comments, and a convenient value for the correct parsing_directive to use).

@MisterDA
Copy link
Contributor Author

MisterDA commented Feb 3, 2023

Crunching is already super fragile: is assumes a Unix shell-like syntax. I think we had an issue for something like this but I can't remember where it is. Anyway, I don't use crunch too much in Windows code, it behaves poorly with line continuations, &&, between cmd, powershell, Cygwin's shell...
It's doable to have a configurable switch to commands with different mounts, but I fear crunch would do too much. Perhaps it should error instead?

I have a few more things on my branch (caching support in opam package manager, but that builds on top of this, and some doc comments, and a convenient value for the correct parsing_directive to use).

Cool!

@edwintorok
Copy link
Contributor

as long as the mounts are identical I think crunch should accept it (and be careful so we end up just with one set of mounts), otherwise either eject it or silently skip over it. Rejecting sounds better because it wouldn't break user expectations.

Yes crunching is already quite fragile if you e.g. 'cd' in one RUN line then the next one will run in a different directory. That may or may not be what the user wanted. It is useful to be able to run on small portions of the dockerfile, but when mounts are used I don't think that running it on the entire one would be useful.

@MisterDA
Copy link
Contributor Author

I've simplified the code, I think. I've added your buildkit_syntax value too.
run and run_exec take well typed arguments.
crunch will raise if it tries to merge lines using different networks or security policies. It'll merge mounts if they are strictly identical.

@edwintorok
Copy link
Contributor

Thanks, I have some additional code to use this, I'll rebase it on top of your latest branch.

@edwintorok
Copy link
Contributor

edwintorok commented Feb 17, 2023

run-args...edwintorok:ocaml-dockerfile:caching-run-args

There are some commits there that you may want to cherry-pick into this PR:
2dcbb8e Dockerfile: escape spaces in mount args
45dac5c Dockerfile.mli: more documentation on mounts
fe66805 Dockerfile: refer to {!buildkit_syntax}

In particular escaping is important because 'space' is otherwise a separator between mount args, but it may also show up inside mount args (e.g. a cache id, or a directory path, though in general on Linux paths don't have spaces that is not a reason to not implement escaping).

And I think the buildkit_syntax commit from above would also fix the ocaml-lint failure that ocaml-ci is complaining about here.

I've also written a test that generates a single dockerfile with all opam containers and builds them in parallel, but I'll open a separate PR with that (it is in my branch above), and the rest of the changes (to use caching for apt/yum/opam commands/etc.)

edwintorok and others added 5 commits February 20, 2023 11:00
Signed-off-by: Edwin Török <edwin.torok@cloud.com>
The official docs are quite scarce on how these work, add a few more
details here to make it easier to use.

Most of these work with both Docker and Podman 4.x, some options are only
supported by Docker, and some options are parsed but do not work
on older versions of Podman.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
Space is the separator between mount args, and if some mount arg
contains a space (e.g. a cache id, or directory) then we must escape it.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
@MisterDA
Copy link
Contributor Author

I've also written a test that generates a single dockerfile with all opam containers and builds them in parallel, but I'll open a separate PR with that (it is in my branch above), and the rest of the changes (to use caching for apt/yum/opam commands/etc.)

The caching part is super cool, that would be a great feature IMO.
As a matter of fact, there's already a test outputting all the build instructions to give us a point of reference when they change; it's just not in this repo. See ocurrent/docker-base-images/builds.expected.

Thank you for the other commits, I've cherry-picked them (rebasing with the format fix, which changed the commit id).

I'm all in for escapes, so I've included your patch.

@tmcgilchrist
Copy link
Member

tmcgilchrist commented Feb 20, 2023 via email

@tmcgilchrist
Copy link
Member

tmcgilchrist commented Feb 20, 2023 via email

@MisterDA MisterDA merged commit 0e0dba2 into master Feb 21, 2023
@MisterDA MisterDA deleted the run-args branch February 21, 2023 14:58
MisterDA added a commit to MisterDA/opam-repository that referenced this pull request Mar 23, 2023
CHANGES:

- Install system packages required by OCaml in the ocaml stage,
  starting with OCaml 5.1 and libzstd.
  (@MisterDA ocurrent/ocaml-dockerfile#149, review by @kit-ty-kate)
- Add OracleLinux 9. (@MisterDA ocurrent/ocaml-dockerfile#155)
- Optimize and fix Linux package install.
  (@MisterDA ocurrent/ocaml-dockerfile#147, ocurrent/ocaml-dockerfile#151, ocurrent/ocaml-dockerfile#153, ocurrent/ocaml-dockerfile#154, review by @kit-ty-kate)
- Switch to ocaml-opam/opam-repository-mingw#sunset for Windows images. (@MisterDA ocurrent/ocaml-dockerfile#152)
- Use DockerHub user risvc64/ubuntu. (@MisterDA, ocurrent/ocaml-dockerfile#150)
- Various LCU Updates (@mtelvers ocurrent/ocaml-dockerfile#144 ocurrent/ocaml-dockerfile#136 ocurrent/ocaml-dockerfile#135)
- Support mounts, networks, and security parameters in RUN
  commands, add buildkit_syntax helper function.
  (@MisterDA, @edwintorok, ocurrent/ocaml-dockerfile#137, ocurrent/ocaml-dockerfile#139, review by @edwintorok)
- Build and install opam master from source in Windows images.
  (@MisterDA ocurrent/ocaml-dockerfile#140, ocurrent/ocaml-dockerfile#142, ocurrent/ocaml-dockerfile#143)
- Include the ocaml-beta-repository in the images. (@kit-ty-kate ocurrent/ocaml-dockerfile#132, review by @MisterDA)
- Add OpenSUSE 15.4, deprecate OpenSUSE 15.3. (@MisterDA ocurrent/ocaml-dockerfile#138)
- Update to bubblewrap 0.8.0. (@MisterDA ocurrent/ocaml-dockerfile#131 ocurrent/ocaml-dockerfile#148)
- Add Alpine 3.17 (3.16 is now tier 2 and 3.15 is deprecated). Remove
  libexecinfo-dev from the list of apk packages as it is no longer
  available. Its symbols are only used in OCaml's self tests.
  (@MisterDA ocurrent/ocaml-dockerfile#129, ocurrent/ocaml-dockerfile#130)
- Fix location of Debian exotic architecture images (@dra27 ocurrent/ocaml-dockerfile#134)
- Fix passing of --platform to all stages of the Dockerfiles (@dra27 ocurrent/ocaml-dockerfile#134)
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.

4 participants