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

Pre-install some extensions on code-server notebook #347

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

atheo89
Copy link
Member

@atheo89 atheo89 commented Nov 15, 2023

Related to: #336

Description

By default, code-server does not come with any installed extensions. This pull request aims to streamline the user experience by pre-installing several useful extensions on behalf of the end user. The extensions that we added are:

  • Jupyter (ms-toolsai.jupyter)
  • python (ms-python.python)

Test image: quay.io/rh_ee_atheodor/workbench-images@sha256:ac16959bffb660397247100666729b314eb78a8b0ec387131b878697d3cb1e48

How Has This Been Tested?

  1. Spin up ODH
  2. Edit the code-server-notebook imagestream by adding the following tag, Builds > ImageStreams
    - name: 'new'
      annotations:
        opendatahub.io/notebook-python-dependencies: '[{"name":"code-sever","version":"4.11"}]'
        opendatahub.io/notebook-software: '[{"name":"Python","version":"v3.9"}]'
        openshift.io/imported-from: quay.io/opendatahub/workbench-images
      from:
        kind: DockerImage
        name: >-
         quay.io/rh_ee_atheodor/workbench-images@sha256:ac16959bffb660397247100666729b314eb78a8b0ec387131b878697d3cb1e48
      importPolicy: {}
      referencePolicy:
        type: Source
  1. Enter on DSP and trigger a vs code using the new tag that you created above.

  2. Inspect on the extension tab, and check if there are already installed extensions.
    You should see the following:
    image

  3. Or by a terminal should type: code-server --list-extensions
    You should see the following:
    image

  4. To locally test the notebook in air-gap env disconnect your internet connection and trigger by using
    podman run --network=host --name validation-container quay.io/rh_ee_atheodor/workbench-images@sha256:ac16959bffb660397247100666729b314eb78a8b0ec387131b878697d3cb1e48

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@openshift-ci openshift-ci bot requested review from dibryant and harshad16 November 15, 2023 15:14
Copy link
Member

@harshad16 harshad16 left a comment

Choose a reason for hiding this comment

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

great work,
just had one suggestion.

codeserver/ubi9-python-3.9/run-code-server.sh Outdated Show resolved Hide resolved
Copy link
Member

@harshad16 harshad16 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

thanks for the work 💯

Copy link
Contributor

openshift-ci bot commented Dec 6, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: harshad16

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Dec 6, 2023
Copy link
Contributor

openshift-ci bot commented Dec 6, 2023

@atheo89: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/notebooks-e2e-tests 0ffca51 link unknown /test notebooks-e2e-tests

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@harshad16 harshad16 merged commit 9e1ed7a into opendatahub-io:main Dec 6, 2023
3 of 5 checks passed
Copy link

@shalberd shalberd Feb 18, 2024

Choose a reason for hiding this comment

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

@atheo89 is there a particular reason you selected Version 2023.3.100 for the Jupyter extension? when I go to marketplace visualstudio, I get 2024 versions and there are a bunch of changelogs for e.g. February 2024 milestone

Does it have something to do with Codeserver 4.16.1 vs. Visual Studio proper? I guess for one thing, the location to go to for extensions is openvsx vs the official marketplace. But then, even there, the latest version is 2023.9.100

coder/code-server#6323 (comment)

Codeserver 4.16.1 ist VS Code 1.80.2 https://github.com/coder/code-server/releases?page=2 so I guess that might have played a role in your considerations for 2023.3.100?

Disclaimer: I am asking because I've got some extension requests unrelated to these here from a user and just now getting into the topic, i.e. Codeserver custom container build.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @shalberd , the reason we specifically selected these versions of the extension is to ensure compatibility with code-server version 4.16.1.

Choose a reason for hiding this comment

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

Hi @atheo89 ok, from the vsx marketplace, or from the Github pages of the components, how can I see which code-server version or VS Code version the extension is for? I am looking for a kind of compatibility info. I do understand that
Codeserver 4.16.1 is VS Code 1.80.2, in essence.

Copy link
Member Author

Choose a reason for hiding this comment

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

When installing an extension without specifying the version, code-server automatically selects the most compatible one. You can initially install them without specifying a version, then determine compatibility by running code --show-versions.

Copy link

@shalberd shalberd Feb 19, 2024

Choose a reason for hiding this comment

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

@atheo89 found it, though with some research on stackoverflow, it is the package.json engine entry that shows the required version of code server / VS Code. https://github.com/microsoft/vscode-python/blob/main/package.json#L47 sorry for my long asking around, maybe this also helps others in future. Case closed.

Copy link
Member Author

Choose a reason for hiding this comment

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

We downloaded the packages from vsx marketplace

Choose a reason for hiding this comment

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

I am mostly focused on offline install, that is why I was looking around for this info so much.

Copy link

@shalberd shalberd Feb 19, 2024

Choose a reason for hiding this comment

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

We downloaded the packages from vsx marketplace

Yes, but very un-user-friendly, the marketplace does not show the required code server / VS Code version. One always has to go to the engines section of package.json ...

You can initially install them without specifying a version, then determine compatibility by running code > --show-versions.

Yeah, though this is kinda complicated for a pure airgapped install, deciding which version to put into utils.

Thank you for your help, I know how to proceed now, also with more / other extensions to ensure compatibility (package.json)

Copy link

@shalberd shalberd Feb 19, 2024

Choose a reason for hiding this comment

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

