Remote-SSH Debugging for Appdaemon Apps in Docker Container

A docker container with ssh natively enabled for dev can be used for debugging the apps of AppDaemon or AD itself. The base image has been changed into Python:3.x (Debian).

No source code needs to be on your local machine due to the Remote-SSH in the VSCode. Minimize the development envirnment configuration. The config folder in use can be volumed (-v) to the container directly. But do not worry about interfering running instance because all the files have been copied to the dev config folder.

Just copy the AppDaemon service in the docker-compose.yml (same with docker run) with a few modifications and type the command docker-compose up. Let’s roll.

Features

  • Local Deployment free (almost)
  • Existing config folder can be used directly
  • Small modifications of a running container service is ready to go

How to use

If you are using docker-compose to running AD and the original service looks like this:

version: '3.3'
services:
    appdaemon:
        image: acockburn/appdaemon:latest
        environment:
            HA_URL: "http://192.168.1.100:8123"
            TOKEN: "ha_long_live_token"
            DASH_URL: "http://192.168.1.100:5050"
        volumes:
            - ./appdaemon/conf:/conf
            - /etc/localtime:/etc/localtime:ro
        ports:
            - 5050:5050
        restart: unless-stopped

Copy the service and modify it:

    appdaemon_dev:
    # set a different service name
        image: blindlight/appdaemon:dev
        # the image set to blindlight/appdaemon
        # the tag can be latest(offical AD master branch)
        # or dev(offcial AD dev branch)
        environment:
            HA_URL: "http://192.168.1.100:8123"
            TOKEN: "ha_long_live_token"
            DASH_URL: "http://192.168.1.100:5050"
            # SSHPASSWORD: "set_root_ssh_password"   # set root password for ssh
            RSA_PUB: id_rsa-ad-dev.pub # alternatively, if you prefer rsa-key, set this to the rsa public file you create in local machine.
        volumes:
            - ./appdaemon/conf:/conf
            - /etc/localtime:/etc/localtime:ro
        ports:
            - 5050:5050
            - "8022:22" # set the ssh port mapping, don't forget the quotes because yaml recognizes int(a):int(b)<60 as a*60+b
        restart: unless-stopped

Then

docker-compose up -d

Install Remote-SSH extention if you don’t have it.

Open remote window to config a ssh. Recommand to edit config file.

Host appdaemon-dev                        # host id, selfdefine
  User root                               # root, do not change
  HostName 192.168.1.10                   # host ip
  # IdentityFile ~/.ssh/id_rsa-ad-dev     # rsa private key*
  Port 8022                               # ssh port you mapping in container

* To create ssh-key

ssh-keygen -t rsa -b 4096 -f rsa_file

A private key file and a public key file will be create in the %USERPROFILE%\.ssh\
Copy the public-key to AD config folder and change the env in the docker-compose.yml accordingly.

After ssh into the remote container, open folder /usr/src/app
open_debug_folder
Select an app and add a breakpoint then press F5 to start debugging.

Inspired by

This works much better if you use VScode to remote directly into the docker container itself. That way linters have a much easier time linting your imports.

Here is the link how to do that.

https://code.visualstudio.com/docs/remote/containers

Reviving the topic.
I have the following setup.
VScode connecting via remote ssh to a debian pc running homeassistant in docker supervised
I connect to the appdaemon docker (add-on) via vscode
when I try to run in debug though pylance complains of a missing assai import and it stops.

Any clue?