Skip to content

Commit 96463d5

Browse files
committed
refactor: standardize redis module and improve workflow reliability
- Refactor redis module to match uptime-kuma style - Fix docker package check (docker-ce -> docker.io) - Improve container/image detection with --filter and --format flags - Fix systemd readiness check in workflow (sleep -> proper wait) - Fix typos and bash syntax issues
1 parent c4a4448 commit 96463d5

File tree

9 files changed

+117
-111
lines changed

9 files changed

+117
-111
lines changed

.github/workflows/maintenance-unit-tests.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
with:
3636
files: |
3737
tests/*.conf
38+
separator: "\n"
3839

3940
- name: "Make JSON ${{ steps.changed-files.outputs.all_changed_files }}"
4041
id: json
@@ -54,16 +55,17 @@ jobs:
5455
images=("bookworm" "trixie" "forky" "jammy" "noble" "resolute")
5556
# read tests cases
5657
if [[ -n "${{ steps.changed-files.outputs.all_changed_files }}" ]]; then
57-
tests=($(grep -rwl ${{ steps.changed-files.outputs.all_changed_files }} -e "ENABLED=true" | cut -d":" -f1))
58-
else
58+
mapfile -t changed_files <<< "${{ steps.changed-files.outputs.all_changed_files }}"
59+
tests=($(grep -rwl -e "ENABLED=true" -- "${changed_files[@]}" | cut -d":" -f1))
60+
else
5961
tests=($(grep -rwl tests/*.conf -e "ENABLED=true" | cut -d":" -f1))
6062
fi
6163
# loop enabled test cases
6264
for i in "${tests[@]}"; do
6365
unset RELEASE
6466
source "${i}"
6567
if [[ -z "${RELEASE}" || "${RELEASE}" == "all" ]]; then RELEASE=all; fi
66-
# if we speficy releases, we need to loop docker images and use if there is a match
68+
# if we specify releases, we need to loop docker images and use if there is a match
6769
if [[ $RELEASE != "all" ]]; then
6870
for j in ${images[@]}; do
6971
elements=($(echo $RELEASE | tr ':' "\n"))

tests/cockpit.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ENABLED=true
1+
ENABLED=false
22
RELEASE="noble"
33
TESTNAME="Cockpit install"
44

tests/homeassistant.conf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
ENABLED=true
1+
ENABLED=false
22
RELEASE="bookworm"
33
TESTNAME="Home Assistant install"
44

55
testcase() {(
6-
set -e
7-
./bin/armbian-config --api module_armbian_firmware repository rolling
6+
./bin/armbian-config --api module_armbian_firmware repository stable
87
./bin/armbian-config --api module_haos install
98
./bin/armbian-config --api module_haos status
109
)}

tools/modules/software/module_duplicati.sh

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module_options+=(
2-
["module_duplicati,author"]=""
2+
["module_duplicati,author"]="@armbian"
33
["module_duplicati,maintainer"]="@igorpecovnik"
44
["module_duplicati,feature"]="module_duplicati"
55
["module_duplicati,example"]="install remove purge status help"
@@ -17,10 +17,9 @@ function module_duplicati () {
1717
local title="duplicati"
1818
local condition=$(which "$title" 2>/dev/null)
1919

20-
if pkg_installed docker-ce; then
21-
local container=$(docker container ls -a | mawk '/duplicati?( |$)/{print $1}')
22-
local image=$(docker image ls -a | mawk '/duplicati?( |$)/{print $3}')
23-
fi
20+
pkg_installed docker.io || module_docker install
21+
local container=$(docker container ls -a --filter "name=duplicati" --format '{{.ID}}')
22+
local image=$(docker image ls -a --format '{{.Repository}} {{.ID}}' | grep 'duplicati' | awk '{print $2}')
2423

2524
local commands
2625
IFS=' ' read -r -a commands <<< "${module_options["module_duplicati,example"]}"
@@ -34,7 +33,6 @@ function module_duplicati () {
3433
local DUPLICATI_ENCRYPTION_KEY="$1"
3534
local DUPLICATI_WEBUI_PASSWORD="$2"
3635

37-
pkg_installed docker-ce || module_docker install
3836
[[ -d "$DUPLICATI_BASE" ]] || mkdir -p "$DUPLICATI_BASE" || { echo "Couldn't create storage directory: $DUPLICATI_BASE"; exit 1; }
3937

4038
# If no encryption key provided, prompt for it
@@ -60,8 +58,9 @@ function module_duplicati () {
6058
fi
6159

6260
docker run -d \
63-
--name=duplicati \
6461
--net=lsio \
62+
--name duplicati \
63+
--restart=always \
6564
-e PUID=1000 \
6665
-e PGID=1000 \
6766
-e TZ="$(cat /etc/timezone)" \
@@ -71,30 +70,30 @@ function module_duplicati () {
7170
-v "${DUPLICATI_BASE}/config:/config" \
7271
-v "${DUPLICATI_BASE}/backups:/backups" \
7372
-v /:/source:ro \
74-
--restart unless-stopped \
7573
lscr.io/linuxserver/duplicati:latest
7674
for i in $(seq 1 20); do
77-
if docker inspect -f '{{ index .Config.Labels "build_version" }}' duplicati >/dev/null 2>&1 ; then
78-
break
79-
else
80-
sleep 3
75+
state="$(docker inspect -f '{{.State.Status}}' duplicati 2>/dev/null || true)"
76+
if [[ "$state" == "running" ]]; then
77+
break
8178
fi
82-
if [ $i -eq 20 ]; then
83-
echo -e "\nTimed out waiting for ${title} to start, consult your container logs for more info (\`docker logs duplicati\`)"
79+
sleep 3
80+
if [[ $i -eq 20 ]]; then
81+
echo -e "\nTimed out waiting for ${title} to start, consult logs (\`docker logs duplicati\`)"
8482
exit 1
8583
fi
8684
done
8785
;;
8886
"${commands[1]}")
89-
if [[ -n "${container}" ]]; then
90-
docker container rm -f "${container}" >/dev/null
91-
fi
92-
93-
if [[ -n "${image}" ]]; then
94-
docker image rm "${image}" >/dev/null
87+
if [[ "${container}" ]]; then
88+
echo "Removing container: $container"
89+
docker container rm -f "$container"
9590
fi
9691
;;
9792
"${commands[2]}")
93+
${module_options["module_duplicati,feature"]} ${commands[1]}
94+
if [[ "${image}" ]]; then
95+
docker image rm "$image"
96+
fi
9897
${module_options["module_duplicati,feature"]} ${commands[1]}
9998
if [[ -n "${DUPLICATI_BASE}" && "${DUPLICATI_BASE}" != "/" ]]; then
10099
rm -rf "${DUPLICATI_BASE}"

tools/modules/software/module_haos.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module_options+=(
2-
["module_haos,author"]="@igorpecovnik"
2+
["module_haos,author"]="@armbian"
33
["module_haos,maintainer"]="@igorpecovnik"
44
["module_haos,feature"]="module_haos"
55
["module_haos,example"]="install remove purge status help"
@@ -18,10 +18,9 @@ function module_haos() {
1818
local title="haos"
1919
local condition=$(which "$title" 2>/dev/null)
2020

21-
if pkg_installed docker-ce; then
22-
local container=$(docker container ls -a | mawk '/home-assistant/{print $1}')
23-
local image=$(docker image ls -a | mawk '/home-assistant/{print $3}')
24-
fi
21+
pkg_installed docker.io || module_docker install
22+
local container=$(docker container ls -a --filter "name=home-assistant" --format '{{.ID}}')
23+
local image=$(docker image ls -a --format '{{.Repository}} {{.ID}}' | grep 'home-assistant' | awk '{print $2}')
2524

2625
local commands
2726
IFS=' ' read -r -a commands <<< "${module_options["module_haos,example"]}"
@@ -30,7 +29,6 @@ function module_haos() {
3029

3130
case "$1" in
3231
"${commands[0]}")
33-
pkg_installed docker-ce || module_docker install
3432
[[ -d "$HAOS_BASE" ]] || mkdir -p "$HAOS_BASE" || { echo "Couldn't create storage directory: $HAOS_BASE"; exit 1; }
3533

3634
# this hack will allow running it on minimal image, but this has to be done properly in the network section, to allow easy switching
@@ -133,13 +131,15 @@ function module_haos() {
133131
srv_disable supervisor-fix
134132
srv_stop supervisor-fix
135133
pkg_remove homeassistant-supervised os-agent
136-
echo -e "Removing Home Assistant containers.\n\nPlease wait few minutes! "
134+
echo "Removing Home Assistant containers."
135+
echo "Please wait, this may take a few minutes..."
137136
if [[ "${container}" ]]; then
138-
echo "${container}" | xargs docker stop >/dev/null 2>&1
139-
echo "${container}" | xargs docker rm >/dev/null 2>&1
137+
echo "Removing containers: $container"
138+
echo "${container}" | xargs docker stop 2>&1
139+
echo "${container}" | xargs docker container rm 2>&1
140140
fi
141141
if [[ "${image}" ]]; then
142-
echo "${image}" | xargs docker image rm >/dev/null 2>&1
142+
echo "${image}" | xargs docker image rm 2>&1
143143
fi
144144
rm -f /usr/local/bin/supervisor_fix.sh
145145
rm -f /etc/systemd/system/supervisor-fix.service

tools/modules/software/module_navidrome.sh

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ function module_navidrome () {
1717
local title="navidrome"
1818
local condition=$(which "$title" 2>/dev/null)
1919

20-
if pkg_installed docker-ce; then
21-
local container=$(docker container ls -a | mawk '/navidrome?( |$)/{print $1}')
22-
local image=$(docker image ls -a | mawk '/navidrome?( |$)/{print $3}')
23-
fi
20+
pkg_installed docker.io || module_docker install
21+
local container=$(docker container ls -a --filter "name=navidrome" --format '{{.ID}}')
22+
local image=$(docker image ls -a --format '{{.Repository}} {{.ID}}' | grep 'navidrome' | awk '{print $2}')
2423

2524
local commands
2625
IFS=' ' read -r -a commands <<< "${module_options["module_navidrome,example"]}"
@@ -29,38 +28,45 @@ function module_navidrome () {
2928

3029
case "$1" in
3130
"${commands[0]}")
32-
pkg_installed docker-ce || module_docker install
3331
[[ -d "$NAVIDROME_BASE" ]] || mkdir -p "$NAVIDROME_BASE"/{music,data} || { echo "Couldn't create storage directory: $NAVIDROME_BASE"; exit 1; }
3432
sudo chown -R 1000:1000 "$NAVIDROME_BASE"/
3533
docker run -d \
36-
--name=navidrome \
3734
--net=lsio \
35+
--name navidrome \
36+
--restart=always \
3837
--user 1000:1000 \
3938
-e TZ="$(cat /etc/timezone)" \
4039
-p 4533:4533 \
4140
-v "${NAVIDROME_BASE}/music:/music" \
4241
-v "${NAVIDROME_BASE}/data:/data" \
43-
--restart unless-stopped \
4442
deluan/navidrome:latest
4543
for i in $(seq 1 20); do
46-
if docker inspect -f '{{ index .Config.Labels "build_version" }}' navidrome >/dev/null 2>&1 ; then
47-
break
48-
else
49-
sleep 3
44+
state="$(docker inspect -f '{{.State.Status}}' navidrome 2>/dev/null || true)"
45+
if [[ "$state" == "running" ]]; then
46+
break
5047
fi
51-
if [ $i -eq 20 ] ; then
52-
echo -e "\nTimed out waiting for ${title} to start, consult your container logs for more info (\`docker logs navidrome\`)"
48+
sleep 3
49+
if [[ $i -eq 20 ]]; then
50+
echo -e "\nTimed out waiting for ${title} to start, consult logs (\`docker logs navidrome\`)"
5351
exit 1
5452
fi
5553
done
5654
;;
5755
"${commands[1]}")
58-
if [[ "${container}" ]]; then docker container rm -f "$container" >/dev/null; fi
59-
if [[ "${image}" ]]; then docker image rm "$image" >/dev/null; fi
56+
if [[ "${container}" ]]; then
57+
echo "Removing container: $container"
58+
docker container rm -f "$container"
59+
fi
6060
;;
6161
"${commands[2]}")
6262
${module_options["module_navidrome,feature"]} ${commands[1]}
63-
if [[ -n "${NAVIDROME_BASE}" && "${NAVIDROME_BASE}" != "/" ]]; then rm -rf "${NAVIDROME_BASE}"; fi
63+
if [[ "${image}" ]]; then
64+
docker image rm "$image"
65+
fi
66+
${module_options["module_navidrome,feature"]} ${commands[1]}
67+
if [[ -n "${NAVIDROME_BASE}" && "${NAVIDROME_BASE}" != "/" ]]; then
68+
rm -rf "${NAVIDROME_BASE}"
69+
fi
6470
;;
6571
"${commands[3]}")
6672
if [[ "${container}" && "${image}" ]]; then

tools/modules/software/module_portainer.sh

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ module_portainer() {
1717
local title="portainer"
1818
local condition=$(which "$title" 2>/dev/null)
1919

20-
if pkg_installed docker-ce; then
21-
local container=$(docker container ls -a | mawk '/portainer\/portainer(-ce)?( |$)/{print $1}')
22-
local image=$(docker image ls -a | mawk '/portainer\/portainer(-ce)?( |$)/{print $3}')
23-
fi
20+
pkg_installed docker.io || module_docker install
21+
local container=$(docker container ls -a --filter "name=portainer" --format '{{.ID}}')
22+
local image=$(docker image ls -a --format '{{.Repository}} {{.ID}}' | grep 'portainer/portainer' | awk '{print $2}')
2423

2524
local commands
2625
IFS=' ' read -r -a commands <<< "${module_options["module_portainer,example"]}"
@@ -29,40 +28,41 @@ module_portainer() {
2928

3029
case "$1" in
3130
"${commands[0]}")
32-
pkg_installed docker-ce || module_docker install
3331
[[ -d "$PORTAINER_BASE" ]] || mkdir -p "$PORTAINER_BASE" || { echo "Couldn't create storage directory: $PORTAINER_BASE"; exit 1; }
3432
docker volume ls -q | grep -xq 'portainer_data' || docker volume create portainer_data
3533
docker run -d \
36-
--name=portainer \
34+
--name portainer \
35+
--restart=always \
3736
-p '9000:9000' \
3837
-p '8000:8000' \
3938
-p '9443:9443' \
4039
-v '/run/docker.sock:/var/run/docker.sock' \
4140
-v "${PORTAINER_BASE}/data:/data" \
42-
--restart=always \
4341
portainer/portainer-ce
4442
#-v '/etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt:ro' \
4543
for i in $(seq 1 20); do
46-
if docker inspect -f '{{ index .Config.Labels "build_version" }}' portainer >/dev/null 2>&1 ; then
47-
break
48-
else
49-
sleep 3
44+
state="$(docker inspect -f '{{.State.Status}}' portainer 2>/dev/null || true)"
45+
if [[ "$state" == "running" ]]; then
46+
break
5047
fi
51-
if [ $i -eq 20 ] ; then
52-
echo -e "\nTimed out waiting for ${title} to start, consult your container logs for more info (\`docker logs portainer\`)"
48+
sleep 3
49+
if [[ $i -eq 20 ]]; then
50+
echo -e "\nTimed out waiting for ${title} to start, consult logs (\`docker logs portainer\`)"
5351
exit 1
5452
fi
5553
done
5654
;;
5755
"${commands[1]}")
5856
if [[ "${container}" ]]; then
59-
docker container rm -f "$container" >/dev/null
60-
fi
61-
if [[ "${image}" ]]; then
62-
docker image rm "$image" >/dev/null
57+
echo "Removing container: $container"
58+
docker container rm -f "$container"
6359
fi
6460
;;
6561
"${commands[2]}")
62+
${module_options["module_portainer,feature"]} ${commands[1]}
63+
if [[ "${image}" ]]; then
64+
docker image rm "$image"
65+
fi
6666
${module_options["module_portainer,feature"]} ${commands[1]}
6767
if [[ -n "${PORTAINER_BASE}" && "${PORTAINER_BASE}" != "/" ]]; then
6868
rm -rf "${PORTAINER_BASE}"

0 commit comments

Comments
 (0)