Skip to content

Dockerfile cleanup #2861

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

Merged
merged 3 commits into from
Dec 12, 2024
Merged

Dockerfile cleanup #2861

merged 3 commits into from
Dec 12, 2024

Conversation

cuihtlauac
Copy link
Collaborator

@cuihtlauac cuihtlauac commented Dec 12, 2024

Extracted from PR #2831

- don't cache packages to lighten the image.
Dockerfile Outdated
# Install Opam dependencies
ADD ocamlorg.opam ocamlorg.opam
# Install opam dependencies
COPY --chown=opam --link ocamlorg.opam .
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can we keep the old thing here?

ADD ocamlorg.opam ocamlorg.opam

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha, my mistake, I shouldn't have introduced the --link here, but COPY is preferable to ADD: Dockerfile best practice: ADD or COPY.


# Branch freeze was opam-repo HEAD at the time of commit
RUN cd opam-repository && git pull origin c45f5bab71d3589f41f9603daca5acad14df0ab0 && opam update
RUN cd ~/opam-repository && git fetch -q origin master && git reset --hard c45f5bab71d3589f41f9603daca5acad14df0ab0 && opam update
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This has always confused me. I think we've changed this line a couple of times. Back and forth between what we have now and what you're suggesting. Your line downloads some more doesn't it? Is there another difference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In my view, here, to avoid docker cache miss, we should just do git checkout to a hash that is known to be already in opam-repo history.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it downloads more, as per the docs:

More precisely, git pull runs git fetch with the given parameters and then depending on configuration options or command line flags, will call either git rebase or git merge to reconcile diverging branches.

So here by splitting git pull into git fetch and git reset, we're avoiding conflict resolution, though it's not clear to me why there would be any conflicts in the first place. Corruption could happen.

The base image already ships the opam repository, I tend to set this hash to the one already present in the image, so that the git reset operation is mostly free. It can be needed from time to time to update to a newer opam-repository, or just set it explicitly for reproducibility/debugging purposes. The base images are updated weekly, I don't know how often the deployed image is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The deployed image is updated fairly frequently. Several times a week, often more. If we can take advantage of this, it would be nice. That's why we are considering using a docker image pin instead of an opam repo pin

Copy link
Contributor

Choose a reason for hiding this comment

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

Both may be needed, as the docker image is updated weekly, you might want to rely on a dependency that's been released during the week but not yet available in the base image.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No we don't want to do that :-) We're laggards. We want to use old stuff that has been around for some time, preferably a long time. We run away from anything new, fresh, fancy or cool :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

There might be new, fresh, fancy, or cool bug fixes!

RUN cd opam-repository && git checkout master && git pull origin master && opam update
ENV OCAMLORG_REPO_PATH opam-repository
ENV OCAMLORG_PKG_STATE_PATH package.state
RUN cd ~/opam-repository && git checkout master && opam update
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, if you pulled in the previous stage, you don't need to do it again.

@cuihtlauac
Copy link
Collaborator Author

@MisterDA can you have a look at this?

Co-authored-by: Antonin Décimo <[email protected]>
Co-authored-by: Antonin Décimo <[email protected]>
@cuihtlauac cuihtlauac merged commit 620b813 into main Dec 12, 2024
2 of 3 checks passed
@cuihtlauac cuihtlauac deleted the docker-style branch December 12, 2024 16:27
@cuihtlauac
Copy link
Collaborator Author

Terrible mistake I shouldn't have merged this!

cuihtlauac pushed a commit that referenced this pull request Dec 12, 2024
cuihtlauac added a commit that referenced this pull request Dec 12, 2024
This reverts commit 620b813.

Co-authored-by: Cuihtlauac ALVARADO <[email protected]>
@cuihtlauac cuihtlauac restored the docker-style branch December 12, 2024 16:48
@cuihtlauac cuihtlauac deleted the docker-style branch December 12, 2024 16:50
cuihtlauac added a commit that referenced this pull request Dec 18, 2024
* Dockerfile: fix style

- don't cache packages to lighten the image.

* Update Dockerfile

Co-authored-by: Antonin Décimo <[email protected]>

* Update Dockerfile

Co-authored-by: Antonin Décimo <[email protected]>

* Don't fetch before building the switch

* Remove unwanted line

---------

Co-authored-by: Antonin Décimo <[email protected]>
Co-authored-by: Antonin Décimo <[email protected]>
Co-authored-by: Cuihtlauac ALVARADO <[email protected]>
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