Addon development using gitpod

Hi everyone,

I recently stumbled upon gitpod.io.
For whose who are unware what it is, it’s bascily a git repository you specified cloned into this instance. After your workspace is ready, you can access it in your browser and get a VSCode UI to develop. In the background your workspace is a container run in kubernetes.
Gitpod self says:

Spin up fresh, automated dev environments
for each task, in the cloud, in seconds.

The interessting stuff begins when you find out, that you can write your own dockerfile to install other software and tools, not provided initially by gitpod or which you don’t want to install everytime manually.

Disclaimer:
I am not affiliated with gitpod.
This is no complete gitpod tutorial. If you want to know more, please head over to their documentation.

And so I thought, would it be possible to install OH and develop/debug addons in there?
The short answer is yes, but there are a few things to consider if you follow gitpods initial thoughts.

But why would I want running OH in gitpod?

  • I don’t want to use my productive OH instance for developing
  • I don’t want to install OH on my development machine
  • In case of bugs, I can exclude configuration errors or sideeffects from other addons or software
  • new addons don’t “destroy” your isntallation while you develop them
  • you can develop from everywhere without the need to have your local installation available

So let’s start with how to start OH in gitpod.

  1. First head over to github and fork the addons-repo
  2. Now we need to create two files in the root of the repository which tell gitpod how yout workspace should look like
    1. The first one is .gitpod.yaml in which you specify the path to the custom dockerfile, what tasks should be run and how gitpod should act on opening ports. Note the tasks section. If you want OH to start with your workspace uncomment those lines and OH will start in debug mode
      It should look like this:
image:
  file: .gitpod.Dockerfile

# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/
# tasks:
# - command: sudo /bin/bash -c '/opt/openhab/start.sh debug' # uncomment if openhab should be started in debug mode at launch

# List the ports to expose. Learn more https://www.gitpod.io/docs/config-ports/
ports:
  - port: 8080
    onOpen: open-preview
  - port: 8081-50000
    onOpen: ignore
  - port: 5007
    onOpen: ignore
  - port: 5005
    onOpen: ignore
  1. The second file is the dockerfile. We use the full workspace image, install java and install OH manually (I tried it also with the package manager one but failed)
    The file should be called .gitpod.Dockerfile like above.
    Note that we set the gitpod user as owner of /opt/openhab so that we can put our addons in OH during build
FROM gitpod/workspace-full

USER root

RUN wget -qO - 'https://openhab.jfrog.io/artifactory/api/gpg/key/public' | sudo apt-key add - && \
    echo 'deb https://openhab.jfrog.io/artifactory/openhab-linuxpkg stable main' | sudo tee /etc/apt/sources.list.d/openhab.list && \
    sudo apt-get update && \
    sudo apt-get -y install apt-transport-https openjdk-11-jdk

WORKDIR /tmp

RUN wget -O openhab-download.zip https://openhab.jfrog.io/artifactory/libs-release-local/org/openhab/distro/openhab/3.1.0/openhab-3.1.0.zip && \
    sudo unzip openhab-download.zip -d /opt/openhab && \
    rm openhab-download.zip && \
    sudo chown -hR gitpod:gitpod /opt/openhab
  1. Now we can head over to gitpod and create a workspace with our repository. We need just to paste the url and wait till the workspace is ready.
  2. Now we need just to follow the VSCode IDE setup instructions from the OH docu: Visual Studio Code | openHAB and we are ready to go
  3. If you didn’t start OH from the tasks, just type in the terminal /opt/openhab/start.sh. Port 8080 is configured to open in the preview window and you should see the familiar OH login screen.
  4. Open the astro binding (/bundles/org.openhab.binding.astro) in VSCode and you should see the “Debug (Attach) - openHAB” task in VSCodes task section. So set some breakpoints in the sourcecode an run the task.

I created a example repo yesterday with a .vscode folder to try to debug the astro binding and was successful. There are also the above mentionend gitpod files for reference. You can also use this as example and try OH in gitpod: https://github.com/FloSchl8/openhab-addons

Now some minor drawbacks:

  • You get a fresh OH installation with no data, meaning you must setup some basics. This can be good or bad, depending on your usecase. But I suppose you can make some basic setup, back it up and restore it in the dockerfile.
  • .gitpod.yaml and .gitpod.Dockerfile need to be in the repository. I think they shouln’t be in the offical repo unless it should be official supported, so you need to create them everytime you fork the offical repo. This should be the case everytime you start e.g. a new addon, a new feature or start working on a bug.
  • You need to maintain the OH version to download in the dockerfile

Another option gitpod mentions is inlets to connect servies in gitpod to your local machine (they even mention OH in their blogpost about using inlets: Using local services in Gitpod)

But nethertheless I think it’s a great piece of software for developers and I’m looking forward what the OH community thinks about it. So share your thoughts :wink:

Greetings

These cloud based IDEs are certainly an interesting development.

Though I think it is very personal what kind of trade-offs you are willing to make with this because it also introduces extra complexity and incompatibilities you have to deal with.

I wonder how it compares to the similar GitHub Codespaces which is also using VS Code?

Also worth mentioning is the pricing model. Usually these services start off cheap and then start increasing their prices or go out of business. :wink:

If you want to use this solution full time instead of an IDE running on your own desktop, you probably already need at least the “Professional” plan €23/month = €1380/5years at the current price. That is serious money, which you cannot spend on the computer you still need (and which needs to be replaced).

:wave: Geoff here from Gitpod. Both are essentially the same type of products with some minor (yet major) differences.

  1. Gitpod is open-source and can be self-hosted on your own infrastructure.
  2. Gitpod prebuilds your development environment (think CI/CD) so everything opens in a snap (ie. no more waiting for npm install or that initial compilation)

Last week I put together a template which demonstrates the similarity and how to share a development environment between both platforms over at https://github.com/gitpod-io/template-gitpod-sxs-codespaces

GitHub Codespaces is $$$ immediately whilst Gitpod provides everyone with 50 hours a month for free and for open-source maintainers is free for life.

See GitHub Codespaces, Welcome to the Party!

If you got any questions come drop by the Gitpod discord community. :wave: