Skip to content

Commit 788281e

Browse files
author
Release Manager
committed
Trac #33739: Migrate gitpod to conda
The current solution to prebuild the gitpod docker image using github actions does not work nicely, since prebuilds triggered shortly after a new release still use the old gitpod image (and it may take up to a few days until the new image is available). This is especially notable for the `develop` branch, which is the default entry point if you want to start a new branch on gitpod. In this ticket, we migrate the gitpod config to use the conda environment, which is now generally stable enough for serious development (e.g. almost all tests pass). As a positive side effect, the gitpod config simplifies and startup times are considerably reduced. URL: https://trac.sagemath.org/33739 Reported by: gh-tobiasdiez Ticket author(s): Tobias Diez Reviewer(s): Matthias Koeppe
2 parents c2ca6af + 5748c21 commit 788281e

File tree

6 files changed

+37
-99
lines changed

6 files changed

+37
-99
lines changed

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
fail-fast: false
3939
max-parallel: 20
4040
matrix:
41-
tox_system_factor: [gitpod, ubuntu-trusty, ubuntu-xenial, ubuntu-bionic, ubuntu-focal, ubuntu-hirsute, ubuntu-impish, ubuntu-jammy, debian-stretch, debian-buster, debian-bullseye, debian-bookworm, debian-sid, linuxmint-17, linuxmint-18, linuxmint-19, linuxmint-19.3, linuxmint-20.1, linuxmint-20.2, linuxmint-20.3, fedora-26, fedora-27, fedora-28, fedora-29, fedora-30, fedora-31, fedora-32, fedora-33, fedora-34, fedora-35, fedora-36, centos-7, centos-stream-8, gentoo-python3.9, gentoo-python3.10, archlinux-latest, opensuse-15.3, opensuse-tumbleweed, slackware-14.2, conda-forge, ubuntu-bionic-i386, manylinux-2_24-i686, debian-buster-i386, centos-7-i386]
41+
tox_system_factor: [ubuntu-trusty, ubuntu-xenial, ubuntu-bionic, ubuntu-focal, ubuntu-hirsute, ubuntu-impish, ubuntu-jammy, debian-stretch, debian-buster, debian-bullseye, debian-bookworm, debian-sid, linuxmint-17, linuxmint-18, linuxmint-19, linuxmint-19.3, linuxmint-20.1, linuxmint-20.2, linuxmint-20.3, fedora-26, fedora-27, fedora-28, fedora-29, fedora-30, fedora-31, fedora-32, fedora-33, fedora-34, fedora-35, fedora-36, centos-7, centos-stream-8, gentoo-python3.9, gentoo-python3.10, archlinux-latest, opensuse-15.3, opensuse-tumbleweed, slackware-14.2, conda-forge, ubuntu-bionic-i386, manylinux-2_24-i686, debian-buster-i386, centos-7-i386]
4242
tox_packages_factor: [minimal, standard]
4343
env:
4444
TOX_ENV: docker-${{ matrix.tox_system_factor }}-${{ matrix.tox_packages_factor }}

.gitpod.yml

Lines changed: 27 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
11
# Use custom docker image. https://www.gitpod.io/docs/config-docker
22
image:
3-
# Each of these two options works:
4-
# - Directly use the "-with-targets" image built by .github/workflows/tox.yml
5-
# image: ghcr.io/sagemath/sage/sage-docker-gitpod-standard-with-targets:dev
6-
# - or go through a custom Dockerfile, which builds a smaller image
7-
# based on the "-with-system-packages" image built by .github/workflows/tox.yml
8-
# with the built SAGE_LOCAL from the "-with-targets" image copied in.
9-
file: docker/.gitpod.Dockerfile
10-
11-
# We use the following layout:
12-
#
13-
# $HOME/sage Source tree used by the Docker build; see SAGE_ROOT/tox.ini (gitpod).
14-
# - We delete it in every invocation of the 'before' script
15-
# and replace it by a symlink to /workspace/...
16-
# (This symlink is needed because the package-removal scripts
17-
# ({prefix,venv}/var/lib/sage/scripts/*/{spkg-piprm,spkg-prerm,spkg-postrm)
18-
# hardcode SAGE_ROOT and SAGE_SRC from package installation time)
19-
# $HOME/sage/logs Logs of the Docker build.
20-
# - In the first invocation of the 'before' script, we move it
21-
# to /workspace/.../logs
22-
# $HOME/sage-local The configured prefix (SAGE_LOCAL) of the Sage installation.
23-
# - During the Docker build, this is the physical location.
24-
# - In the first invocation of the 'before' script, we move it
25-
# to the new physical location /workspace/.../local
26-
# (because gitpod only preserves the contents of /workspace)
27-
# and replace it by a symlink to the new physical location.
28-
# - In subsequent invocations of the 'before' script, we
29-
# remove it and replace it by a symlink to the physical
30-
# location /workspace/.../local
31-
# /worktree/.../local The physical location of the Sage installation,
32-
# established in the first run of the 'before' script and
33-
# preserved by gitpod.
3+
file: docker/.gitpod.Dockerfile
344