@atheo89 @harshad16 there is a problem with this approach and current Notebooks when installing more than just these few extensions at runtime. The defaults for liveness and readiness probe times come from odh-dashboard, I think, when assembling the notebook CR.

          name: code-server-vs
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /notebook/dstst-analytix-fraud/code-server-vs/api
              port: notebook-port
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 5
            successThreshold: 1
            timeoutSeconds: 1

Because installing extensions takes some time at the code-server-vs/api health check endpoint is not up and running until after all extensions install and the nginx http server is running, the container keeps re-starting without more than 5 or 6 extensions ever installed.

I solved this by patching the notebook CR to have a large initialDelaySeconds of 100, so then code server started.

What do you think? @guimou do you have an idea of how to circumvent this problem of premature container restart due to failing liveness probes when installing more than, say, 6 or 7 extensions?

@guimou
Copy link
Member

guimou commented Feb 19, 2024 via email

@shalberd
Copy link

shalberd commented Feb 19, 2024

@guimou about not installing any extensions and about the whole Jupyter stuff in general in VS Code:

yes, though some things like material theme and other GUI things like German language pack are quite useful actually.

about not installing any extensions and letting users install them:

that is a good solution in non-airgapped environments. But in environments like ours, with a proxy not allowing connections to marketplaces, pypi.org and so on, this command-based install of extensions by providing them in the file system is the only way to go. I guess @atheo89 also had some restricted network customers in her automotive environment south of the Alps.

Here's some example ;-)

        code-server --install-extension ${SCRIPT_DIR}/utils/steoates.autoimport-1.5.3.vsix
        code-server --install-extension ${SCRIPT_DIR}/utils/njpwerner.autodocstring-0.6.1.vsix
        code-server --install-extension ${SCRIPT_DIR}/utils/aaron-bond.better-comments-3.0.2.vsix
        code-server --install-extension ${SCRIPT_DIR}/utils/alefragnani.Bookmarks-13.0.1.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/Catppuccin.catppuccin-vsc-3.10.1.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/formulahendry.code-runner-0.12.1.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/streetsidesoftware.code-spell-checker-3.0.0.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/streetsidesoftware.code-spell-checker-german-2.3.1.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/MS-CEINTL.vscode-language-pack-de-1.80.0.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/davidlday.languagetool-linter-0.20.0.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/PKief.material-icon-theme-4.33.0.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/ionutvmi.path-autocomplete-1.25.0.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/alefragnani.project-manager-12.0.1.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/KevinRose.vsc-python-indent-1.18.0.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/donjayamanne.python-environment-manager-1.0.4.vsix
        code-server --install-extension ${SCRIPT_DIR}/utils/hbenl.test-adapter-converter-0.1.6.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/hbenl.vscode-test-explorer-2.21.1.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/LittleFoxTeam.vscode-python-test-adapter-0.8.2.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/njqdev.vscode-python-typehint-1.4.0.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/ms-python.black-formatter-2023.6.0.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/wmaurer.change-case-1.0.0.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/mgesbert.python-path-0.0.14.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/dongli.python-preview-0.0.4.vsix
	code-server --install-extension ${SCRIPT_DIR}/utils/Semgrep.semgrep-1.6.3.vsix

I wonder if there is a better way than doing the code-server --install-extension at runtime.
Ideally, this would be done at build time and then perhaps only copied to the .local user app root at runtime ...

@guimou
Copy link
Member

guimou commented Feb 19, 2024 via email

@shalberd
Copy link

shalberd commented Feb 19, 2024

@guimou Yes, this is what I did on contrib workbench images builder. I added a custom ide snippet for my vscode and used the logic here, with all the extensions I need in the utils folder.

We can't impose all sorts of extensions, even a few, to everyone just to cover this specific case.

But we could make this a special case or extended snippet, i.e. Code Server Airgapped Extensions, of Code Server in contrib workbench-images builder.

However, the current approach here to install extensions fails due to the imposed liveness probe (initialDelaySeconds: 10) that I had to manually patch to be waiting 100s initially so the extension install can run through.

Since liveness probe is something that is statically created by odh dashboard, this is not very good.

Best way to install extensions would be with an init container mechanism, but we don't have that option with Notebook CRs here, I think. Another users in the comments below also tried to bake in the extensions at build time, I'll see what I can do. I don't want them installed at runtime in the entrypoint script, due to the liveness probe timeout problem I described.

Best way would be to have an init Container in the pod that runs before
the main pod and installs the extensions.

coder/code-server#4778 (comment)

https://github.com/coder/code-server/blob/439f27c5685d3aeba158269d162f1bf800482295/docs/helm.md#extra-containers

Since that is not possible, I'm just creating a dedicated extensions (installed extensions) dir at /opt/app-root/share/codeserver/extensions outside the mounted volume context in the Containerfile.

I then install the extensions in the Containerfile instead of the entrypoint script, with an --extensions-dir /opt/app-root/share/codeserver/extensions additional argument. Then, in the code-server run command in run-code-server.sh, I also add an additional argument --extensions-dir /opt/app-root/share/codeserver/extensions \

This works, of course, also having the usual directory permissions fixes for the new directory. Extensions are now baked in for airgapped.

@harshad16
Copy link
Member

harshad16 commented Feb 22, 2024

Thanks @shalberd and @guimou , i will convert this into an issue
so we can have this and work on this as we proceed.

Please use this: #421 for further discussion.

jstourac pushed a commit to jstourac/notebooks that referenced this pull request Aug 29, 2024
[pull] release-2023b from opendatahub-io:2023b
@atheo89 atheo89 deleted the pre-intall-ext branch October 23, 2024 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants