Skip to content

Commit

Permalink
Merge pull request #104 from thin-edge/feat-set-firmware-on-first-boot
Browse files Browse the repository at this point in the history
feat(systemd): set initial firmware and hardware info on startup
  • Loading branch information
reubenmiller authored Oct 5, 2024
2 parents a26a570 + 1f61c72 commit 67555cb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
6 changes: 6 additions & 0 deletions images/child-device-container/child.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN apk add --no-cache \
&& curl -1sLf 'https://dl.cloudsmith.io/public/thinedge/community/config.alpine.txt?distro=alpine&codename=v3.8' >> /etc/apk/repositories \
&& apk add --no-cache \
tedge-apk-plugin \
tedge-inventory-plugin \
tedge-pki-smallstep-client \
&& echo "tedge ALL = (ALL) NOPASSWD: /usr/bin/tedge, /usr/bin/tedge-write /etc/*, /etc/tedge/sm-plugins/[a-zA-Z0-9]*, /bin/sync, /bin/kill" > /etc/sudoers.d/tedge \
&& echo "Defaults env_keep += \"FEATURES\"" > /etc/sudoers.d/step-ca \
Expand All @@ -23,6 +24,11 @@ COPY child-device-container/config/tedge-configuration-plugin.toml /etc/tedge/pl
COPY common/utils/enroll/enroll.sh /usr/bin/
COPY child-device-container/entrypoint.sh /app/
COPY common/utils/workflows/firmware_update.toml /etc/tedge/operations/

# Configure device (to run one-off commands on first boot)
COPY common/utils/configure-device/runner.sh /usr/share/configure-device/
COPY common/utils/set-startup-info /usr/share/configure-device/scripts.d/90_set-startup-info

ENV TEDGE_MQTT_CLIENT_HOST=tedge
ENV TEDGE_HTTP_CLIENT_HOST=tedge
ENV TEDGE_C8Y_PROXY_CLIENT_HOST=tedge
Expand Down
9 changes: 9 additions & 0 deletions images/child-device-container/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ fi
(cd /tmp && sudo /usr/bin/enroll.sh --no-inherit-env --provisioner-password-file "$PROVISION_PASSWORD_FILE")
rm -f "$PROVISION_PASSWORD_FILE"

# configure device scripts (run once)
if [ ! -f /etc/tedge/.configure-device-ran ]; then
/usr/share/configure-device/runner.sh
touch /etc/tedge/.configure-device-ran
fi

# Note: inventory scripts are run on every startup
/usr/share/tedge-inventory/runner.sh

# start agent
exec /usr/bin/tedge-agent
4 changes: 3 additions & 1 deletion images/child-device-systemd/child.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ COPY common/utils/configure-device/scripts.d/* /usr/share/configure-device/scrip
COPY common/utils/configure-device/configure-device.service /lib/systemd/system/
RUN systemctl enable configure-device.service

# Configure device hooks
# add mtls enablement script. Store script under /usr/bin so it can also be manually called
COPY common/utils/enroll/enroll.sh /usr/bin/
RUN ln -sf /usr/bin/enroll.sh /usr/share/configure-device/scripts.d/70_enable_mtls
RUN ln -sf /usr/bin/enroll.sh /usr/share/configure-device/scripts.d/70_enroll
COPY common/utils/set-startup-info /usr/share/configure-device/scripts.d/90_set-startup-info

COPY child-device-systemd/config/system.toml /etc/tedge/
COPY child-device-systemd/config/tedge.toml /etc/tedge/
Expand Down
11 changes: 11 additions & 0 deletions images/common/utils/set-startup-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
set -e
TARGET="$(tedge config get mqtt.topic_root)/$(tedge config get mqtt.device_topic_id)"

# firmware
tedge mqtt pub --qos 1 "$TARGET/twin/firmware" "$(printf '{"name": "iot-linux", "version": "1.0.0"}')"

# Trigger inventory service on startup
if command -V systemd; then
systemctl start tedge-inventory.service ||:
fi
1 change: 1 addition & 0 deletions images/debian-systemd/debian-systemd.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ RUN mkdir -p /usr/share/configure-device/scripts.d/ \

# Configure device hooks
COPY common/utils/init-pki/init-pki.sh /usr/share/configure-device/scripts.d/30_init-pki
COPY common/utils/set-startup-info /usr/share/configure-device/scripts.d/90_set-startup-info

# Copy bootstrap script hooks
COPY common/config/bootstrap /etc/bootstrap
Expand Down
4 changes: 2 additions & 2 deletions tests/debian-systemd/children-container/operations.robot
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Install Firmware
${date_from}= Get Test Start Time
Sleep 1s
${binary_url}= Cumulocity.Create Inventory Binary iot-linux child-firmware contents=dummy_file
${operation}= Cumulocity.Install Firmware name=iot-linux version=1.0.0 url=${binary_url}
${operation}= Cumulocity.Install Firmware name=iot-linux version=2.0.0 url=${binary_url}
Operation Should Be SUCCESSFUL ${operation} timeout=90
Cumulocity.Device Should Have Fragment Values c8y_Firmware.name\=iot-linux c8y_Firmware.version\=1.0.0 c8y_Firmware.url\=${binary_url}
Cumulocity.Device Should Have Fragment Values c8y_Firmware.name\=iot-linux c8y_Firmware.version\=2.0.0 c8y_Firmware.url\=${binary_url}

Set Configuration
${binary_url}= Cumulocity.Create Inventory Binary modem_v2 child-modem-config contents={"version":"2"}
Expand Down
4 changes: 2 additions & 2 deletions tests/debian-systemd/children-systemd/operations.robot
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Install Firmware
${date_from}= Get Test Start Time
Sleep 1s
${binary_url}= Cumulocity.Create Inventory Binary iot-linux child-firmware contents=dummy_file
${operation}= Cumulocity.Install Firmware name=iot-linux version=1.0.0 url=${binary_url}
${operation}= Cumulocity.Install Firmware name=iot-linux version=2.0.0 url=${binary_url}
Operation Should Be SUCCESSFUL ${operation} timeout=90
Cumulocity.Device Should Have Fragment Values c8y_Firmware.name\=iot-linux c8y_Firmware.version\=1.0.0 c8y_Firmware.url\=${binary_url}
Cumulocity.Device Should Have Fragment Values c8y_Firmware.name\=iot-linux c8y_Firmware.version\=2.0.0 c8y_Firmware.url\=${binary_url}

Set Configuration
${binary_url}= Cumulocity.Create Inventory Binary modem_v2 child-modem-config contents={"version":"2"}
Expand Down

8 comments on commit 67555cb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
11 0 2 11 100 52.325s

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
14 0 0 14 100 55.42s

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
7 0 0 7 100 53.701s

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
22 0 2 22 100 2m47.244s

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
7 0 0 7 100 45.501s

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
11 0 2 11 100 53.217s

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
14 0 0 14 100 56.298999999s

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
22 0 2 22 100 2m50.707s

Please sign in to comment.