theia-ide / theia-apps

Theia applications examples - docker images, desktop apps, packagings
Apache License 2.0
1.04k stars 344 forks source link

question: help understanding docker setup #490

Closed psociety closed 2 years ago

psociety commented 2 years ago

Hi Theia guide seems to be made for people that already knows how to set it up :( I wanted to do something that i consider very basic: Install Theia with support for php+js/html/css and authentication.

It seemed that the way to go was to install docker theiaide/theia-full:latest like this:

docker run -it -p 10443:10443 -v "/var/www/:/home/project:cached" -e token=testtoken --name theia theiaide/theia-full:latest But it doesn't work.

Name says "full" but it doesn't seem to contain https module described here. Only god knows what does actually contain, as there is no documentation : s

I thought "okay, maybe i have to build a docker-compose specifying the modules" but i checked the "How to use theiaide/theia image?" but it explains nothing about combining modules :(

How could i easily setup Theia with support for php+js/html/css and authentication using docker?

vince-fugnitto commented 2 years ago

@psociety thank you for the discussion.

The theia-apps repository contains application examples using the eclipse-theia framework, if you want additional information regarding the framework itself you can take a look at the repo for documentation, and also the website. You can use the examples provided in this repository as a an example to build your own docker image.

I wanted to do something that i consider very basic: Install Theia with support for php+js/html/css and authentication.

In a theia application, language support is contributed by vscode extensions since the framework supports the vscode API. For example, the theia-php docker image contains the necessary extensions and environment for php support and you can use it as an example for your own application:

https://github.com/theia-ide/theia-apps/blob/e588b91f02615c1ff796e2681eaadc0cc726ccbc/theia-php-docker/latest.package.json#L60

https://github.com/theia-ide/theia-apps/blob/e588b91f02615c1ff796e2681eaadc0cc726ccbc/theia-php-docker/latest.package.json#L70

https://github.com/theia-ide/theia-apps/blob/e588b91f02615c1ff796e2681eaadc0cc726ccbc/theia-php-docker/latest.package.json#L89-L90

As for theia-https-docker it is a special case and you can follow its documentation here.

psociety commented 2 years ago

ty for replying that fast @vince-fugnitto! So rather than theia-full i can switch to theia-php because it already includes web languages. And if i want php + security i then should grab https://github.com/theia-ide/theia-apps/blob/master/theia-https-docker/Dockerfile and rename APP to make it theia-php and build that docker image, as there is no official image being built automatically like that. Right?

vince-fugnitto commented 2 years ago

@psociety the idea would be to use theia-php or theia-full (if you're thinking of additional support) as a reference to create your own image yes. The only thing that really changes between images is the list of bundled extensions (extensions included by default in the application which are referenced in an application's package.json), and the environment setup or tools in the dockerfile itself.

As for theia-https, I believe you can do like you've suggested or even pass app through a command line argument like so:

app=theia-php

there is no official image being built automatically like that

The images are published to dockerhub automatically for latest and next versions of the framework, but you are correct that they are not official, they are used as example purposes or for CI purposes for the framework as highlighted in the readme:

psociety commented 2 years ago

@vince-fugnitto okey, so after building everything i encountered 2 problems:

  1. theia-https is not really meant for security because the token is on the url, so anyone sniffing your navigation will gain full acces.
  2. docker container uses theia user that doesn't match with host machine, which provokes a permission denied when trying to save/create files.

To fix the first problem, i just used the nginx that i have at my host machine by setting:

server {
    listen 10443;
    server_name mydomain.com;
    server_name www.mydomain.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        auth_basic           "Honeypot Realm";
        auth_basic_user_file /var/www/.htpasswd;
    }
}

It worked flawlessly. Then to fix problem 2 i:

  1. moved onto a docker-compose.yml
    services:
    theia:
    container_name: theia
    image: theia-custom
    restart: unless-stopped
    ports:
     - "127.0.0.1:3000:3000"
    volumes:
     - /var/www/:/home/project:cached
  2. Downloaded https://github.com/theia-ide/theia-apps/tree/master/theia-php-docker folder
  3. Added a new user to match my host one and change all chown lines to mine
  4. Executed docker build . -t theia-custom aaaand BOOOM. That Dockerfile doesn't seem able to build an image:
    
    Package libsecret-1 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libsecret-1.pc'
    to the PKG_CONFIG_PATH environment variable
    Package 'libsecret-1', required by 'virtual:world', not found
    gyp: Call to 'pkg-config --libs-only-l libsecret-1' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
    gyp ERR! configure error
I've tried adding that dependency in the Dockerfile like
`RUN apk add --no-cache make pkgconfig gcc g++ python libx11-dev libxkbfile-dev  libsecret-1-dev`
But i just get a 

ERROR: unsatisfiable constraints: libsecret-1-dev (missing): required by: world[libsecret-1-dev]



I'm really confused. Theia blog says it's the "modern" cloud IDE that overpasses v1 cloud IDEs like cloud9, but... it took me less than an hour to setup cloud9, while i haven't been able to properly make theia work in more than 4.
marcdumais-work commented 2 years ago

Package libsecret-1 was not found in the pkg-config search path.

We just merged a related fix (*), that should help with libsecret issues. You might have better luck if you rebase the image you're using, to the latest master.

(*): https://github.com/theia-ide/theia-apps/pull/489

psociety commented 2 years ago

@marcdumais-work cool! compilation has advanced a bit, now it gets stuck on:

$ /home/theia/node_modules/.bin/theia build
Failed to resolve module: filenamify
marcdumais-work commented 2 years ago

Failed to resolve module: filenamify

That's a usual warning that should not affect the build. Is there any error after that?

psociety commented 2 years ago

@marcdumais-work it seemed frozen but nope it kept going on :)

