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.
- First head over to github and fork the addons-repo
- Now we need to create two files in the root of the repository which tell gitpod how yout workspace should look like
- 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:
- 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
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
- 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
- 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.
- 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
- 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.
- 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 - Blog)
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
Greetings