Best approach for git and openhab config

The same as for conf. I initially did a git init, copied over the conf and userdata folders to get started (also ~openhab/.java as that is where the oauth token stuff is stored for Nest connections). So I really just have the one repo which contains both my conf and userdata. I don’t do anything different for the two.

About the only complaint that I have with this setup is my cloned repo OH runs on is almost always “dirty” because I have code that copies around icons for weather and the jsondb is constantly being backed up so at any given time I almost always have something to check in. Therefore I can’t quickly tell whether I have changes I’ve made that need to be checked in. This has forced me to be a lot more diligent about making small concise changes and checking them in frequently.

So if you look at my repo you would see:

As you can see, I have .java, conf, and userdata just as folders in the repo. Then, because I’m using Docker I map those folders into the container to the appropriate locations. Before I started using Docker, I would use symbolic links to so map from where ever I cloned the repo to to /etc/openhab2 and /var/lib/openhab2.

Does that anwer your question?

I host my own git server (Gogs). Though there are other approaches like git-crypt which lets you encrypt sensitive files so only those with a password can read those with sensitive info in it.

It is sensitive info only in that it reveals quite a bit about your internal network topology, though the impact of that information being released is relatively low. But it does make someone who is specifically targeting you’s job easier. And it becomes much more sensitive when combined with information like lat/long and usernames, both of which would be in a typical OH config. Whether the aggregate of information in your repo makes internal ip addresses a risk for you is something you have to decide.

That is why I chose Gogs, it is super light weight and has pretty much all of the features of Gitlab that I care about. It is also really easy to set up. Here is my ansible role I use to deploy it:

---

- name: Create a git user
  user:
    comment: 'Gogs'
    createhome: no
    name: git
    shell: /bin/bash
    state: present
    system: yes
  become: yes

- name: Mount gogs working folder
  include_role:
    name: mount-cifs
  vars:
    mount_mode: '0660'
    cifs_user: "{{ share_user }}"
    cifs_pass: "{{ share_pass }}"
    cifs_domain: "{{ workgroup }}"
    mount_user: git
    mount_path: "{{ gogs_data }}"
    mount_src: "{{ gogs_mount }}"

- name: Start gogs
  docker_container:
    detach: True
    exposed_ports:
      - 22
      - 3000
    hostname: chimera.koshak.net
    image: gogs/gogs
    log_driver: syslog
    name: gogs
    published_ports:
      - "10022:22"
      - "3000:3000"
    pull: True
    recreate: True
    restart: True
    restart_policy: always
    volumes:
      - "{{ gogs_data }}:/data"
      - /etc/passwd:/etc/passwd:ro
      - /usr/share/zoneinfo:/usr/share/zoneinfo:ro

Note, it has bee a very long time since I’ve had to run this. It depends on there being a preconfigured app.ini file and variables defined. The data folders used by Gogs is servered by my NAS so I have a task to mount them. I no longer need to get to these folders from Windows but I’ve not converted them to NFS from CIFS yet.

For me it is incredibly useful to be able to go back and see the tiny little differences in Rules between versions as I help people on the forum. If I were smart, I would have cut a tag each time I moved to a new version. Gonna have to start doing that going forward.

Yes. You would work with it the same as you would with Github or Bitbucket or any other Git server. From your client’s perspective it is just like any other git server. And it has a nice web UI akin to what you are used to with services like Github as well.

It’s a little awkward but certainly. Browse to the file, click the pencil icon in the upper right, and you can edit away.

Yes. From the command line the workflow would look something like

// from your editing machine
vim myitems.item
/// and save make edits
 git add myitems.item
git commit -M "Added a new super cool Item"
git push

// from the OH server
git pull

Of course, you can edit the file through the browser or from the same OH machine.

I never looked that deeply into that option. I need to give it a second look. That is pretty cool.

I think he is asking if one can edit files from the Gogs web app directly or if you need to clone the repo and edit the file locally and push the changes.

3 Likes