Automatic update all hosts
continuous-integration/drone/push Build is failing Details

This commit is contained in:
starcalc 2022-09-08 20:07:10 +02:00
parent b09717595a
commit 50b37674ff
4 changed files with 61 additions and 39 deletions

View File

@ -1,54 +1,47 @@
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
name: default name: default
steps: steps:
- name: fetch ip - name: fetch ips
image: cburki/mosquitto-clients image: cburki/mosquitto-clients
commands: commands:
- echo "$hostname" - rm -f lastknownhostips
- mosquitto_sub -h raum.ctdo.de -t "homie/$hostname/\$localip" -C 1 | tr -d '\n' - cat hosts
- mosquitto_sub -h raum.ctdo.de -t "homie/$hostname/\$localip" -C 1 | tr -d '\n' >lastknownip - for h in $(cat hosts); do echo $h; echo $h; done
- cat "lastknownip" - for h in $(cat hosts); do mosquitto_sub -h raum.ctdo.de -t "homie/$h/\$localip" -C 1; done >lastknownips
environment: - for h in $(cat hosts); do echo -n "$h," >>lastknownhostips; mosquitto_sub -h raum.ctdo.de -t "homie/$h/\$localip" -C 1 >>lastknownhostips; done
hostname: - cat lastknownhostips
from_secret: hostname - cat lastknownips
- name: configure - name: build
image: alpine image: suculent/platformio-docker-build
commands: commands:
- sed -i "s/WIFISSID/$IOTSSID/" data/homie/config.json # Build images
- sed -i "s/WIFIPASS/$iotpwd/" data/homie/config.json - platformio run --environment d1_mini
- sed -i "s/HOSTNAME/$hostname/g" data/homie/config.json - |
- sed -i "s/HOSTNAME/$hostname/g" data/homie/config.json chmod u+x ./configurefs.sh
- lastknownip=$(cat lastknownip) chmod u+x ./uploadfs.sh
- sed -i "s/HOSTNAME/$lastknownip/g" platformio.ini ./configurefs.sh
- name: upload image
image: curlimages/curl
commands:
# Upload image with espota-gateway
# All hosts receive the identical image
- |
cat lastknownips
for thisip in $(cat lastknownips)
do
echo "Current IP to upload is $thisip"
curl -m 180 --insecure --no-progress-meter --fail-with-body --request POST --url "https://espota.ctdo.de/" --header "Content-Type: multipart/form-data" --form ip="$thisip" --form firmware=@.pio/build/d1_mini/firmware.bin --no-buffer
done
- name: upload configs
image: curlimages/curl
commands:
- ls -lA .
- /bin/sh ./uploadfs.sh
environment: environment:
hostname:
from_secret: hostname
IOTSSID: IOTSSID:
from_secret: iotssid from_secret: iotssid
iotpwd: iotpwd:
from_secret: iotpwd from_secret: iotpwd
- name: build
image: suculent/platformio-docker-build
commands:
# - pip install -U platformio
# Build image
- platformio run --environment d1_mini
# Build file system image
- platformio run --target buildfs --environment d1_mini
- name: upload
image: curlimages/curl
commands:
- lastknownip=$(cat lastknownip)
- echo "$lastknownip"
# Upload image with espota-gateway
- |
curl --insecure --no-progress-meter --fail-with-body --request POST --url "https://espota.ctdo.de/" --header "Content-Type: multipart/form-data" --form ip="$lastknownip" --form firmware=@.pio/build/d1_mini/firmware.bin --no-buffer
# TODO: Upload file system image with espota-gateway, if the device is available again (or leave it to espota-gateway to retry often enough)
- |
curl --insecure --no-progress-meter --fail-with-body --request POST --url "https://espota.ctdo.de/" --header "Content-Type: multipart/form-data" --form ip="$lastknownip" --form spiffs=@.pio/build/d1_mini/spiffs.bin --no-buffer
### matrix-builds? - for multiple volumeknobs?
### https://0-8-0.docs.drone.io/matrix-builds/
###

16
configurefs.sh Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
while IFS="," read -r curhost curip
do
echo "Host ${curhost} and IP ${curip}"
cp data/homie/config.json data/homie/config.json.sample
sed -i "s/WIFISSID/$IOTSSID/" data/homie/config.json
sed -i "s/WIFIPASS/$iotpwd/" data/homie/config.json
sed -i "s/HOSTNAME/${curhost}/g" data/homie/config.json
sed -i "s/HOSTNAME/${curhost}/g" data/homie/config.json
# Build image with these parameters
platformio run --target buildfs --environment d1_mini
# Save this image
cp .pio/build/d1_mini/spiffs.bin .pio/build/d1_mini/spiffs_${curhost}.bin
# Revert config.json
cp data/homie/config.json.sample data/homie/config.json
done < <(cat lastknownhostips)

2
hosts Normal file
View File

@ -0,0 +1,2 @@
volumeknob2
volumeknob3

11
uploadfs.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/sh
echo "Running"
while read line
do
echo "Line is ${line}"
curhost=$(echo ${line} | cut -d ',' -f1)
curip=$(echo ${line} | cut -d ',' -f2)
echo "Host ${curhost} and IP ${curip}"
# Upload this image
curl -m 180 --insecure --no-progress-meter --fail-with-body --request POST --url "https://espota.ctdo.de/" --header "Content-Type: multipart/form-data" --form ip="$curip" --form spiffs=@.pio/build/d1_mini/spiffs_${curhost}.bin --no-buffer
done < <(cat lastknownhostips)