355
# Start up tasks. https://www.gitpod.io/docs/config-start-tasks/
366
tasks:
377
- name: Setup
38-
before: |
8+
init: |
9+
# Create conda environment
10+
./bootstrap-conda
11+
mamba env create --file src/environment-dev.yml --prefix venv
12+
conda config --append envs_dirs /workspace/sagetrac-mirror
13+
conda activate /workspace/sagetrac-mirror/venv
14+
15+
# Build sage
16+
./bootstrap
17+
./configure --enable-build-as-root --with-python=$CONDA_PREFIX/bin/python --prefix=$CONDA_PREFIX
18+
pip install --no-build-isolation -v -v -e ./pkgs/sage-conf ./pkgs/sage-setup
19+
pip install --no-build-isolation -v -v -e ./src
20+
21+
command: |
22+
# Activate conda environment
23+
conda config --append envs_dirs /workspace/sagetrac-mirror
24+
conda activate /workspace/sagetrac-mirror/venv
25+
26+
# RestructuredText extension recommends python extension, although we have already installed it
27+
## So disable the recommendation dialog
28+
echo "{\"restructuredtext.pythonRecommendation.disabled\": true}" > /workspace/.vscode-remote/data/Machine/settings.json
29+
3930
# Setup trac as remote
4031
## In order to push to trac, generate a new key with `ssh-keygen -f tempkey` and save the private key to gitpod `gp env PRIVATE_SSH_KEY="$(<tempkey)"` (or by following https://www.gitpod.io/docs/environment-variables#using-the-account-settings)
4132
## then follow https://doc.sagemath.org/html/en/developer/trac.html#linking-your-public-key-to-your-trac-account to register the public key with trac.
@@ -47,7 +38,7 @@ tasks:
4738
echo $PRIVATE_SSH_KEY | sed 's/\(-----\(BEGIN\|END\) OPENSSH PRIVATE KEY-----\)/\n\1\n/g' > ~/.ssh/id_rsa
4839
sed -i '/^$/d' ~/.ssh/id_rsa
4940
chmod 600 ~/.ssh/id_rsa
50-
unset PRIVATE_SSH_KEY
41+
echo "PubkeyAcceptedKeyTypes +ssh-rsa" > ~/.ssh/config
5142
ssh-keyscan -H trac.sagemath.org >> ~/.ssh/known_hosts
5243
5344
# Setup trac repo
@@ -60,43 +51,7 @@ tasks:
6051
git remote add trac https://github.com/sagemath/sagetrac-mirror.git -t master -t develop
6152
git remote set-url --push trac pushing-needs-ssh-key
6253
fi
63-
64-
## No need for pyenv
65-
pyenv shell --unset 2> /dev/null
66-
pyenv global system 2> /dev/null
67-
if [ -d local ]; then
68-
mkdir -p logs && echo '### .gitpod.yml Setup.before: Prebuild init script has been run. Running "make" again in case the build had timed out.' >> logs/install.log
69-
# The init script has already populated the SAGE_LOCAL,
70-
# but only /workspace is preserved; and the $HOME/sage-local may contain a resurrected
71-
# copy of sage-local. Replace it again by a symlink.
72-
rm -Rf $HOME/sage-local
73-
ln -sf $(pwd)/local $HOME/sage-local
74-
# Now run make. No timeout here.
75-
MAKE='make -j24' make build V=0
76-
else
77-
# Prebuild init script has not been run
78-
# Only /workspace is preserved during build.
79-
# If the Docker image contains a built SAGE_LOCAL, use it to populate the SAGE_LOCAL in the workspace.
80-
if [ -d $HOME/sage-local ]; then
81-
mv $HOME/sage-local local
82-
fi
83-
rm -Rf $HOME/sage-local
84-
ln -sf $(pwd)/local $HOME/sage-local
85-
# Save the logs of the source tree used by the Docker build
86-
if [ -d $HOME/sage/logs ]; then
87-
mv $HOME/sage/logs logs
88-
fi
89-
fi
90-
# Remove the source tree used by the Docker build and replace it by a symlink
91-
rm -Rf $HOME/sage
92-
ln -s $(pwd) $HOME/sage
93-
init: |
94-
# Start build
95-
mkdir -p logs && echo '### .gitpod.yml Setup.init: Starting build' >> logs/install.log
96-
./bootstrap
97-
./configure --enable-editable --enable-download-from-upstream-url --prefix=$HOME/sage-local --with-sage-venv
98-
## Gitpod has a timeout of 1h, so make sure we are below this to ensure that the prebuild is always successful
99-
MAKE='make -j24' timeout 51m make build V=0 || echo "(ignoring error)"
54+
10055
env:
10156
SAGE_NUM_THREADS: 8
10257

