dockerdockerfilebinaryfilesxtextlanguageservice

Running a language server in a Dockerfile: Binary file of the Language Server


I built a simple language server following this tutorial:

http://www.eclipse.org/Xtext/documentation/102_domainmodelwalkthrough.html

In this server, I have 5 folders,

org.example.domainmodel
org.example.domainmodel.ide
org.example.domainmodel.tests
org.example.domainmodel.ui
org.example.domainmodel.ui.tests

Now I need to run this language server inside a Docker image, and need the binary directory for it. Which binary directory out of the above 5 folders should I use? The actual language servers I've explored so far are quite different from what I've created.


Solution

  • The above project that I had created is used to develop Eclipse plugins. To create a LS to run in a Dockerfile, it is required to create a binary file (I used fatJar) from the Eclipse Xtext project that should be created as explained in this tutorial (Should only complete up to 'Packaging the LS', inclusive). Note that when packaging the LS, it is enough to add the following code snippet in the *.ide project's build.gradle file : -

    shadowJar {
        baseName = 'dsl-language-server'
        classifier = null
        version = null
    }
    

    Afterwards, the parent project should be built by gradle shadowJar command in the command prompt. Once it is done, a .jar file will be created in the following path: *.ide/build/libs

    Then you'll need to create a separate directory and copy and paste the build folder into it, and create a file named dockerfile (no file extension) and include the following code in it: -

    FROM barais/eclipse-xtend
    ADD build/libs/dsl-language-server-ls.jar dsl-language-server-ls.jar
    RUN sudo apt-get install socat
    RUN apt-get update && \
        apt-get upgrade -y && \
        apt-get install -y  software-properties-common && \
        add-apt-repository ppa:webupd8team/java -y && \
        apt-get update && \
        echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
        apt-get install -y oracle-java8-installer && \
        apt-get clean
    CMD socat TCP4-LISTEN:4417,reuseaddr,fork EXEC:"java -jar dsl-language-server-ls.jar"
    

    Then build this file using Docker, and push it to your Docker Hub account as a repo. Use the following recipe to create a new stack in Eclipse Che to use the pushed repo from Docker Hub as a language server: -

    services:
     dsl-language-server-ls:
      image : <youraccountname>/mydsl
      mem_limit : 1073741824
     dev-machine:
      image : eclipse/ubuntu_jdk8
      mem_limit : 2147483648
      depends_on:
       - dsl-language-server-ls
    

    Edit the raw config and update it with the following code at the respective location in the config (Read the che doc for more information: -

    "id": "mydsl-ls",
          "internal": "true",
          "type": "ls",
          "languageRegexes": "[ {\"languageId\":\"mydsllang\", \"regex\":\".*\\\\.mydsl$\"}]"
    

    Create a file in a new project in Eclipse Che with the file extension you added (.mydsl) and the LS will start to run, allowing you to write code in your DSL.

    Yay!