ubopod / ubo_app

This repo contains code for Ubo system app to control Raspberry Pi utilities and Ubo based functionalities
6 stars 2 forks source link

Refactor: place docker image commands in a separate config file #49

Open mehrdadfeller opened 6 months ago

mehrdadfeller commented 6 months ago

Currently app specific docker commands are hard coded in reducer.py file. Please refactor this and allow developers to simply add docker run command in a yaml file or line commands.

For example:

docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ee:latest

Also, I can't find where in the code the published ports are being included. I was not able to access the UI for Portainer. Also since --restart=always is not provided all images stop if a reboot happens.

--restart=always

        ImageEntry(
            id='home_assistant',
            label='Home Assistant',
            icon='home',
            path='homeassistant/home-assistant:stable',
            ports={'8123/tcp': '8123'},
        ),
        ImageEntry(
            id='home_bridge',
            label='Home Bridge',
            icon='home_work',
            path='homebridge/homebridge:latest',
        ),
        ImageEntry(
            id='portainer',
            label='Portainer',
            icon='settings_applications',
            path='portainer/portainer-ce:latest',
            volumes=['/var/run/docker.sock:/var/run/docker.sock'],
        ),
        ImageEntry(
            id='pi_hole',
            label='Pi-hole',
            icon='dns',
            path='pihole/pihole:latest',
        ),
        ImageEntry(
            id='alpine',
            label='Alpine',
            icon='code',
            path='alpine:latest',
        ),
sassanh commented 6 months ago

Also, I can't find where in the code the published ports are being included.

It is happening here: https://github.com/ubopod/ubo-app/blob/main/ubo_app/services/080-docker/image.py#L135

Also since --restart=always is not provided all images stop if a reboot happens.

Since we are just building a UI for the docker service, I think we better stick with its default behavior for these reasons:

  1. If it is not restarting containers on system restart by default, they probably have some reasoning behind it.
  2. If we change the default behavior implicitly, it may become surprising for some people.

My suggestion is to add an "options" section for each image in which users can change the default behavior as needed. The first option would be "restart" with values "no", "on-failure", "always" and "unless-stopped". Over time we can add more options to this section as needed. What do you think?

mehrdadfeller commented 6 months ago

We revisit this in the future in more depth. It would be cool to be able to pass a link to a yaml file with QR code to pass a custom yaml or command. I think adding some extra controls to the GUI would allow for more control in the meantime.