IOTstack icon indicating copy to clipboard operation
IOTstack copied to clipboard

Feature request regarding .templates (overridden)?

Open simonlock opened this issue 5 years ago • 4 comments

Hi Graham

Would it be feasible to introduce something like an "override" folder within .templates folder which would be used at a higher priority than the default templates found within the .templates folder when creating docker containers? And to include this folder of overridden templates in the automated backups?

I've made several changes to the defaults found in .templates that you provide i.e. different images, networking and ports and I find myself having to redo my configuration when IoTstack is updated. I think this would be a very useful enhancement and should cause no issues for the current users of IOTstack. Just an idea.

Best regards

Simon

simonlock avatar Jan 12 '20 16:01 simonlock

I think maybe a yaml merging type code would be better suited for this type of thing? That way it can inject properties under specific objects, while still providing updates where necessary.

I could probably code something like this, could use Python or NodeJS for it. Python is probably better as it comes installed already in most systems (especially Raspberry Pis).

Slyke avatar Jan 13 '20 23:01 Slyke

I agree. The merging sound like an excellent idea. That would allow for the overriding of components of each template file, therefore allowing customisation, whilst not having to replace the template files completely.

simonlock avatar Jan 14 '20 16:01 simonlock

Found some example code that will achieve this: https://stackoverflow.com/questions/47424865/merge-two-yaml-files-in-python

my-custom.yml example:

services:
  pihole:
    restart: always
    extra_hosts:
      - router: 192.168.1.1
      - iotstack 192.168.1.5

The current service.yml for pihole:

pihole:
    container_name: pihole
    image: pihole/pihole:latest
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "8089:80/tcp"
      #- "443:443/tcp"
    env_file:
      - ./services/pihole/pihole.env
    volumes:
       - ./volumes/pihole/etc-pihole/:/etc/pihole/
       - ./volumes/pihole/etc-dnsmasq.d/:/etc/dnsmasq.d/
    dns:
      - 127.0.0.1
      - 1.1.1.1
    # Recommended but not required (DHCP needs NET_ADMIN)
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    cap_add:
      - NET_ADMIN
    restart: unless-stopped

The output to docker-compose.yml:

  pihole:
    extra_hosts:
      - router: 192.168.1.1
      - iotstack 192.168.1.5
    container_name: pihole
    image: pihole/pihole:latest
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "8089:80/tcp"
      #- "443:443/tcp"
    env_file:
      - ./services/pihole/pihole.env
    volumes:
       - ./volumes/pihole/etc-pihole/:/etc/pihole/
       - ./volumes/pihole/etc-dnsmasq.d/:/etc/dnsmasq.d/
    dns:
      - 127.0.0.1
      - 1.1.1.1
    # Recommended but not required (DHCP needs NET_ADMIN)
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    cap_add:
      - NET_ADMIN
    restart: always

You can see that restart is overridden by the value in my-custom.yml and that extra_hosts with it's properties is added in.

Slyke avatar Jan 26 '20 07:01 Slyke

Excellent. This sounds like the perfect solution.

simonlock avatar Jan 26 '20 11:01 simonlock