From 8dd6e5e0d86c3097b1dc4eb5c68ed4fd09ef1261 Mon Sep 17 00:00:00 2001
From: Reiner Jung <reiner.jung@email.uni-kiel.de>
Date: Mon, 29 Mar 2021 19:29:23 +0200
Subject: [PATCH] Updated language setup.

---
 Dockerfile                 | 44 +++++++++++++++++++
 README.md                  | 90 ++++++++++++++++++++++++++++++++++++++
 docker-compose.yml         | 11 +++++
 jupyter_notebook_config.py | 52 ++++++++++++++++++++++
 kernel.json                |  5 +++
 logback.xml                | 18 ++++++++
 run.sh                     |  7 +++
 7 files changed, 227 insertions(+)
 create mode 100644 Dockerfile
 create mode 100644 README.md
 create mode 100644 docker-compose.yml
 create mode 100644 jupyter_notebook_config.py
 create mode 100644 kernel.json
 create mode 100644 logback.xml
 create mode 100755 run.sh

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..be46671
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,44 @@
+#Base image
+FROM jupyter/datascience-notebook@sha256:73a577b006b496e1a1c02f5be432f4aab969c456881c4789e0df77c89a0a60c2
+
+USER root
+#RUN conda install -n root conda=4.6
+#RUN conda update jupyterlab
+
+# Install OpenJDK-8
+RUN apt-get update && \
+    apt-get install -y openjdk-11-jdk && \
+    apt-get install -y ant && \
+    apt-get clean;
+
+# Fix certificate issues
+RUN apt-get update && \
+    apt-get install ca-certificates-java && \
+    apt-get clean && \
+    update-ca-certificates -f;
+
+RUN conda install --quiet --yes --freeze-installed \
+    'python-language-server' \
+    'r-languageserver' \
+  && python3 -m pip install --no-cache-dir --no-deps \
+    'jupyter_lsp==0.7' \
+  && jupyter labextension install --no-build \
+    '@krassowski/jupyterlab-lsp@0.7.1' \
+  && jupyter lab build --dev-build=False --minimize=True \
+  && conda clean --all -f -y \
+  && rm -rf \
+    $CONDA_DIR/share/jupyter/lab/staging \
+    /home/$NB_USER/.cache/yarn \
+  && fix-permissions $CONDA_DIR \
+  && fix-permissions /home/$NB_USER
+
+
+# Add Language server File
+ADD org.oceandsl.configuration.ide-1.0.0-SNAPSHOT-ls.jar /etc/
+ADD jupyter_notebook_config.py /etc/jupyter
+
+# Add kernel
+ADD cp-dsl-jupyter-kernel /cp-dsl-jupyter-kernel/
+COPY kernel.json /opt/conda/share/jupyter/kernels/xtext/kernel.json
+COPY logback.xml /opt/conda/share/jupyter/kernels/xtext/logback.xml
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..65473f3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,90 @@
+# CP-DSL Jupyter Setup
+
+The CP-DSL Jupyter setup allows to run Jupyter with an LSP extension for the
+Configuration and Parameterization DSL (CP-DSL) with its associated kernel
+for code generation.
+
+In the following, we explain how to setup the docker image and then run the
+whole kaboodle.
+
+## Setup
+
+This git repository does not come with the necessary binary artifacts for
+the CP-DSL LSP component and the kernel. They must be obtained from cp-dsl and
+jupyter-base-kernel repository.
+
+### Download and compile the CP-DSL
+
+The following instructions reflect actions on a command line interface.
+Leave the `cp-dsl-jupyter-setup` directory and clone the CP-DSL repository
+alongside it.
+
+`git clone https://git.se.informatik.uni-kiel.de/oceandsl/cp-dsl.git`
+
+Switch into the `cp-dsl` directory
+
+`cd cp-dsl`
+
+and build the DSL with
+
+`mvn -P build -Dinstallation=false compile`
+`mvn -P build -Dinstallation=false package`
+
+This produces various jar files. Copy `org.oceandsl.configuration.ide-1.0.0-SNAPSHOT-ls.jar`
+to the `cp-dsl-juypter-setup directory`
+
+`cp bundles/org.oceandsl.configuration.ide/target/org.oceandsl.configuration.ide-1.0.0-SNAPSHOT-ls.jar ../cp-dsl-jupyter-setup`
+
+### Download and compile the CP-DSL Kernel
+
+The following instructions reflect actions on a command line interface.
+Leave the `cp-dsl` directory and clone the CP-DSL Jupyter kernel repository
+alongside the `cp-dsl-jupyter-setup`.
+
+`git clone https://git.se.informatik.uni-kiel.de/oceandsl/cp-dsl-jupyter-kernel.git`
+
+Switch to the `cp-dsl-jupyter-kernel` directory.
+
+`cd cp-dsl-jupyter-kernel` 
+
+and copy the necessary files from `cp-dsl` to the `libs` directory
+
+`cp ../cp-dsl/bundles/org.oceandsl.configuration.model.support.uvic/target/org.oceandsl.configuration.model.support.uvic-1.0.0-SNAPSHOT.jar libs`
+`cp ../cp-dsl/bundles/org.oceandsl.configuration.model.support.mitgcm/target/org.oceandsl.configuration.model.support.mitgcm-1.0.0-SNAPSHOT.jar libs`
+`cp ../cp-dsl/bundles/org.oceandsl.configuration/target/org.oceandsl.configuration-1.0.0-SNAPSHOT.jar libs`
+
+Now build the kernel with
+
+`./gradlew build`
+
+After the build is complete, switch back to `cp-dsl-jupyter-setup` with
+
+`cd ../cp-dsl-jupyter-setup`
+
+and unpack the build distribution package of the kernel inside the `cp-dsl-jupyter-setup` 
+
+`unzip ../cp-dsl-jupyter-kernel/build/distributions/cp-dsl-jupyter-kernel.zip`
+
+### Check setup script
+
+Check `kernel.json`, `jupyter_notebook_config.py` and `Dockerfile` that the appropriate
+files have been named there.
+
+The `kernel.json` file
+```
+{"argv":["/cp-dsl-jupyter-kernel/bin/cp-dsl-juypter-kernel","{connection_file}"],
+  "display_name":"oconf",
+  "language": "oconf"
+}
+```
+
+The `jupyter_notebook_config.py` must contain `org.oceandsl.configuration.ide-1.0.0-SNAPSHOT-ls.jar`
+as file under `c.LanguageServerManager.language_servers`.
+
+## How to run 
+
+Start ```run.sh``` This works on Linux, but not on windows.
+On Windows simply run *docker build -t lsp* and *docker-compose up* after that.
+Jupyter lab can be reached on localhost:18888/lab using a token provided in windows shell. 
+
+
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..71932df
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,11 @@
+version: '2'
+
+services:
+  lsp-lab:
+    build: .
+    ports:
+      - '18888:8888'
+        - '18888:8888'
+    environment:
+      - GRANT_SUDO:"yes"
+    user: jovyan
diff --git a/jupyter_notebook_config.py b/jupyter_notebook_config.py
new file mode 100644
index 0000000..97596dc
--- /dev/null
+++ b/jupyter_notebook_config.py
@@ -0,0 +1,52 @@
+# Copyright (c) Jupyter Development Team.
+# Distributed under the terms of the Modified BSD License.
+
+from jupyter_core.paths import jupyter_data_dir
+import subprocess
+import os
+import errno
+import stat
+# jupyter_notebook_config.py
+import shutil
+
+
+c = get_config()
+c.NotebookApp.ip = '*'
+c.NotebookApp.port = 8888
+c.NotebookApp.open_browser = False
+
+# https://github.com/jupyter/notebook/issues/3130
+c.FileContentsManager.delete_to_trash = False
+
+# Generate a self-signed certificate
+if 'GEN_CERT' in os.environ:
+    dir_name = jupyter_data_dir()
+    pem_file = os.path.join(dir_name, 'notebook.pem')
+    try:
+        os.makedirs(dir_name)
+    except OSError as exc:  # Python >2.5
+        if exc.errno == errno.EEXIST and os.path.isdir(dir_name):
+            pass
+        else:
+            raise
+    # Generate a certificate if one doesn't exist on disk
+    subprocess.check_call(['openssl', 'req', '-new',
+                           '-newkey', 'rsa:2048',
+                           '-days', '365',
+                           '-nodes', '-x509',
+                           '-subj', '/C=XX/ST=XX/L=XX/O=generated/CN=generated',
+                           '-keyout', pem_file,
+                           '-out', pem_file])
+    # Restrict access to the file
+    os.chmod(pem_file, stat.S_IRUSR | stat.S_IWUSR)
+    c.NotebookApp.certfile = pem_file
+
+# c is a magic, lazy variable
+c.LanguageServerManager.language_servers = {
+    "a-language-server-implementation": {
+        # if installed as a binary
+	"version": 1,
+        "argv": ["java","-jar", "/etc/org.oceandsl.configuration.ide-1.0.0-SNAPSHOT-ls.jar"],
+        "languages": ["oconf"]
+	   }
+}
diff --git a/kernel.json b/kernel.json
new file mode 100644
index 0000000..4afdc0b
--- /dev/null
+++ b/kernel.json
@@ -0,0 +1,5 @@
+ {"argv":["/cp-dsl-jupyter-kernel/bin/cp-dsl-jupyter-kernel","{connection_file}"],
+ "display_name":"oconf",
+  "language": "oconf"
+}
+
diff --git a/logback.xml b/logback.xml
new file mode 100644
index 0000000..d920ca8
--- /dev/null
+++ b/logback.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+    <property name="HOME_LOG" value="/home/jovyan/work/xtext.log"/>
+
+    <appender name="FILE-ROLLING" class="ch.qos.logback.core.FileAppender">
+        <file>${HOME_LOG}</file>
+
+        <encoder>
+           <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <root level="debug">
+        <appender-ref ref="FILE-ROLLING"/>
+    </root>
+
+</configuration>
diff --git a/run.sh b/run.sh
new file mode 100755
index 0000000..c09d91d
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+docker build -t lsp .
+docker run -v $PWD/work:/home/jovyan/work lsp
+
+# end
+
-- 
GitLab