Skip to content

Commit

Permalink
Vscode 4.8 (#178)
Browse files Browse the repository at this point in the history
* feat: vscode 4.8
  • Loading branch information
TFellet authored Nov 30, 2022
1 parent 8c3b352 commit c1f5cda
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 13 deletions.
25 changes: 17 additions & 8 deletions technologies/app/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://code.visualstudio.com/docs/>.
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))

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).
33 changes: 31 additions & 2 deletions technologies/app/vscode/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
112 changes: 112 additions & 0 deletions technologies/app/vscode/vscode-4.8-python/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.defaultInterpreterPath": "/opt/conda/envs/py310/bin/python"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"jupyter.sendSelectionToInteractiveWindow": true,
"jupyter.alwaysScrollOnNewCell": true,
"jupyter.askForKernelRestart": false,
"interactiveWindow.collapseCellInputCode": "never",
"workbench.colorTheme": "Default Dark+"
}
42 changes: 42 additions & 0 deletions technologies/app/vscode/vscode-4.8/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 14 additions & 0 deletions technologies/app/vscode/vscode-4.8/resources/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions technologies/app/vscode/vscode-4.8/resources/fix-permissions
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions technologies/app/vscode/vscode-4.8/resources/nginx-run
Original file line number Diff line number Diff line change
@@ -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;"
26 changes: 26 additions & 0 deletions technologies/app/vscode/vscode-4.8/resources/nginx.conf
Original file line number Diff line number Diff line change
@@ -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/;

}
}
3 changes: 3 additions & 0 deletions technologies/app/vscode/vscode-4.8/resources/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"workbench.colorTheme": "Default Dark+"
}
6 changes: 3 additions & 3 deletions version.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c1f5cda

Please sign in to comment.