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

Install system packages required by OCaml 5.1+ in the ocaml stage #149

Merged
merged 1 commit into from
Mar 23, 2023

Conversation

MisterDA
Copy link
Contributor

@MisterDA MisterDA commented Mar 6, 2023

Different releases of OCaml require different system libraries: libX11 isn't needed since 4.09, when the Graphics library was moved from the core distribution to a separate package. On the opposite side, OCaml 5.1 can optionally use libzstd for compressing marshalled data. Install these packages accordingly in the ocaml image.

@MisterDA
Copy link
Contributor Author

Now based on top of #153.

Copy link
Contributor

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

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

That sounds good in principle but I'm not sure why the dev_packages function wasn't changed instead of creating a new function that users have to call manually. Is there a downside to adding a new mandatory parameter to the dev_packages function? Is this just to allow optional dependencies to be decided by the user (if so I think the function name could be more explicit about that). I would personally be more in favour of simply adding a new mandatory parameter to dev_packages and enforce a set of packages in an opinionated way.

@MisterDA
Copy link
Contributor Author

The goal is really to avoid installing unneeded packages, like libx11 and all its dependencies in the shared opam image. We're going to have to call a function anyway when creating the ocaml stage.

With this new function, the patch to docker-base-images is trivial:
https://github.com/ocurrent/docker-base-images/pull/213/files#diff-5f0eea7390672da3c255b6d2e394932d240c9129a0db3eb95df34ed94a098a43

I think there would be two new parameters: one indicating whether we're in the opam or ocaml (installing the ocaml switch) stage, and the other the ocaml version (the name of the switch). IMO that's better expressed with a new function, but maybe the name could be better. Perhaps ocaml_dev_depexts, or ocaml_opt_packages?

@MisterDA
Copy link
Contributor Author

hmm, passing the switch in an option would work too, I'll try that.
Thanks for the idea!

@MisterDA MisterDA force-pushed the ocaml-dev-packages branch 2 times, most recently from 3d05d4e to 360f477 Compare March 21, 2023 14:48
@MisterDA MisterDA requested review from kit-ty-kate and removed request for dra27 March 21, 2023 14:49
Comment on lines 44 to 55
match version with
| None ->
install
"sudo passwd bzip2 unzip patch rsync nano gcc-c++ git tar curl xz \
which m4 diffutils findutils%s"
extra
| Some v ->
if Ocaml_version.compare v Ocaml_version.Releases.v4_08 <= 0 then
install "libX11-devel%s" extra
else if Ocaml_version.compare v Ocaml_version.Releases.v5_1_0 >= 0 then
install "zstd%s" extra
else empty
Copy link
Contributor

Choose a reason for hiding this comment

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

i was more thinking of something like this

Suggested change
match version with
| None ->
install
"sudo passwd bzip2 unzip patch rsync nano gcc-c++ git tar curl xz \
which m4 diffutils findutils%s"
extra
| Some v ->
if Ocaml_version.compare v Ocaml_version.Releases.v4_08 <= 0 then
install "libX11-devel%s" extra
else if Ocaml_version.compare v Ocaml_version.Releases.v5_1_0 >= 0 then
install "zstd%s" extra
else empty
install
"sudo passwd bzip2 unzip patch rsync nano gcc-c++ git tar curl xz \
which m4 diffutils findutils%s%s"
extra
(if Ocaml_version.compare v Ocaml_version.Releases.v4_08 <= 0
then "libX11-devel"
else if Ocaml_version.compare v Ocaml_version.Releases.v5_1_0 >= 0
then "zstd"
else ""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, but I want for instance to remove libx11 from ocaml/opam:alpine-3.17-opam:

	RUN apk update && apk upgrade
-	RUN apk add build-base patch tar ca-certificates git rsync curl sudo bash libx11-dev nano coreutils xz ncurses-dev bubblewrap
+	RUN apk add build-base patch tar ca-certificates git rsync curl sudo bash nano coreutils xz ncurses-dev bubblewrap
	COPY --from=0 [ "/usr/local/bin/opam-2.0", "/usr/bin/opam-2.0" ]
	RUN ln /usr/bin/opam-2.0 /usr/bin/opam
	COPY --from=0 [ "/usr/local/bin/opam-2.1", "/usr/bin/opam-2.1" ]

and have it installed as part of ocaml/opam:alpine-3.17-ocaml-4.02 to ocaml/opam:alpine-3.17-ocaml-4.07:

	# syntax=docker/dockerfile:1
	FROM ocurrent/opam-staging:alpine-3.17-opam-amd64
	ENV OPAMYES="1" OPAMCONFIRMLEVEL="unsafe-yes" OPAMERRLOGLEN="0" OPAMPRECISETRACKING="1"
+	RUN apk update && apk upgrade
+	RUN apk add libX11-dev
	RUN opam switch create 4.02 --packages=ocaml-base-compiler.4.02.3
	RUN opam pin add -k version ocaml-base-compiler 4.02.3
	RUN opam install -y opam-depext

The function dev_packages is called when building the first stage, so we can't test the ocaml version at this step. We could reinstall all the packages in the second step but that would be wasted work.
Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also supposing that libx11 and zstd are not needed when bootstrapping opam.

@MisterDA
Copy link
Contributor Author

MisterDA commented Mar 22, 2023

As @kit-ty-kate noticed privately, removing libx11 from the -opam images might break workflows of people using them, especially for older versions of OCaml, so I've (for now) constrained this change to only installing zstd on -ocaml-5.1 (and onwards) images.
I've also changed the name of the original function to ocaml_depexts.
I'll squash before merging.
Thoughts?

"build-base patch tar ca-certificates git rsync curl sudo bash \
libx11-dev nano coreutils xz ncurses-dev%s"
"build-base patch tar ca-certificates git rsync curl sudo bash nano \
coreutils xz ncurses-dev libX11-dev%s"
Copy link
Contributor

@kit-ty-kate kit-ty-kate Mar 23, 2023

Choose a reason for hiding this comment

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

On Alpine the name of packages are case sensitive

Suggested change
coreutils xz ncurses-dev libX11-dev%s"
coreutils xz ncurses-dev libx11-dev%s"

I would also suggest to keep the same ordering as before to limit the diff and avoid such issues elsewhere

OCaml 5.1+ can optionally use libzstd for compressing marshalled data.
Install this package in the ocaml image. It's not needed in the opam
stage.

Future work might remove uneeded packages from the opam image, like
libx11 that the graphics library depends on, for OCaml 4.09+.
@MisterDA MisterDA changed the title Install system packages required by OCaml in the ocaml stage Install system packages required by OCaml 5.1+ in the ocaml stage Mar 23, 2023
@MisterDA
Copy link
Contributor Author

Thanks for the reviews!

@MisterDA MisterDA merged commit 6a6d0fa into master Mar 23, 2023
@MisterDA MisterDA deleted the ocaml-dev-packages branch March 23, 2023 16:11
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.

2 participants