Done in 402.16s.
yarn run v1.22.4
$ /home/theia/node_modules/.bin/theia build
Failed to resolve module: filenamify

(node:1684) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
        Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
        Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.

Done in 225.40s.
yarn autoclean v1.22.4
[1/1] Creating ".yarnclean"...
info Created ".yarnclean". Please review the contents of this file then run "yarn autoclean --force" to perform a clean.
Done in 0.15s.
yarn autoclean v1.22.4
[1/1] Cleaning modules...
info Removed 8061 files
info Saved 30.36 MB.
Done in 18.42s.
yarn cache v1.22.4
success Cleared cache.
Done in 18.60s.
psociety commented 2 years ago

@marcdumais-work looks like i'm about to have it fully working :p I've tried opening a simple model and theia seems to use/expect old php syntax, like from php 5: image

I've checked the Preferences but i can't find anything related to syntax highlighting (only the ability to enable/disable it, but not to set the "project/php version". Disabling it doesn't seem to actually disable it. I've also checked https://github.com/theia-ide/theia-apps/blob/master/theia-php-docker/Dockerfile and seems to at least be installing some php7 packages :s What i'm missing now?

Edit: seems that container's php version is 7.3, that's why it doesn't have typed properties. Edit2: 7,4 or greater are only availale on alpine edge jurllllllllllllll Edit3: Got php 7.4 by editing Dockerfile with: RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community php php-cli php-mbstring php-openssl php-phar php-json php-tokenizer php-ctype php7-pecl-yaml php7-pecl-xdebug

As i can see:

# docker exec -it theia bash
bash-5.0$ php -v
PHP 7.4.22 (cli) (built: Jul 29 2021 18:28:34) ( NTS )

Yet syntax highlighting is still wrong huh.

Edit4: I've noticed it also doesn't have support for twig syntax by default. I think i fixed it by using https://open-vsx.org/extension/mblode/twig-language-2:

  1. Opening a terminal in theia -> cd /home/theia/plugins/
  2. wget https://open-vsx.org/api/mblode/twig-language-2/0.9.1/file/mblode.twig-language-2-0.9.1.vsix
  3. Preferences -> Search for asso -> Files: Association -> Edit in settings.json
  4. On settings file add:
    "files.associations": {
    "*.html": "twig"
    },
    "emmet.includeLanguages": {
    "twig": "html"
    },
  5. docker restart theia
marcdumais-work commented 2 years ago

Hi @psociety ,

Syntax highlighting and advanced language support are provided by vscode extensions, listed in the app's package.json:

[...]
        "vscode-builtin-php": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/php-1.39.1-prel.vsix",
        "vscode-builtin-php-language-features": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/php-language-features-1.39.1-prel.vsix",
[...]

It could be you need more recent version of the php-related built-ins, to support later versions of PHP. Most of the vscode built-in extensions can now be provided by an extension pack that we produce. Until we update the example apps here, you could take inspiration from this, from a WIP PR: https://github.com/eclipse-theia/theia-blueprint/blob/566115d49ec4a9fcffcc72b695d4567e762387ef/applications/electron/package.json#L112-L127