Skip to content

Implement a dockerTools.buildLayeredImage target for obelisk projects#697

Closed
fabianhjr wants to merge 1 commit into
obsidiansystems:developfrom
LibreCybernetics:db-docker-support
Closed

Implement a dockerTools.buildLayeredImage target for obelisk projects#697
fabianhjr wants to merge 1 commit into
obsidiansystems:developfrom
LibreCybernetics:db-docker-support

Conversation

@fabianhjr

@fabianhjr fabianhjr commented Apr 11, 2020

Copy link
Copy Markdown
Contributor

This is a rebase (solving conflicts) and squash of #512

I have:

  • Based work on latest develop branch
  • Looked for lint in my changes with hlint . (lint found code you did not write can be left alone)
  • Run the test suite: $(nix-build -A selftest --no-out-link)
  • (Optional) Run CI tests locally: nix-build release.nix -A build.x86_64-linux --no-out-link (or x86_64-darwin on macOS)

Changes from #512:

  • ChangeLog Next entry on merge
  • version became optional with default "latest" docker tag
  • moved docker build along deployment in readme
  • changed buildImage to buildLayeredImage for image efficiency/reusability.
  • use an optional internalPort argument

@fabianhjr fabianhjr changed the base branch from master to develop April 11, 2020 02:47
@fabianhjr fabianhjr changed the title Implement a dockerTools.imageBuild target for obelisk projects WIP: Implement a dockerTools.imageBuild target for obelisk projects Apr 11, 2020
@fabianhjr fabianhjr force-pushed the db-docker-support branch 4 times, most recently from e517de9 to e73cdcc Compare April 11, 2020 04:55
@3noch

3noch commented Apr 11, 2020

Copy link
Copy Markdown
Collaborator

Awesome! We'll try to get this in!

@fabianhjr

Copy link
Copy Markdown
Contributor Author

Hi @3noch, good to hear. Currently doing some testing with some of the changes made from the original merge request. :3

Though, it will take me some time to really get a feel about this. First time doing anything docker/k8s related. I can say with confidence that buildLayeredImage, nix and obelisk have been really interesting to learn about.

Anyways, here are the layers created for the project I am currently working on (https://gitlab.com/LibreCybernetics/LaTiendita/-/tree/1df40b5d8b984e55588b4ada1ec70db336cb40c5):
Screenshot from 2020-04-11 00-00-42

@fabianhjr

Copy link
Copy Markdown
Contributor Author

From initial tests buildImage created a single ~550 MB layer, buildLayeredImage created several images and a ~450 MB one.
Screenshot from 2020-04-11 00-07-00

@fabianhjr fabianhjr changed the title WIP: Implement a dockerTools.imageBuild target for obelisk projects Implement a dockerTools.imageBuild target for obelisk projects Apr 11, 2020
@fabianhjr

Copy link
Copy Markdown
Contributor Author

Interestingly enough, seems like the compressed image is closer to 160MB.
Screenshot from 2020-04-11 00-09-45

@fabianhjr

fabianhjr commented Apr 11, 2020

Copy link
Copy Markdown
Contributor Author

And it is live :')

https://latiendita.coop

@fabianhjr fabianhjr changed the title Implement a dockerTools.imageBuild target for obelisk projects Implement a dockerTools.buildLayeredImage target for obelisk projects Apr 11, 2020
@fabianhjr

Copy link
Copy Markdown
Contributor Author

Hi @3noch, on some further testing it seems like nix is packaging obelisk projects alongside thunks (like obelisk/obvelisk-oauth) as a single package and that stops some reusability from happening in the layered docker image.

I tried reading some of the nix expressions but wouldn't know how to separate them into packages. :C

@3noch

3noch commented Apr 13, 2020

Copy link
Copy Markdown
Collaborator

Obelisk executables are statically linked. Perhaps that's what you're seeing? However, it's uncommon to layer multiple nix produced Docker images. It's more common, I think, to do your layering in nix and then produce a single Docker image at the end. Nix is better at sharing correctly than Docker.

@fabianhjr

fabianhjr commented Apr 13, 2020

Copy link
Copy Markdown
Contributor Author

Nix is better at sharing correctly than Docker.

Yes, however this is for deployment from nix, Docker doesn't build the layers nix does as per documentation:

pkgs.dockerTools is a set of functions for creating and manipulating Docker images according to the Docker Image Specification v1.2.0 . Docker itself is not used to perform any of the operations done by these functions.

It would be really neat if for this small project the difference (the project itself) could get to about 50 MB or so. (Though I am not really sure how small or not the resulting single project layer can get)

EDIT: That way space usage in Container Registries could be reduced.

@3noch

3noch commented Apr 13, 2020

Copy link
Copy Markdown
Collaborator

If the docker image size is the problem then what we probably need to do is figure out how to minimize our nix closure for obelisk projects. I've looked into this before and I suspect we can make the closure much smaller. That will produce smaller Docker images.

Comment thread default.nix
))
];
Expose = 8000;
Entrypoint = ["/var/lib/backend/backend"];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We shouldn't have hardcoded this. We'll probably have to move this nix into the mkObelisk module function so that one can get a docker image for obelisk without assuming default configuration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will look into it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If I understood this correctly then any changes on internalPort should propagete to the docker target. It should now not be hardcoded.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As per the entrypoint, if I understand this correctly that location is being grabbed from nix and symlinked in line 172

