gcgarner / IOTstack

docker stack for getting started on IOT on the Raspberry PI
GNU General Public License v3.0
1.51k stars 584 forks source link

Feature request regarding .templates (overridden)? #128

Open simonlock opened 4 years ago

simonlock commented 4 years ago

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

Slyke commented 4 years ago

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).

simonlock commented 4 years ago

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.

Slyke commented 4 years ago

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.

simonlock commented 4 years ago

Excellent. This sounds like the perfect solution.