From c1f5cda7ad3791d3aa8886bc7177c3cc7743b012 Mon Sep 17 00:00:00 2001 From: Tony Fellet Date: Wed, 30 Nov 2022 16:44:29 +0100 Subject: [PATCH] Vscode 4.8 (#178) * feat: vscode 4.8 --- technologies/app/vscode/README.md | 25 ++-- technologies/app/vscode/metadata.yaml | 33 +++++- .../app/vscode/vscode-4.8-python/Dockerfile | 112 ++++++++++++++++++ .../resources/project-settings.json | 3 + .../vscode-4.8-python/resources/settings.json | 7 ++ technologies/app/vscode/vscode-4.8/Dockerfile | 42 +++++++ .../vscode/vscode-4.8/resources/entrypoint.sh | 14 +++ .../vscode-4.8/resources/fix-permissions | 35 ++++++ .../app/vscode/vscode-4.8/resources/nginx-run | 13 ++ .../vscode/vscode-4.8/resources/nginx.conf | 26 ++++ .../vscode/vscode-4.8/resources/settings.json | 3 + version.properties | 6 +- 12 files changed, 306 insertions(+), 13 deletions(-) create mode 100644 technologies/app/vscode/vscode-4.8-python/Dockerfile create mode 100644 technologies/app/vscode/vscode-4.8-python/resources/project-settings.json create mode 100644 technologies/app/vscode/vscode-4.8-python/resources/settings.json create mode 100644 technologies/app/vscode/vscode-4.8/Dockerfile create mode 100644 technologies/app/vscode/vscode-4.8/resources/entrypoint.sh create mode 100644 technologies/app/vscode/vscode-4.8/resources/fix-permissions create mode 100644 technologies/app/vscode/vscode-4.8/resources/nginx-run create mode 100644 technologies/app/vscode/vscode-4.8/resources/nginx.conf create mode 100644 technologies/app/vscode/vscode-4.8/resources/settings.json diff --git a/technologies/app/vscode/README.md b/technologies/app/vscode/README.md index 5e14946..d15d8d6 100644 --- a/technologies/app/vscode/README.md +++ b/technologies/app/vscode/README.md @@ -3,23 +3,32 @@ ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/saagie/vscode-server/3.9.3?label=v3.9.3%20image%20size&style=for-the-badge) ## Description + This directory contains a VsCode server contenairized and customized for Saagie Platform. -See Vscode server official documentation for more information https://code.visualstudio.com/docs/ +See Vscode server official documentation for more information . +This image is based on [linuxserver/docker-code-server](https://github.com/linuxserver/docker-code-server). ## How to build in local -``` +```bash docker build -t saagie/vscode-server . -docker push saagie/vscode-server ``` ## How to run image in local +```bash +docker run --rm -it -e SAAGIE_BASE_PATH=/ -p 8443:8443 saagie/vscode-server ``` -docker build -t saagie/vscode-server . -docker run -e "SAAGIE_BASE_PATH=/hello" -p 80:80 saagie/vscode-server -``` -And access it with this adress: [localhost/hello/](localhost/hello/) + +And access it with this adress: [localhost:8443/](localhost:8443/) ## Job/App specific information -If you want to configure a password to access your VsCode Server, you need to setup an environment Variable named "PASSWORD" and enter your password (see Saagie [documentation](https://docs.saagie.io/user/latest/tutorials/projects-module/projects/envar/index.html#projects-create-envar-global)) \ No newline at end of file + +You can customize this application with the following parameters: + +- "VSCODE_PASSWORD": Password to access the VSCode interface. +- "VSCODE_HASHED_PASSWORD": Same functionality as "VSCODE_PASSWORD", but hashed. +- "VSCODE_SUDO_PASSWORD": Allows to use sudo commands in VSCode terminal. +- "VSCODE_SUDO_PASSWORD_HASH": Same functionality as "VSCODE_SUDO_PASSWORD", but hashed. + +To set these variables in your project, see Saagie [documentation](https://docs.saagie.io/user/latest/tutorials/projects-module/projects/envar/index.html#projects-create-envar-global). diff --git a/technologies/app/vscode/metadata.yaml b/technologies/app/vscode/metadata.yaml index a87f175..251ffe4 100644 --- a/technologies/app/vscode/metadata.yaml +++ b/technologies/app/vscode/metadata.yaml @@ -3,8 +3,9 @@ type: APP id: vscode label: VS Code baseline: "VS Code server" -description: "VS Code server is an IDE that supports several languages. \nCreate an environment variable named 'PASSWORD' to set a password for the interface, - and SUDO_PASSWORD to get sudo access inside the container." +description: "VS Code server is an IDE that supports several languages. \n + Create an environment variable named 'VSCODE_PASSWORD' to set a password for the interface, + and VSCODE_SUDO_PASSWORD to get sudo access inside the container." available: true icon: vscode backgroundColor: "#3EAAF2" @@ -52,3 +53,31 @@ contexts: dockerInfo: image: saagie/vscode-server version: python-4.1.0-10 + - id: vscode-4.8.3 + label: VS Code 4.8.3 + releaseNotes: "" + available: true + trustLevel: experimental + ports: + - port: 80 + name: vscode + rewriteUrl: false + basePath: SAAGIE_BASE_PATH + volumes: ["/config/workspace", "/config/data/User"] + dockerInfo: + image: saagie/vscode-server + version: "4.8" + - id: vscode-python-4.8.3 + label: VS Code Python 4.8.3 + releaseNotes: "" + available: true + trustLevel: experimental + ports: + - port: 80 + name: vscode + rewriteUrl: false + basePath: SAAGIE_BASE_PATH + volumes: ["/config/workspace", "/config/data/User"] + dockerInfo: + image: saagie/vscode-server + version: python-4.8 diff --git a/technologies/app/vscode/vscode-4.8-python/Dockerfile b/technologies/app/vscode/vscode-4.8-python/Dockerfile new file mode 100644 index 0000000..7dff938 --- /dev/null +++ b/technologies/app/vscode/vscode-4.8-python/Dockerfile @@ -0,0 +1,112 @@ +FROM saagie/python:3.9-1.109.0 AS PYTHON39 +FROM saagie/vscode-server:4.8 + +RUN apt-get update \ + && apt-get install -qqy --no-install-recommends \ + wget \ + gcc \ + g++ \ + libsasl2-2 \ + libsasl2-modules-ldap \ + build-essential \ + unixodbc \ + unixodbc-dev \ + libpq-dev \ + libsqlite3-dev \ + libkrb5-dev \ + libsasl2-dev \ + libssl-dev \ + libcurl4-openssl-dev \ + libgeos-dev \ + swig \ + python3-matplotlib \ + python3-lxml \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/ + +ARG NB_UID="1000" +ARG NB_GID="100" + +ENV CONDA_DIR=/opt/conda \ + SHELL=/bin/bash \ + NB_UID=${NB_UID} \ + NB_GID=${NB_GID} \ + LC_ALL=en_US.UTF-8 \ + LANG=en_US.UTF-8 \ + LANGUAGE=en_US.UTF-8 +ENV PATH="${CONDA_DIR}/bin:${PATH}" + +# Install miniforge +ARG CONDA_MIRROR=https://github.com/conda-forge/miniforge/releases/latest/download + +# ---- Miniforge installer ---- +# Check https://github.com/conda-forge/miniforge/releases +# Package Manager and Python implementation to use (https://github.com/conda-forge/miniforge) +# We're using Mambaforge installer, possible options: +# - conda only: either Miniforge3 to use Python or Miniforge-pypy3 to use PyPy +# - conda + mamba: either Mambaforge to use Python or Mambaforge-pypy3 to use PyPy +# Installation: conda, mamba, pip +RUN set -x && \ + # Miniforge installer + miniforge_arch=$(uname -m) && \ + miniforge_installer="Mambaforge-Linux-${miniforge_arch}.sh" && \ + wget --quiet "${CONDA_MIRROR}/${miniforge_installer}" && \ + /bin/bash "${miniforge_installer}" -f -b -p "${CONDA_DIR}" && \ + rm "${miniforge_installer}" && \ + # Conda configuration see https://conda.io/projects/conda/en/latest/configuration.html + conda config --system --set auto_update_conda false && \ + conda config --system --set show_channel_urls true && \ + if [[ "${PYTHON_VERSION}" != "default" ]]; then mamba install --quiet --yes python="${PYTHON_VERSION}"; fi && \ + # Pin major.minor version of python + mamba list python | grep '^python ' | tr -s ' ' | cut -d ' ' -f 1,2 >> "${CONDA_DIR}/conda-meta/pinned" && \ + # Using conda to update all packages: https://github.com/mamba-org/mamba/issues/1092 + conda update --all --quiet --yes && \ + conda clean --all -f -y && \ + fix-permissions "${CONDA_DIR}" + +# Create 3 conda envs +RUN conda create -n py38 python=3.8.12 \ + && bash -c "source activate py38 && conda install notebook ipykernel -y && ipython kernel install --user --name py38 --display-name 'Python 3.8'" \ + && conda create -n py39 python=3.9.10 \ + && bash -c "source activate py39 && conda install notebook ipykernel -y && ipython kernel install --user --name py39 --display-name 'Python 3.9'" \ + && conda create -n py310 python=3.10.2 \ + && bash -c "source activate py310 && conda install notebook ipykernel -y && ipython kernel install --user --name py310 --display-name 'Python 3.10'" \ + && conda clean -ay \ + && rm -rf ~/.cache/pip \ + && fix-permissions "${CONDA_DIR}" + +# Get requirements from Saagie Python image +COPY --from=PYTHON39 /tmp/requirements.txt /tmp/requirements.txt + +SHELL ["/bin/bash", "-c"] + +# Install requirements from Saagie Python image +RUN sh -x \ + && for env in py38 py39 py310; \ + do \ + . activate $env \ + && python -m pip install --no-cache-dir -r /tmp/requirements.txt \ + && conda deactivate; \ + done \ + && conda clean -ay \ + && rm -rf ~/.cache/pip \ + && fix-permissions "${CONDA_DIR}" + + +# Install Vscode Python extension +RUN /app/code-server/bin/code-server --extensions-dir /config/extensions/ --install-extension ms-python.python + +# # # Change settings to run interactive code in jupyter +# COPY resources/* /config/data/User/ +RUN rm /tmp/settings/settings.json +COPY resources/* /tmp/settings/ + +ENV CONDA_DEFAULT_ENV=py310 + +# Setup user env and prefix environment variables with VSCODE_ +RUN conda init bash \ + && echo "conda activate py310" >> ~/.bashrc \ + && sed -i '2s|^|\ + mkdir -p /config/workspace/.vscode \n \ + cp -u /tmp/settings/project-settings.json /config/workspace/.vscode/settings.json \n \ + |' /etc/s6-overlay/s6-rc.d/svc-code-server/run diff --git a/technologies/app/vscode/vscode-4.8-python/resources/project-settings.json b/technologies/app/vscode/vscode-4.8-python/resources/project-settings.json new file mode 100644 index 0000000..f4a65b1 --- /dev/null +++ b/technologies/app/vscode/vscode-4.8-python/resources/project-settings.json @@ -0,0 +1,3 @@ +{ + "python.defaultInterpreterPath": "/opt/conda/envs/py310/bin/python" +} \ No newline at end of file diff --git a/technologies/app/vscode/vscode-4.8-python/resources/settings.json b/technologies/app/vscode/vscode-4.8-python/resources/settings.json new file mode 100644 index 0000000..c9e2a36 --- /dev/null +++ b/technologies/app/vscode/vscode-4.8-python/resources/settings.json @@ -0,0 +1,7 @@ +{ + "jupyter.sendSelectionToInteractiveWindow": true, + "jupyter.alwaysScrollOnNewCell": true, + "jupyter.askForKernelRestart": false, + "interactiveWindow.collapseCellInputCode": "never", + "workbench.colorTheme": "Default Dark+" +} \ No newline at end of file diff --git a/technologies/app/vscode/vscode-4.8/Dockerfile b/technologies/app/vscode/vscode-4.8/Dockerfile new file mode 100644 index 0000000..6d42f4f --- /dev/null +++ b/technologies/app/vscode/vscode-4.8/Dockerfile @@ -0,0 +1,42 @@ +FROM ghcr.io/linuxserver/code-server:4.8.3 + +USER root + +ENV PUID=1000 +ENV PGID=1000 +RUN TZ=Europe/London + +RUN apt-get update \ + && apt-get install -y nginx \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/ \ + && rm /etc/nginx/sites-enabled/default + +COPY resources/nginx.conf /etc/nginx/sites-enabled/nginx.conf +COPY resources/entrypoint.sh /entrypoint.sh + +RUN chmod +x /entrypoint.sh \ + && chmod +x /etc/nginx/sites-enabled/nginx.conf + +# Copy a script that we will use to correct permissions after running certain commands +COPY resources/fix-permissions /usr/local/bin/fix-permissions +RUN chmod a+rx /usr/local/bin/fix-permissions + +RUN mkdir -p /tmp/settings +COPY resources/settings.json /tmp/settings/ + +RUN sed -i 's/SUDO_PASSWORD/VSCODE_SUDO_PASSWORD/g' /etc/s6-overlay/s6-rc.d/init-code-server/run \ + && sed -i '2s|^|\ + export PASSWORD=$VSCODE_PASSWORD \n \ + export HASHED_PASSWORD=$VSCODE_HASHED_PASSWORD \n \ + mkdir -p /config/data/User/ \n \ + cp -u /tmp/settings/settings.json /config/data/User/ \n \ + fix-permissions /config/ \n \ + |' /etc/s6-overlay/s6-rc.d/svc-code-server/run + +COPY resources/nginx-run /etc/services.d/nginx/run + +EXPOSE 8443 + +# Use s6-overlay as entrypoint to run multiple processes +ENTRYPOINT ["/init"] \ No newline at end of file diff --git a/technologies/app/vscode/vscode-4.8/resources/entrypoint.sh b/technologies/app/vscode/vscode-4.8/resources/entrypoint.sh new file mode 100644 index 0000000..7b5d8cd --- /dev/null +++ b/technologies/app/vscode/vscode-4.8/resources/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/bash +echo "Set Proxy" +export PROXY_DOMAIN=$SAAGIE_BASE_PATH + +echo "SAAGIE_BASE_PATH" +echo $SAAGIE_BASE_PATH +echo "PROXY_DOMAIN" +echo $PROXY_DOMAIN + +# /init + +sed -i 's:SAAGIE_BASE_PATH:'"$SAAGIE_BASE_PATH"':g' /etc/nginx/sites-enabled/nginx.conf + +/init \ No newline at end of file diff --git a/technologies/app/vscode/vscode-4.8/resources/fix-permissions b/technologies/app/vscode/vscode-4.8/resources/fix-permissions new file mode 100644 index 0000000..0969275 --- /dev/null +++ b/technologies/app/vscode/vscode-4.8/resources/fix-permissions @@ -0,0 +1,35 @@ +#!/bin/bash +# set permissions on a directory +# after any installation, if a directory needs to be (human) user-writable, +# run this script on it. +# It will make everything in the directory owned by the group ${NB_GID} +# and writable by that group. +# Deployments that want to set a specific user id can preserve permissions +# by adding the `--group-add users` line to `docker run`. + +# uses find to avoid touching files that already have the right permissions, +# which would cause massive image explosion + +# right permissions are: +# group=${NB_GID} +# AND permissions include group rwX (directory-execute) +# AND directories have setuid,setgid bits set + +set -e + +for d in "$@"; do + find "${d}" \ + ! \( \ + -group "${NB_GID}" \ + -a -perm -g+rwX \ + \) \ + -exec chgrp "${NB_GID}" {} \; \ + -exec chmod g+rwX {} \; + # setuid, setgid *on directories only* + find "${d}" \ + \( \ + -type d \ + -a ! -perm -6000 \ + \) \ + -exec chmod +6000 {} \; +done \ No newline at end of file diff --git a/technologies/app/vscode/vscode-4.8/resources/nginx-run b/technologies/app/vscode/vscode-4.8/resources/nginx-run new file mode 100644 index 0000000..729e176 --- /dev/null +++ b/technologies/app/vscode/vscode-4.8/resources/nginx-run @@ -0,0 +1,13 @@ +#!/usr/bin/with-contenv bash + +echo "Set Proxy" +export PROXY_DOMAIN=$SAAGIE_BASE_PATH + +echo "SAAGIE_BASE_PATH" +echo $SAAGIE_BASE_PATH +echo "PROXY_DOMAIN" +echo $PROXY_DOMAIN + +sed -i 's:SAAGIE_BASE_PATH:'"$SAAGIE_BASE_PATH"':g' /etc/nginx/sites-enabled/nginx.conf + +nginx -g "daemon off;" diff --git a/technologies/app/vscode/vscode-4.8/resources/nginx.conf b/technologies/app/vscode/vscode-4.8/resources/nginx.conf new file mode 100644 index 0000000..6474232 --- /dev/null +++ b/technologies/app/vscode/vscode-4.8/resources/nginx.conf @@ -0,0 +1,26 @@ +map $http_connection $upgrade_requested { + default upgrade; + '' close; +} +server { + listen 80 default_server; + root /usr/share/nginx/html; + index index.html index.htm; + + location SAAGIE_BASE_PATH { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $upgrade_requested; + # proxy_set_header Accept-Encoding "" + proxy_read_timeout 20d; + + rewrite ^SAAGIE_BASE_PATH/(.*)$ /$1 break; + rewrite ^SAAGIE_BASE_PATH$ / break; + + proxy_pass http://localhost:8443; + + proxy_redirect http://localhost:8443/ $scheme://$hostSAAGIE_BASE_PATH/; + proxy_redirect https://localhost:8443/ $scheme://$hostSAAGIE_BASE_PATH/; + + } +} \ No newline at end of file diff --git a/technologies/app/vscode/vscode-4.8/resources/settings.json b/technologies/app/vscode/vscode-4.8/resources/settings.json new file mode 100644 index 0000000..b09db5c --- /dev/null +++ b/technologies/app/vscode/vscode-4.8/resources/settings.json @@ -0,0 +1,3 @@ +{ + "workbench.colorTheme": "Default Dark+" +} \ No newline at end of file diff --git a/version.properties b/version.properties index 4fdcc49..a54c00c 100644 --- a/version.properties +++ b/version.properties @@ -1,6 +1,6 @@ -version.buildmeta= +version.buildmeta=feature/vscode-4.8 version.major=0 version.minor=73 version.patch=0 -version.prerelease= -version.semver=0.73.0 +version.prerelease=BETA +version.semver=0.73.0-BETA+feature/vscode-4.8