sagemath/sage

gitpod integration using Docker images from portability testing workflow

mkoeppe opened this issue ยท 199 comments

Gitpod allows one to setup a complete dev environment in the cloud. It is free to use for up to 50 hours per month. In this ticket the config necessary for making this work with sagemath is added.

You can try this out by going to https://gitpod.io/#https://github.com/mkoeppe/sage/tree/mkoeppe-9.5.beta9%2Bupdates.

It works by building docker images on github, push them to GH packages (https://github.com/mkoeppe?tab=packages&q=gitpod) and then use these ones as the base for the gitpod workspace.

After this ticket is merged, we should activate the automatic prebuild by installing the github app (https://www.gitpod.io/docs/prebuilds#on-github). With this enabled, every push would trigger a prebuild of the complete environment (including the build of all dependencies and cythonizion) so that one has a up-to-date code env very quickly without the need to build anything.

Follow-up: #33113 gitpod usability improvements

Alternative: #32749, which only builds the docker image on gitpod (which is currently not really feasible as they have a time limit of 1h)

Depends on #30933
Depends on #29285

CC: @tobiasdiez @dimpase @saraedum

Component: docker

Author: Tobias Diez, Matthias Koeppe

Branch/Commit: 078f247

Reviewer: Matthias Koeppe, Dima Pasechnik

Issue created by migration from https://trac.sagemath.org/ticket/33103

Last 10 new commits:

e99a09esed -i.bak 's/ubunty/ubuntu/g' .github/workflows/*.yml
edb4364.github/workflows/tox.yml: Replace homebrew-macos-python3_xcode-standard by homebrew-macos-usrlocal-python3_xcode-standard
e27e161Merge #32703
96a45d1tox.ini, .github/workflows: Remove ubuntu-groovy
59ec3d0Merge #33068
cbf03d1.github/workflows/tox.yml: Add docker-gitpod
4a9edfcbuild/bin/write-dockerfile.sh: Handle __SUDO
d697d94build/bin/write-dockerfile.sh: Use relative workdir 'sage'
c7cc5cd.gitpod.yml, docker/.gitpod.Dockerfile: Reverse SAGE_LOCAL symlink
bde9f74build/bin/write-dockerfile.sh: Handle $__CHOWN

Commit: bde9f74

Author: Tobias Diez, Matthias Koeppe

Branch pushed to git repo; I updated commit sha1. New commits:

21afe51.github/workflows/tox*.yml, tox.ini: Pass ddocker.pkg.github.com credentials via DOCKER_CONFIG_FILE
76b5e76Merge #30933

Changed commit from bde9f74 to 76b5e76

Description changed:

--- 
+++ 
@@ -1 +1,5 @@
 Based on #32749.
+
+Docker images are pushed to GH Packages - https://github.com/mkoeppe?tab=packages&q=gitpod - and can be used to initialize gitpod
+
+

Branch pushed to git repo; I updated commit sha1. New commits:

7ef6a6edocker/.gitpod.Dockerfile: Remove, use custom image from GH Packages instead

Changed commit from 76b5e76 to 7ef6a6e

Description changed:

--- 
+++ 
@@ -2,4 +2,5 @@
 
 Docker images are pushed to GH Packages - https://github.com/mkoeppe?tab=packages&q=gitpod - and can be used to initialize gitpod
 
-
+To try out (after the image has been built):
+- https://gitpod.io/#https://github.com/mkoeppe/sage/tree/t/33103/gitpod_integration_using_docker_images_from_portability_testing_workflow

Description changed:

--- 
+++ 
@@ -2,5 +2,5 @@
 
 Docker images are pushed to GH Packages - https://github.com/mkoeppe?tab=packages&q=gitpod - and can be used to initialize gitpod
 
-To try out (after the image has been built):
+To try out (after the image has been built, https://github.com/mkoeppe/sage/runs/4680839663?check_suite_focus=true):
 - https://gitpod.io/#https://github.com/mkoeppe/sage/tree/t/33103/gitpod_integration_using_docker_images_from_portability_testing_workflow

Branch pushed to git repo; I updated commit sha1. New commits:

6b41c4a.github/workflows/tox.yml: Also push ...-with-targets-pre

Changed commit from 7ef6a6e to 6b41c4a

comment:9

Running into pyenv issues (#29285) here too:

[pytest] installing. Log file: /home/gitpod/sage/logs/pkgs/pytest.log
  [pytest] error installing, exit status 1. End of log file:
  [pytest]   /home/gitpod/sage-local/var/lib/sage/venv-python3.8/bin/python3: No module named pip
  [pytest] Full log file: /home/gitpod/sage/logs/pkgs/pytest.log
make[4]: *** [Makefile:2756: pytest-no-deps] Error 1

Changed dependencies from #33068, #30933 to #33068, #30933, #29285

Changed commit from 6b41c4a to 5f0c36c

Branch pushed to git repo; I updated commit sha1. New commits:

376932fbuild/bin/sage-bootstrap-python: Reject pyenv shims
5f0c36cMerge #29285

Changed dependencies from #33068, #30933, #29285 to #33068, #30933, #29285, #32868

Changed dependencies from #33068, #30933, #29285, #32868 to #33068, #30933, #29285, #32868, #33067

Changed commit from 5f0c36c to af7c8d3

Branch pushed to git repo; I updated commit sha1. Last 10 new commits:

aeca1a0Makefile (pypi-sdists): Add sage_setup
cd3dce9pkgs/sage-conf_pypi/setup.py: Update directory of configured sage_conf.py
c695921pkgs/sage-conf/sage_conf.py.in (SAGE_SPKG_WHEELS): Update so it works if SAGE_VENV != SAGE_LOCAL
cebcda3Merge tag '9.5.beta4' into t/29039/pip_installable_package_sage_bootstrap
0026892Merge tag '9.5.beta5' into t/29039/pip_installable_package_sage_bootstrap
2a4a323Merge tag '9.5.beta7' into t/29039/pip_installable_package_sage_bootstrap
02234ceMerge #29039
b1413d4build/bin/write-dockerfile.sh: Move 'ADD pkgs' earlier
859be3ebuild/bin/write-dockerfile.sh: ADD src/*.m4 files for bootstrapping
af7c8d3Merge #33067

Description changed:

--- 
+++ 
@@ -2,5 +2,5 @@
 
 Docker images are pushed to GH Packages - https://github.com/mkoeppe?tab=packages&q=gitpod - and can be used to initialize gitpod
 
-To try out (after the image has been built, https://github.com/mkoeppe/sage/runs/4680839663?check_suite_focus=true):
+To try out (after the image has been built, https://github.com/mkoeppe/sage/runs/4682227249?check_suite_focus=true):
 - https://gitpod.io/#https://github.com/mkoeppe/sage/tree/t/33103/gitpod_integration_using_docker_images_from_portability_testing_workflow

Changed commit from af7c8d3 to fad8942

Branch pushed to git repo; I updated commit sha1. New commits:

fad8942build/bin/write-dockerfile.sh: Use relative workdir 'sage' (again)

Description changed:

--- 
+++ 
@@ -3,4 +3,4 @@
 Docker images are pushed to GH Packages - https://github.com/mkoeppe?tab=packages&q=gitpod - and can be used to initialize gitpod
 
 To try out (after the image has been built, https://github.com/mkoeppe/sage/runs/4682227249?check_suite_focus=true):
-- https://gitpod.io/#https://github.com/mkoeppe/sage/tree/t/33103/gitpod_integration_using_docker_images_from_portability_testing_workflow
+- https://gitpod.io/#https://github.com/mkoeppe/sage/tree/mkoeppe-9.5.beta9%2Bupdates

Branch pushed to git repo; I updated commit sha1. New commits:

601a3b5.gitpod.yml: Remove pyenv workarounds
1258c70.gitpod.yml: configure --enable-download-from-upstream-url

Changed commit from fad8942 to 1258c70

comment:19

This works. To be done:

Description changed:

--- 
+++ 
@@ -2,5 +2,5 @@
 
 Docker images are pushed to GH Packages - https://github.com/mkoeppe?tab=packages&q=gitpod - and can be used to initialize gitpod
 
-To try out (after the image has been built, https://github.com/mkoeppe/sage/runs/4682227249?check_suite_focus=true):
+To try out:
 - https://gitpod.io/#https://github.com/mkoeppe/sage/tree/mkoeppe-9.5.beta9%2Bupdates

Changed commit from 1258c70 to fdb49a1

Branch pushed to git repo; I updated commit sha1. New commits:

fdb49a1tox.ini, .github/workflows/tox*.yml: Also tag the Docker images with GITHUB_REF_NAME

Branch pushed to git repo; I updated commit sha1. New commits:

ab757ba.github/workflows/tox.yml: Fix passing of EXTRA_DOCKER_TAGS

Changed commit from fdb49a1 to ab757ba

Changed commit from ab757ba to 96528eb

Branch pushed to git repo; I updated commit sha1. New commits:

96528eb.github/workflows/tox*.yml: Tag docker images 'latest' or 'dev' when building a release tag

Branch pushed to git repo; I updated commit sha1. New commits:

5d1dc0f.gitpod.yml: Use tag :dev

Changed commit from 96528eb to 5d1dc0f

Work Issues: Change .gitpod.yml to use sagemath instead of mkoeppe

comment:31

Also the configuration of VS Code should be improved. It seems to start up using the wrong interpreter (not venv/bin/python3), and also one needs to manually select the right Jupyter kernel.

The scipy folks have some good documentation and configuration (https://scipy.github.io/devdocs/dev/contributor/quickstart_gitpod.html), perhaps we can lift something from there.

comment:32

Is the prebuild working for this branch?

How can one work with branches that update sage packages? With #32749 one could trigger a rebuild of the docker image (and thus of the system packages) using the #imagebuild context. Can something like this also be implemented here? For example, take the github action build docker as base, and then re-install system or python packages on top of this if they have newer versions?

For the VS integration, #30677 is closed but not yet merged into develop.

comment:33

Replying to @tobiasdiez:

Is the prebuild working for this branch?

I've just merged #33071 into the branch https://github.com/mkoeppe/sage/tree/mkoeppe-9.5.beta9%2Bupdates to try this out.

How can one work with branches that update sage packages?

Nothing special, make just rebuilds what needs rebuilding.

comment:34

Replying to @tobiasdiez:

For the VS integration, #30677 is closed but not yet merged into develop.

I forgot to say that the branch https://github.com/mkoeppe/sage/tree/mkoeppe-9.5.beta9%2Bupdates already contains #30677 and other updates

comment:35

Replying to @mkoeppe:

Replying to @tobiasdiez:

Is the prebuild working for this branch?

I've just merged #33071 into the branch https://github.com/mkoeppe/sage/tree/mkoeppe-9.5.beta9%2Bupdates to try this out.

How can one work with branches that update sage packages?

Nothing special, make just rebuilds what needs rebuilding.

So this would then be done as part of the prebuild?

comment:36

Yes, I think so

comment:37

Looks like I'll have to add some configuration so that it does prebuilds on all branches

comment:38

I created a "project" and now it looks like the prebuild triggered by a push is running - https://gitpod.io/projects/sage

Changed commit from 5d1dc0f to 3e28e13

Branch pushed to git repo; I updated commit sha1. New commits:

3e28e13.gitpod.yml: Set github prebuild options to true
comment:40

Before the push I had merged #32968 with the Sphinx update; and the prebuild has just installed the upgraded package

comment:41

Replying to @mkoeppe:

Before the push I had merged #32968 with the Sphinx update; and the prebuild has just installed the upgraded package

That's very nice!

Branch pushed to git repo; I updated commit sha1. New commits:

49575f5.gitpod.yml: Switch to image ghcr.io/sagemath/sage/sage-docker-gitpod-standard-with-targets:dev

Changed commit from 3e28e13 to 49575f5

Changed work issues from Change .gitpod.yml to use sagemath instead of mkoeppe to none

Description changed:

--- 
+++ 
@@ -4,3 +4,6 @@
 
 To try out:
 - https://gitpod.io/#https://github.com/mkoeppe/sage/tree/mkoeppe-9.5.beta9%2Bupdates
+
+Follow-up: #33113 gitpod usability improvements
+
comment:44

The prebuild was just killed because of the 35m timeout.
What's the best choice of timeout according to your experiments?

comment:45

If its really the timeout that killed the prebuild (in which the prebuild would be green and be used for the next workspace, but maybe doesn't contain all packages) then you can go to 50min. Maybe a bit less since the docker image is quite big so this part may take some time. But essentially you have to calculate 60min - bootstrap and config (2-3min) - docker init and copying (?? min).

However, for me the prebuild often timed out after 1h (then its shown red in the project view). The only solution I've found for this is not using symlinks into /home/.

comment:46

https://gitpod.io/projects/sage/e8780c03-b8b8-4810-a772-d4cc2994b6bf shows

[sagelib-9.5.beta9] installing. Log file: /workspace/sage/logs/pkgs/sagelib-9.5.beta9.log
  [pytest] successfully installed.
  [sphinx-4.3.1] successfully installed.
make[1]: *** [Makefile:39: all-build] Terminated
make: *** [Makefile:16: build] Terminated
exit

but it is still claims "RUNNING: Prebuild in progress"

comment:47

However, https://gitpod.io/projects/sage/prebuilds shows READY.

comment:48

๐Ÿค™ This task ran as a workspace prebuild
๐ŸŽ‰ Well done on saving 37 minutes
comment:49

A few more points:

  • please use the recent version of gitpod.yml from https://github.com/tobiasdiez/sagetrac-mirror/blob/develop/.gitpod.yml (the ssh stuff and num threads = 8)
  • --prefix=$HOME/sage-local in gitpod.yml should probably be /workspace/sage-local or a few lines above $HOME should be used?
  • probably 8 parallel tasks are fine. gitpod gives 6 (or 7?) vCPUs to users.
comment:50

Replying to @mkoeppe:


๐Ÿค™ This task ran as a workspace prebuild
๐ŸŽ‰ Well done on saving 37 minutes

Nice, then you can go to 50min indeed.

Changed commit from 49575f5 to e7d4e96

Branch pushed to git repo; I updated commit sha1. New commits:

e7d4e96.gitpod.yml: Increase timeout for make in prebuild, increase parallelism
comment:52

Presumably the before script should try to resume the build in case the prebuild timed out.

comment:53

I agree. But init is called after before during the prebuild, and I couldn't find a way to detect if one is in a prebuild or not...

Branch pushed to git repo; I updated commit sha1. New commits:

fdb332d.gitpod.yml: Run 'make' again in 'before' task if prebuild 'make' timed out

Changed commit from e7d4e96 to fdb332d

Changed commit from fdb332d to aaa9777

Branch pushed to git repo; I updated commit sha1. New commits:

aaa9777.gitpod.yml: Use SAGE_NUM_THREADS=8
comment:56

Replying to @tobiasdiez:

I've updated it - the ssh stuff was already same

Changed commit from aaa9777 to 87900a7

Branch pushed to git repo; I updated commit sha1. New commits:

87900a7.gitpod.yml: Refer to /home/gitpod as /Users/mkoeppe

Branch pushed to git repo; I updated commit sha1. New commits:

0864c6e.github/workflows/tox*.yml: Push stable releases also to Docker tag 'dev'

Changed commit from 87900a7 to 0864c6e

comment:59

https://gitpod.io/projects/sage/134676a9-2a0e-429a-816d-68ad30441f58

[sphinx-4.3.1] installing. Log file: /workspace/sage/logs/pkgs/sphinx-4.3.1.log
[sagelib-9.5.beta9] installing. Log file: /workspace/sage/logs/pkgs/sagelib-9.5.beta9.log
  [pytest] successfully installed.
  [sphinx-4.3.1] successfully installed.
  [sagelib-9.5.beta9] successfully installed.
make --no-print-directory sage_docbuild-SAGE_VENV-no-deps
[sage_docbuild-9.5.beta9] installing. Log file: /workspace/sage/logs/pkgs/sage_docbuild-9.5.beta9.log
  [sage_docbuild-9.5.beta9] successfully installed.
make[2]: Leaving directory '/workspace/sage/build/make'

real    31m8.684s
user    101m44.392s
sys     3m47.093s
SAGE_CHECK=warn, so scanning the log files. This may take a few seconds.
Sage build/upgrade complete!
make[1]: Leaving directory '/workspace/sage'
exit

๐Ÿค™ This task ran as a workspace prebuild
๐ŸŽ‰ Well done on saving 34 minutes
comment:60

Replying to @sagetrac-git:

Branch pushed to git repo; I updated commit sha1. New commits:

fdb332d.gitpod.yml: Run 'make' again in 'before' task if prebuild 'make' timed out

This worked but for some reason the Sphinx package installation was repeated in this step. It's fast but I'll try if refreshing the timestamps of the install records will avoid it.

Branch pushed to git repo; I updated commit sha1. New commits:

36e0c54.gitpod.yml (before): Set timestamps of installation records to same mtime
c9fa015.gitpod.yml: Use /workspace/sage/local as physical location of SAGE_LOCAL

Changed commit from 0864c6e to c9fa015

comment:62

There are some weird synchronization issues on the server side - it seems that if one creates a workspace right after a prebuild has completed, it can happen that it does not use the prebuild.

Changed commit from c9fa015 to 38dafc6

Branch pushed to git repo; I updated commit sha1. New commits:

38dafc6.gitpod.yml (before): Refer to /workspace/sage/local by full path

Branch pushed to git repo; I updated commit sha1. New commits:

e6be067.gitpod.yml (init): Make sure to remove the directory /home/gitpod/sage-local

Changed commit from 38dafc6 to e6be067

Changed commit from e6be067 to cdcf2ac

Branch pushed to git repo; I updated commit sha1. New commits:

cdcf2ac.gitpod.yml (before): establish SAGE_LOCAL here, not in 'init'

Branch pushed to git repo; I updated commit sha1. New commits:

5b44b6b.gitpod.yml: Remove install-record timestamping
f58453d.gitpod.yml: Also remove the source tree used by the Docker build

Changed commit from cdcf2ac to f58453d

Changed commit from f58453d to aef75eb

Branch pushed to git repo; I updated commit sha1. New commits:

aef75eb.gitpod.yml (before): Always remove the source tree used by the Docker build
comment:68

OK, now it's in good shape.

Could you check that the SSH stuff works as intended and matches the added documentation?
I see

$ ls -l ~/.ssh
total 24
-rw-r--r-- 1 gitpod gitpod   381 Jan  4 08:53 authorized_keys
-rw------- 1 gitpod gitpod     0 Jan  4 08:53 id_rsa
-rw-r--r-- 1 gitpod gitpod   664 Jan  4 08:53 known_hosts
-rw-r--r-- 1 gitpod gitpod 15544 Jan  4 08:53 supervisor_env

and am not sure what the empty id_rsa is intended for

comment:70

sagemath/sagetrac-mirror@develop...u/mkoeppe/gitpod_integration_using_docker_images_from_portability_testing_workflow#diff-370a022e48cb18faf98122794ffc5ce775b2606b09a9d1f80b71333425ec078eR17

I'm not sure if I understand the logic behind this and related commands (maybe add a bit more documentation of what's going on?). But please be aware that the code may be in a different location such as /workspace/sagetrac-mirror if someone starts gitpod from https://github.com/sagemath/sagetrac-mirror (which is probably what's going to happen if you want to check someone elses branch)

comment:71

Replying to @mkoeppe:

Could you check that the SSH stuff works as intended and matches the added documentation?
and am not sure what the empty id_rsa is intended for

Did you added a PRIVATE_SSH_KEY env variable in gitpod with your trac ssh as described in the docs? It's working for me.

comment:72

Replying to @mkoeppe:

OK, now it's in good shape.

For me it takes over 5min to start a workspace due to the large workspace image (it displays "fetching build image" or something like this in the loading screen). I think this should be optimized as part of this ticket since otherwise I fear people will not adopt gitpod for e.g. reviewing of tickets.

Also it still loads pyenv: pyenv shell 3.8.12 so https://github.com/tobiasdiez/sagetrac-mirror/blob/20ca179bed4ff605de4111362b02c8e2acca617e/.gitpod.yml#L18-L19 should probably be readded.