@@ -109,6 +64,8 @@ vscode:
10964
- lextudio.restructuredtext
11065
- streetsidesoftware.code-spell-checker
11166
- ms-toolsai.jupyter
67+
- ms-toolsai.jupyter-keymap
68+
- ms-toolsai.jupyter-renderers
11269

11370
# https://www.gitpod.io/docs/prebuilds#github-specific-configuration
11471
github:

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"--doctest-modules",
2222
],
2323
"python.testing.unittestEnabled": false,
24+
"python.linting.pycodestyleEnabled": true,
25+
"python.linting.enabled": true,
2426
"cSpell.words": [
2527
"furo"
2628
"Conda",

bootstrap-conda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ echo " # Additional dev tools" >> src/environment-dev.yml
6565
echo " - openssh" >> src/environment-dev.yml
6666
echo " - pycodestyle" >> src/environment-dev.yml
6767
echo " - pytest" >> src/environment-dev.yml
68+
echo " - esbonio" >> src/environment-dev.yml
6869

6970
cp environment.yml environment-optional.yml
7071
echo " # optional packages" >> environment-optional.yml

docker/.gitpod.Dockerfile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
ARG BASE_GITHUB_REPOSITORY=sagemath/sage
2-
ARG BASE_TAG=dev
3-
FROM ghcr.io/${BASE_GITHUB_REPOSITORY}/sage-docker-gitpod-standard-with-targets:${BASE_TAG} as with-targets
4-
RUN sudo rm -rf /var/cache/debconf/* /var/lib/apt/lists/* /tmp/* /var/tmp/*
5-
# Fast doc rebuilds do not work because
6-
# "loading pickled environment... failed; source directory has changed"
7-
# Until this is fixed, we can as well remove the whole documentation, which saves a lot of space.
8-
RUN rm -Rf /home/gitpod/sage-local/share/doc/sage
9-
10-
FROM ghcr.io/${BASE_GITHUB_REPOSITORY}/sage-docker-gitpod-standard-with-system-packages:${BASE_TAG}
11-
COPY --chown=gitpod:gitpod --from=with-targets /home/gitpod/sage/logs /home/gitpod/sage/logs
12-
COPY --chown=gitpod:gitpod --from=with-targets /home/gitpod/sage-local /home/gitpod/sage-local
1+
# Use minimal Ubuntu installation that includes mamba
2+
FROM condaforge/mambaforge
3+
# Workaround so that vscode internals (such as git) find things installed in the conda env (notably ssh which is required to contribute to trac)
4+
ENV PATH $PATH:/workspace/sagetrac-mirror/venv/bin
5+
# Default to non-admin user
6+
USER gitpod

tox.ini

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -437,22 +437,6 @@ setenv =
437437
ubuntu-bionic-nvidia-cuda: BASE_TAG=ubuntu18.04
438438
ubuntu-xenial-nvidia-cuda: BASE_TAG=ubuntu16.04
439439
#
440-
# https://hub.docker.com/r/gitpod/
441-
#
442-
gitpod: SYSTEM=debian
443-
gitpod: BASE_IMAGE=gitpod/workspace-base
444-
gitpod-full: BASE_IMAGE=gitpod/workspace-full
445-
gitpod: CONFIG_CONFIGURE_ARGS_ROOT=--prefix=/home/gitpod/sage-local --with-sage-venv
446-
gitpod: __SUDO=--sudo
447-
gitpod: __CHOWN=--chown=gitpod:gitpod
448-
# Play safe and make sure that the image build succeeds even
449-
# if packages that do not exist on ubuntu-focal are added to debian.txt
450-
gitpod: IGNORE_MISSING_SYSTEM_PACKAGES=yes
451-
# As of 2022-01, gitpod/workspace-base is based on ubuntu-focal.
452-
# To save space, we filter out some packages that are too old and
453-
# will be rejected by our configure script.
454-
gitpod-standard: SAGE_PACKAGE_LIST_ARGS=--has-file=spkg-configure.m4 :standard: --exclude pari --exclude eclib --exclude lcalc --exclude giac --exclude singular
455-
#
456440
# Resulting full image:tag name
457441
#
458442
docker: FULL_BASE_IMAGE_AND_TAG={env:ARCH_IMAGE_PREFIX:}{env:BASE_IMAGE}{env:ARCH_IMAGE_SUFFIX:}:{env:ARCH_TAG_PREFIX:}{env:BASE_TAG}{env:ARCH_TAG_SUFFIX:}

0 commit comments

Comments
 (0)