OliveTin icon indicating copy to clipboard operation
OliveTin copied to clipboard

entities as YAML output for container orchestration

Open ServerGeek82 opened this issue 1 year ago • 3 comments

What seems to be the problem?!

First off this is an amazing project.

This is almost a 2 sided question. I want to be able to generate the containers.yaml file from yaml instead of JSON. Is this possible?

2nd below is my snippet from config.yaml the debug logs of the container itself.

At the bottom I will also have a copy of the script used to create the yaml file as well.

If you are getting an error message, then please copy/paste, or better, provide a screenshot to show us exactly what is wrong.

level="info" msg="### SOSREPORT START (copy all text to SOSREPORT END)
 Build:
commit: 044613a
version: 2024.09.11
date: 2024-09-11T16:19:52Z

 Runtime:
os: linux
osreleaseprettyname: PRETTY_NAME=\"Fedora Linux 40 (Container Image)\"
arch: amd64
incontainer: true
lastbrowseruseragent: ""
user: ""
uid: ""
sshfoundkey: /config/ssh/id_rsa
sshfoundconfig: not found at /root/.ssh/config
availableversion: none

 Config:
countofactions: 10
countofdashboards: 2
loglevel: DEBUG
listenaddresssinglehttpfrontend: 0.0.0.0:1337
listenaddresswebui: localhost:1340
listenaddressrestactions: localhost:1338
listenaddressgrpcactions: localhost:1339
timezone: Local
timenow: 2024-09-18 22:06:51.135498282 +0000 UTC m=+2782.883451754
configdirectory: /config
webuidirectory: /var/www/olivetin (/var/www/olivetin/)
themesdirectory: /config/custom-webui

### SOSREPORT END  (copy all text from SOSREPORT START)"

A sosreport really helps us to help you, by providing critical information about your install. If you can generate a sosreport, please copy and paste the output here.

How to generate a sosreport: https://docs.olivetin.app/sosreport.html

What package/file/container did you use to install OliveTin?

eg: OliveTin-1234-x86_64.rpm eg: Container from Dockerhub - please include the version number

Your config.yaml

`  # This is the second dashboard.
  - title: MxProd01 Containers
    contents:
      - title: 'Container {{ container.container_name }}'
        entity: container
        type: fieldset
        contents:
          - type: display
            title: |
              Uptime: {{ container.uptime }} <br />
              Status: <strong>{{ container.state }}</strong> <br />
              Exposed Ports: {{ container.exposed_ports | join(', ') }} <br />
          - title: 'Start {{ container.container_name }}'
          - title: 'Stop {{ container.container_name }}'
          - title: 'Pull {{ container.container_name }}'
`

`    # Hidden actions....shhh
  - title: Update container entity file
    shell: 'sh /config/scripts/container.sh > /config/entities/containers.yaml'
    hidden: true
    timeout: 120
    execOnStartup: true
    execOnCron: '*/5 * * * *'

entities:
  - file: /config/entities/containers.yaml
    name: container

Log output on container startup

level="debug" msg="fsnotify event relevant: WRITE         \"/etc/OliveTin/entities/containers.yaml\""
level="debug" msg="fsnotify event &{callbackWrapper:0xc000296050 callbackComplete:true}"
level="debug" msg="fsnotify event callback queued within debounce delay: containers.yaml"
level="info" msg="Action finished" actionTitle="Update container entity file" exit="127" outputLength="77" timedOut="false"
level="debug" msg="fsnotify event callback being fired: containers.yaml"
level="info" msg="Loading entity file with YAML format" file="/etc/OliveTin/entities/containers.yaml" name="container"
level="debug" msg="updateSvFromFile: [map[]]"

Log output while running

`level="debug" msg="ACL check - isAllowedExec" actionTitle="Update container entity file" relevantAcls="0" requiredPermission="2" usergroup="system" username="cron"
level="info" msg="Action parse args - Before" actionTitle="Update container entity file" cmd="sh /config/scripts/container.sh > /config/entities/containers.yaml"
level="info" msg="Action parse args - After" actionTitle="Update container entity file" cmd="sh /config/scripts/container.sh > /config/entities/containers.yaml"
level="info" msg="Action started" actionTitle="Update container entity file" timeout="120"
level="info" msg="Action finished" actionTitle="Update container entity file" exit="127" outputLength="77" timedOut="false"`

Please copy-paste your config.yaml here

You don't need to include anything under "actions:" unless that is where your error probably is.

OliveTin logs

If possible, please copy and paste your OliveTin logs from when the error happened.

Screenshot of WebDeveloper console logs

If you know how, and if you think it's relevant, a screenshot of the WebDeveloper console from when you clicked a button is often really helpful.

Anything else? SH of script used to create the yaml from docker inspect `

#!/bin/bash

# Start the YAML document
echo "---"
echo "containers:"

# Loop through all containers
for container in $(docker ps -a -q); do
  # Get container details from docker ps
  container_name=$(docker inspect --format '{{.Name}}' $container | sed 's/\///')
  running_for=$(docker ps -a --filter id=$container --format '{{.RunningFor}}')
  status=$(docker ps -a --filter id=$container --format '{{.Status}}')
  state=$(docker ps -a --filter id=$container --format '{{.State}}')

  # Extract all exposed ports (host or internal) and add to an array
  exposed_ports=$(docker inspect --format '{{range $p, $conf := .NetworkSettings.Ports}}{{if $conf}}{{if (index $conf 0).HostPort}}{{(index $conf 0).HostPort}}{{else}}{{$p}}{{end}} {{end}}{{end}}' $container)

  # Convert space-separated ports into a YAML list
  exposed_ports_list=$(echo $exposed_ports | sed 's/ /", "/g')

  # Output in YAML format
  echo "  - container_name: $container_name"
  echo "    uptime: \"$running_for\""
  echo "    status: \"$status\""
  echo "    state: \"$state\""
  echo "    exposed_ports: [\"$exposed_ports_list\"]"
done

Add any other context about the problem here.

ServerGeek82 avatar Sep 18 '24 22:09 ServerGeek82

Hey @ServerGeek82 , sorry that you've been waiting for a reply on this one - I don't know why, but I just didn't see this issue. It's been a busy few weeks.

So, OliveTin absolutely supports using yaml files for entity files, but when docker ps --format json exists, with basically the same output as your script, what is the point of using the script?

jamesread avatar Oct 12 '24 23:10 jamesread

I use the script for output in other apps as well. Reusability is all.

ServerGeek82 avatar Oct 13 '24 00:10 ServerGeek82

Ahh okay, so what's the problem you're seeing when loading it with OliveTin?

jamesread avatar Oct 13 '24 00:10 jamesread