Skip to content

Instantly share code, notes, and snippets.

@trilom
Created June 4, 2022 00:42
Show Gist options
  • Save trilom/40fab563db416a69c63c127688ce7924 to your computer and use it in GitHub Desktop.
Save trilom/40fab563db416a69c63c127688ce7924 to your computer and use it in GitHub Desktop.
Docker container work on UXG-Pro

Run something on boot for UXG

Prepare UXG:container:whoami

This is the "thing you want to run" like pihole, I am using a simple web server.

You'll want to prepare a tar of the container

#### FROM CLIENT (your laptop)
# pull latest
docker pull --platform=linux/arm64 traefik/whoami:latest
# save image
export IMAGE_TAG=$(docker image ls traefik/whoami:latest --format '{{.ID}}')
docker save $IMAGE_TAG -o whoami.tar
# you can use gzip for fatties
# docker save $IMAGE_TAG | gzip > whoami.tar.gz
echo $IMAGE_TAG
scp whoami.tar 192.168.1.1:.

Prepare UXG:container:uxg-setup

# shell into container
uxg-setup shell
# make a new entrypoint
cat > /usr/local/bin/docker-entrypoint.sh <<EOF
#!/bin/sh
# sleep 5 to wait for SSH to become available
sleep 5
ssh -o StrictHostKeyChecking=no root@127.0.0.1 sh -c "\$(command -v 'date') > /mnt/data/on-date"
# lets wait 10-15 more for time to be correct, 10 sometimes works 15 is safe
sleep 15
ssh -o StrictHostKeyChecking=no root@127.0.0.1 /mnt/data/init.sh
set -e

if [ "\${1#-}" != "\${1}" ] || [ -z "\$(command -v "\${1}")" ]; then
  set -- node "\$@"
fi

exec "\$@"
EOF

Prepare UXG:host

In order for this to work, you need to prepare the host. This means that it will most likely not be there after a reflash (maybe update), but this does persist reboots within the same version (testing on 6/3/2022 v1.12.19).

The script will load up your tar, tag it correctly, and start it. Note this is set up to create the container with the following arguments -d --name ${CONTAINER_NAME} --label version= --network=host --privileged --stop-timeout=60 so if you don't want host networking (all interfaces), and aren't ready to firewall these out-of-band connections with privileged access, then take care.

# stage work container
mv whoami.tar /mnt/data/init_containers/.
cat > /mnt/data/init.sh <<EOF
#!/bin/sh
\$(command -v 'date') > /mnt/data/start-date 2>&1

source \$(command -v 'uxg-setup') help > /dev/null 2>&1

IMAGE_NAME="traefik/whoami"
CONTAINER_NAME="whoami"
IMAGE_TAG="default"

set_mounts() {
  MOUNTS="-e WHOAMI_PORT_NUMBER=24444"
}
get_version() {
   echo \$(podman inspect --format '{{ index .Digest}}' "${1}")
}

podman load --input /mnt/data/init_containers/whoami.tar
podman tag c59594bb13e9 localhost/traefik/whoami:latest localhost/traefik/whoami:default
start
\$(command -v 'date') > /mnt/data/stop-date 2>&1
EOF
chmod +x /mnt/data/init.sh

If this doesn't work for you, then you can simplify things some.

Simple

Just load up tar, and run command.

cat > /mnt/data/init.sh <<EOF
#!/bin/sh
podman load --input /mnt/data/init_containers/whoami.tar
podman run -d -e WHOAMI_PORT_NUMBER=24444 --name whoami c59594bb13e9
EOF
chmod +x /mnt/data/init.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment