technorabilia / portainer-tools

Various Portainer Tools
GNU General Public License v3.0
11 stars 3 forks source link

merge fail with uploaded template (file) #2

Closed gamegine closed 2 years ago

gamegine commented 2 years ago

hello, I came across an error concerning the merge of local templates

step to reproduce 1 start a new docker with clean configuration

# https://www.technorabilia.com/portainer-tools-merge-and-host-app-template-definitions/
version: '3.3'
services:
    portainer-tools:
        container_name: portainer-tools
        environment:
            #- PUID=<puid>
            #- PGID=<pgid>
            - SERVER_URL=localhost
            - PORTAINER_URL=localhost
            #- PORTAINER_USERNAME=<portainer username>
            #- PORTAINER_PASSWORD=<portainer password>
        ports:
            - 9999:9999
        volumes:
            - config:/config
        restart: unless-stopped
        image: technorabilia/portainer-tools
volumes:
  config:

2 Upload app template definition file (in this case a.json) 3 select 2 templates and merge error message was printed Error in templates/a.json: Invalid URL 'templates/a.json': No schema supplied. Perhaps you meant http://templates/a.json?

it will probably be necessary to add a condition to check if the template is local app/tools/apptemplates/utils.py

    for template in templates:
        template_url = template["url"]
        try:
            response = requests.get(template_url)
            template = json.loads(response.text)
technorabilia commented 2 years ago

I think you have to replace localhost with http://localhost.

Could also be because you omitted the PUID and PGID. Not sure.

gamegine commented 2 years ago

Hello, thank you for your quick response. after testing it is indeed the SERVER_URL localhost variable without the https:// which gives templates/custom.json as url instead of http://localhost:9999/templates/custom.json the variable without http must not be well recognized in the urljoin function used for the config and therefore returns the 2nd argument "templates" app/tools/config.py TEMPLATE_URL = urljoin(SERVER_URL, TEMPLATE_PATH)

for the PUID and PGID this has no effect in my case because I use a volume docker and not a mount bind so the permissions are automatically same as program user