What would be the proper way to add a power button for BalenaOS

Well I changed up my dockerfile quite a bit here:

FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-python:3.7.4

# Enable systemd init system
ENV INITSYSTEM on

# Set the working directory
WORKDIR /usr/src/app

RUN install_packages dbus

# Upgrade pip
RUN pip install --upgrade pip
COPY requirements.txt .
RUN pip install --user -r requirements.txt --no-cache-dir --disable-pip-version-check \
                --index-url https://www.piwheels.org/simple

# Copy everything into the container
COPY . ./
#Make sure scripts in .local are usable:
ENV PATH=/root/.local/bin:$PATH
ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
# Start application
CMD ["bash", "start.sh"]

start.sh

#!/usr/bin/env bash

## connect to the host's system bus from the application container
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

python button.py

button.py

import RPi.GPIO as GPIO
import time
import dbus

# Set GPIO mode: GPIO.BCM or GPIO.BOARD
GPIO.setmode(GPIO.BOARD)

# Set pin 5 an an input, and enable the internal pull-up resistor
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)

oldButtonState1 = True

while True:
    buttonState1 = GPIO.input(5)

    if buttonState1 != oldButtonState1 and buttonState1 == False :
        bus = dbus.SystemBus()
        boolean = dbus.Boolean(True)
        remote_object = bus.get_object('org.freedesktop.login1', '/org/freedesktop/login1')
        interface = dbus.Interface(remote_object, 'org.freedesktop.login1.Manager.PowerOff')

        print (interface)

    oldButtonState1 = buttonState1

time.sleep(1)

The result is still:

<Interface <ProxyObject wrapping <dbus._dbus.SystemBus (system) at 0x768e2fc0> :1.0 /org/freedesktop/login1 at 0x768f13d0> implementing 'org.freedesktop.login1.Manager.PowerOff' at 0x76582910>