@fabianhjr

Copy link
Copy Markdown
Contributor Author

I think the closure doesn't need to be smaller. Maybe dynamically building and having thunks be their own nixpkg would allow nix to split them into different docker layers. (However that is a future nice to have)

Comment thread default.nix Outdated
Comment thread default.nix
Comment thread README.md
To build with a custom configuration, Obelisk's default configuration can be imported and overriden in a `release.nix` file added to your top-level directory:

```nix
{ }:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A function from the empty set seems not useful. Is there something I'm missing with this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Don't think so, not that I could find from #512

@fabianhjr fabianhjr force-pushed the db-docker-support branch 3 times, most recently from e5f18c3 to ee5afdd Compare April 16, 2020 21:39
@fabianhjr fabianhjr mentioned this pull request Apr 17, 2020
@fabianhjr fabianhjr requested a review from 3noch May 3, 2020 18:52
@fabianhjr fabianhjr force-pushed the db-docker-support branch from a7cdad2 to 09c951f Compare May 7, 2020 19:52
@fabianhjr fabianhjr force-pushed the db-docker-support branch 2 times, most recently from cbf0779 to 1938f13 Compare May 25, 2020 14:38
@fabianhjr fabianhjr force-pushed the db-docker-support branch from 1938f13 to 13e94d2 Compare June 8, 2020 19:09
@fabianhjr fabianhjr force-pushed the db-docker-support branch from 13e94d2 to fa13ea6 Compare June 23, 2020 23:39
@fabianhjr fabianhjr force-pushed the db-docker-support branch from fa13ea6 to 9f718bc Compare July 8, 2020 17:59
Documentation on this extra target can be found in nix's dockerTools
documentation: https://nixos.org/nixpkgs/manual/#sec-pkgs-dockerTools

Co-authored-by: Joe Betz <joebetz91@gmail.com>
Co-authored-by: Fabián Heredia Montiel <fabianhjr@protonmail.com>
@fabianhjr fabianhjr force-pushed the db-docker-support branch from 9f718bc to 7c12cc9 Compare July 16, 2020 16:16
@augyg

augyg commented May 23, 2022

Copy link
Copy Markdown
Contributor

@fabianhjr is this still being worked on and wanted?

@fabianhjr

Copy link
Copy Markdown
Contributor Author

I haven't used obelisk in a while, it is something I wanted though. Feel free to rebase and reopen a merge request.

@fabianhjr fabianhjr closed this May 23, 2022
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.

5 participants