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

Periodic Docker images build #37

Merged
merged 9 commits into from
Jul 3, 2019
Merged

Periodic Docker images build #37

merged 9 commits into from
Jul 3, 2019

Conversation

jtpio
Copy link
Member

@jtpio jtpio commented Jun 26, 2019

Related to #10 and #18 (comment).

For now this can be tested by doing a dev install of TLJH and mounting / installing the plugin in the docker container.

TODO

  • Add script to install and enable the systemd units: python -m tljh_voila_gallery.install_build_units
  • Make build_images build from gallery.yaml on the master branch (and default to the package resources)
  • Fetch new gallery.yaml (git pull, requests.get...) and trigger build_images when the new version has been fetched
  • Should the systemd units be installed automatically on plugin install? Could be an issue when developing locally. Or run python -m tljh_voila_gallery.install_build_units after installing TLJH and the plugin
  • Fix WorkingDirectory for the systemd unit? -> remove
  • Update build interval: set to 12h
  • Rename install_build_units
  • Prune stopped containers and images before building

@jtpio
Copy link
Member Author

jtpio commented Jun 26, 2019

This is the current state:

  1. Install TLJH with the tljh-voila-gallery plugin
  2. Run sudo /opt/tljh/hub/bin/python3 -m tljh_voila_gallery.install_builder_units to install the systemd unit files
  3. The systemd timer will trigger the service every 12 hours
  4. The service runs the command: python3 -m tljh_voila_gallery.build_images
  5. The build_images script does the following:

Also installing the systemd units automatically (to be triggered on plugin install) is probably not something we want by default. What do you think @yuvipanda?

@jtpio jtpio changed the title WIP: Periodic Docker images build Periodic Docker images build Jun 26, 2019
@yuvipanda
Copy link
Contributor

I think we should install it by default. You can put it in https://github.com/voila-gallery/gallery/blob/master/tljh-voila-gallery/tljh_voila_gallery/__init__.py#L61, which is executed only when you install TLJH on a machine by running the bootstrapper. Nothing actually happens if you just install the tljh package, so this won't affect local development.

Are rebuilds no-ops if the image is already cached? If so I'd say we should do this every 30min or so instead of 12h. If not, we should make it so and then do it every 30min :D Doesn't need to block this PR though

@jtpio
Copy link
Member Author

jtpio commented Jun 26, 2019

You can put it in https://github.com/voila-gallery/gallery/blob/master/tljh-voila-gallery/tljh_voila_gallery/__init__.py#L61, which is executed only when you install TLJH on a machine by running the bootstrapper.

Right. Do you think it would also make sense to add a new tljh_post_install hook to TLJH specifically for post install scripts? Even though it's true that the tljh_config_post_install or tljh_custom_jupyterhub_config hooks can execute arbitrary python code, that could make the intent clearer.

Are rebuilds no-ops if the image is already cached?

I don't think that's the case for now.

@yuvipanda
Copy link
Contributor

Do you think it would also make sense to add a new tljh_post_install hook to TLJH specifically for post install scripts?

Absolutely! Would love a PR!

@@ -59,6 +53,7 @@ def login_url(self, base_url):

@hookimpl
def tljh_custom_jupyterhub_config(c):
ensure_builder_units()
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized this is the wrong place for this. I meant https://github.com/jupyterhub/the-littlest-jupyterhub/blob/master/tljh/hooks.py#L52, which we don't use right now. Should move to a more explicit post-install hook though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. The best is indeed to have a dedicated post install hook (will submit a PR for that soon!).

Copy link
Member Author

Choose a reason for hiding this comment

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

PR to add the tljh_post_install hook to TLJH: jupyterhub/the-littlest-jupyterhub#389

from ruamel.yaml import YAML

logging.basicConfig(level=logging.INFO)

yaml = YAML()

GALLERY_PATH = 'gallery.yaml' # Relative to module root
GALLERY_URL = 'https://raw.githubusercontent.com/voila-gallery/gallery/master/tljh-voila-gallery/tljh_voila_gallery/gallery.yaml'
Copy link
Contributor

Choose a reason for hiding this comment

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

How would you test this locally? What happens when the format of the yaml file changes but not the code? IMO we should (for now) still load it from the local package, and have some method of autodeployment instead.

Copy link
Member Author

@jtpio jtpio Jun 26, 2019

Choose a reason for hiding this comment

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

Good catch, we should of course support the local gallery.yaml. The same gallery file is also used on the front page so when a new example is added it should also be reflected there.

What happens when the format of the yaml file changes but not the code? IMO we should (for now) still load it from the local package, and have some method of autodeployment instead.

Maybe one way to ensure consistency between the code and the gallery.yaml would be to reinstall / upgrade the plugin? Followed by the build of the docker images.

Copy link
Member Author

Choose a reason for hiding this comment

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

Rebased to revert back to reading from the local package.

@jtpio
Copy link
Member Author

jtpio commented Jun 28, 2019

So to trigger a redeployment of the examples, keeping the timer and systemd unit approach, we could think of:

  • Re-running the same command to upgrade TLJH with the plugin. Although it doesn't look like TLJH support upgrading plugins? (it does for TLJH itself by passing the --upgrade flag)
curl https://raw.githubusercontent.com/jupyterhub/the-littlest-jupyterhub/master/bootstrap/bootstrap.py \
 | sudo python3 - \
   --plugin git+https://github.com/voila-gallery/gallery@master#"egg=tljh-voila-gallery&subdirectory=tljh-voila-gallery"
  • Reinstalling (and updating) the tljh_voila_gallery package directly:
sudo /opt/tljh/hub/bin/python3 -m pip install -U git+https://github.com/voila-gallery/gallery@master#"egg=tljh-voila-gallery&subdirectory=tljh-voila-gallery"

Both ways would still ensure that gallery.yaml and the code stay in sync.

@yuvipanda
Copy link
Contributor

@jtpio I currently like approach 2 - reinstalling the tljh_voila_gallery package. We can do that in a different PR though.


[Timer]
OnBootSec=1min
OnUnitActiveSec=12h
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's bring this down to 2h maybe? 12h seems like a long time :D

Copy link
Member Author

Choose a reason for hiding this comment

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

ah good catch, I thought it was already lowered. Should be fixed now.

@jtpio
Copy link
Member Author

jtpio commented Jul 2, 2019

We can do that in a different PR though.

Agree, it can be in a follow-up PR.

@yuvipanda yuvipanda merged commit 1924639 into master Jul 3, 2019
@yuvipanda
Copy link
Contributor

Thanks, @jtpio!

@jtpio jtpio deleted the systemd-builder branch July 3, 2019 08:40
@jtpio
Copy link
Member Author

jtpio commented Jul 3, 2019

Thanks for reviewing @yuvipanda!

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.

None yet

2 participants