Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ tasks:
set -e
echo "Runner version set as: {{ .EXAMPLE_VERSION }}"
TMP_PATH="$(mktemp -d)"
DEST_PATH="debian/arduino-app-cli/home/arduino/.local/share/arduino-app-cli/"
DEST_PATH="debian/arduino-app-cli/var/lib/arduino-app-cli/"
echo "Cloning arduino/app-bricks-examples into temporary directory ${TMP_PATH}..."
git clone --depth 1 --branch "{{ .EXAMPLE_VERSION }}" https://github.com/arduino/app-bricks-examples "${TMP_PATH}"
rm -rf "${DEST_PATH}/examples"
Expand Down Expand Up @@ -209,11 +209,11 @@ tasks:
generate:assets:
desc: This generates the models and bricks index. Also updates the corresponding testdata.
vars:
sed_replacement: s#runnerVersion = \".*#runnerVersion = \"{{.RUNNER_VERSION}}\"#
sed_replacement: s#RunnerVersion = \".*#RunnerVersion = \"{{.RUNNER_VERSION}}\"#
TMPDIR: '{{trimSuffix "/" (env "TMPDIR")| default "/tmp"}}/generate-assets'
SEMVER_TAG: "{{.RUNNER_VERSION}}"
OUTPUT_DIR: "{{.TMPDIR}}/{{.SEMVER_TAG}}"
ASSETS_DIR: debian/arduino-app-cli/home/arduino/.local/share/arduino-app-cli/assets
ASSETS_DIR: debian/arduino-app-cli/var/lib/arduino-app-cli/assets
TESTDATA_DIR: internal/e2e/daemon/testdata/assets
preconditions:
- sh: '[ ! -d "{{.ASSETS_DIR}}/{{.SEMVER_TAG}}" ] || [ ! -d "{{.TESTDATA_DIR}}/{{.SEMVER_TAG}}" ]'
Expand Down
5 changes: 5 additions & 0 deletions debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ RUN apt-get update && apt-get install -y sed
COPY ./debian/${DEB_NAME} /${DEB_NAME}/
COPY --from=go /app/${BINARY_NAME} /${DEB_NAME}/usr/bin/${BINARY_NAME}

RUN (cd /${DEB_NAME}/DEBIAN && \
sed -e '/# SHARED_FUNCTIONS/r helper_func.sh' ./prerm > prerm.tmp && mv prerm.tmp ./prerm && \
sed -e '/# SHARED_FUNCTIONS/r helper_func.sh' ./preinst > preinst.tmp && mv preinst.tmp ./preinst &&\
chmod a+x ./prerm ./preinst)

# Go application are tagged with `v` prefix, this remove the first v if present
RUN export VERSION=$(echo "${VERSION}" | sed -e "s/^v\(.*\)/\1/") && \
sed -i "s/\$ARCH/${ARCH}/" /${DEB_NAME}/DEBIAN/control && \
Expand Down
28 changes: 28 additions & 0 deletions debian/arduino-app-cli/DEBIAN/helper_func.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Function: cleanup_arduino_examples
# Description: Stops running Arduino apps within example directories and
# removes associated cache files, but only if the root
# examples directory exists.
#
# Arguments:
# $1 - The path to the root examples directory (EXAMPLES_DIR).
#
cleanup_arduino_examples() {
local EXAMPLES_DIR="$1"

if [ -d "${EXAMPLES_DIR}" ]; then
local EXAMPLES=$(find "${EXAMPLES_DIR}" -maxdepth 1 -mindepth 1 -type d 2>/dev/null)
echo "Stopping apps and clearing cache in: ${EXAMPLES_DIR}"
for dir_path in ${EXAMPLES}; do
# 1. Stop the application (suppress output and errors)
sudo -u arduino /usr/bin/arduino-app-cli app stop "${dir_path}" > /dev/null 2>&1 || true

# 2. Remove the cache directory
local CACHE_PATH="${dir_path}/.cache"

# Check if the cache directory exists before attempting to remove it
if [ -d "${CACHE_PATH}" ]; then
rm -r "${CACHE_PATH}"
fi
done
fi
}
11 changes: 10 additions & 1 deletion debian/arduino-app-cli/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#!/bin/sh

chown -R arduino:arduino /home/arduino/.local/share/arduino-app-cli
chown -R arduino:arduino /var/lib/arduino-app-cli

systemctl enable arduino-app-cli
systemctl enable arduino-burn-bootloader
systemctl enable arduino-avahi-serial.service

if [ "$1" = "configure" ]; then
if dpkg --compare-versions "$2" lt "0.9.0"; then
echo "Running pre-0.9.0 legacy migration..."
rm -rf /home/arduino/.local/share/arduino-app-cli/examples
rm -rf /home/arduino/.local/share/arduino-app-cli/properties.msgpack*
rm -rf /home/arduino/.local/share/arduino-app-cli/bootloader_burned.flag
fi
fi
15 changes: 15 additions & 0 deletions debian/arduino-app-cli/DEBIAN/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,18 @@ if ! getent group "$SYSUPGRADE_GROUP" >/dev/null 2>&1; then
groupadd --system "$SYSUPGRADE_GROUP"
fi
usermod -aG "$SYSUPGRADE_GROUP" "$APP_USER"


# SHARED_FUNCTIONS

if [ "$1" = "upgrade" ]; then
# check if this is an upgrade from an old version
if dpkg --compare-versions "$2" lt "0.9.0"; then
echo "Running pre-0.9.0 legacy migration..."
cleanup_arduino_examples /home/arduino/.local/share/arduino-app-cli/examples
mkdir -p /var/lib/arduino-app-cli
cp -rf /home/arduino/.local/share/arduino-app-cli/examples /var/lib/arduino-app-cli
cp -rf /home/arduino/.local/share/arduino-app-cli/properties.msgpack* /var/lib/arduino-app-cli
cp -rf /home/arduino/.local/share/arduino-app-cli/bootloader_burned.flag /var/lib/arduino-app-cli
fi
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fi
cp -r /home/arduino/.local/share/arduino-app-cli /examples /var/lib/arduino-app-cli

Copy link
Contributor Author

@martacarbone martacarbone Dec 16, 2025

Choose a reason for hiding this comment

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

Add the copy of examples here; add the copy of properties.msgpack* and bootloader_burned.flag here;
add rm -rf of examples, properties.msgpack, properties.msgpack.lock and bootloader_burned.flag in postinst

7 changes: 7 additions & 0 deletions debian/arduino-app-cli/DEBIAN/prerm
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/sh

set -e

systemctl disable arduino-app-cli
systemctl disable arduino-burn-bootloader
systemctl disable arduino-avahi-serial.service

# SHARED_FUNCTIONS

echo "Cache cleanup..."
cleanup_arduino_examples /var/lib/arduino-app-cli/examples
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[Unit]
Description=Burn arduino zephyr bootloader on first boot
After=fs-local.target
ConditionPathExists=!/home/arduino/.local/share/arduino-app-cli/bootloader_burned.flag
ConditionPathExists=!/var/lib/arduino-app-cli/bootloader_burned.flag

[Service]
Type=oneshot
RemainAfterExit=true
User=arduino
Group=arduino
ExecStart=/usr/bin/arduino-cli burn-bootloader -b arduino:zephyr:unoq -P jlink
ExecStartPost=/bin/mkdir -p /home/arduino/.local/share/arduino-app-cli
ExecStartPost=/bin/touch /home/arduino/.local/share/arduino-app-cli/bootloader_burned.flag
ExecStartPost=/bin/mkdir -p /var/lib/arduino-app-cli
ExecStartPost=/bin/touch /var/lib/arduino-app-cli/bootloader_burned.flag
StandardOutput=journal
StandardError=journal

Expand Down
2 changes: 1 addition & 1 deletion docs/contributor-guide/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Build the project (run once):

Start the arduino-app-cli in daemon mode:

- `ARDUINO_APP_CLI__DATA_DIR=debian/arduino-app-cli/home/arduino/.local/share/arduino-app-cli go tool task start`
- `ARDUINO_APP_CLI__DATA_DIR=debian/arduino-app-cli/var/lib/arduino-app-cli go tool task start`

NOTE: only a subset of HTTP APIs are working by running the daemon mode on a development PC. To run Arduino App CLI on the board see the **Running Arduino App CLI on the board** section below.

Expand Down
4 changes: 2 additions & 2 deletions docs/user-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The following environment variables are used to configure Arduino App CLI:
| Environment Variable | Default Value | Description |
| -------------------------------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------- |
| `ARDUINO_APP_CLI__APPS_DIR` | `/home/arduino/ArduinoApps` | Path to the directory where Arduino Apps created by the user are stored |
| `ARDUINO_APP_CLI__DATA_DIR` | `/home/arduino/.local/share/arduino-app-cli` | Path to the directory where internal data is stored (examples, assets, properties) |
| `ARDUINO_APP_CLI__DATA_DIR` | `/var/lib/arduino-app-cli` | Path to the directory where internal data is stored (examples, assets, properties) |
| `ARDUINO_APP_BRICKS__CUSTOM_MODEL_DIR` | `$HOME/.arduino-bricks/ei-models` | Path to the directory where custom AI models are stored |
| `ARDUINO_APP_CLI__ALLOW_ROOT` | `false` | Allow running `arduino-app-cli` as root (**Not recommended to set to true**) |
| `LIBRARIES_API_URL` | `https://api2.arduino.cc/libraries/v1/libraries` | URL of the external service used to search Arduino libraries |
Expand Down Expand Up @@ -37,7 +37,7 @@ Examples of user-defined Arduino Apps stored under the `ARDUINO_APP_CLI__APPS_DI
Examples of the `assets` and the builtin `examples` stored under the `ARDUINO_APP_CLI__DATA_DIR` folder.

```
/home/arduino/.local/share/arduino-app-cli/
/var/lib/arduino-app-cli/
├── assets
│   └── 0.5.0 # Version-specific assets
│   ├── bricks-list.yaml # Available bricks
Expand Down
4 changes: 1 addition & 3 deletions internal/e2e/daemon/brick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ func TestBricksList(t *testing.T) {
response, err := httpClient.GetBricksWithResponse(t.Context(), func(ctx context.Context, req *http.Request) error { return nil })
require.NoError(t, err)
require.NotEmpty(t, response.JSON200.Bricks)
cfg, err := config.NewFromEnv()
require.NoError(t, err)

staticStore := store.NewStaticStore(paths.New("testdata", "assets", cfg.RunnerVersion).String())
staticStore := store.NewStaticStore(paths.New("testdata", "assets", config.RunnerVersion).String())
brickIndex, err := bricksindex.Load(staticStore.GetAssetsFolder())
require.NoError(t, err)

Expand Down
12 changes: 4 additions & 8 deletions internal/orchestrator/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

// runnerVersion do not edit, this is generate with `task generate:assets`
var runnerVersion = "0.6.1"
var RunnerVersion = "0.6.1"

type Configuration struct {
appsDir *paths.Path
Expand Down Expand Up @@ -62,11 +62,7 @@ func NewFromEnv() (Configuration, error) {

dataDir := paths.New(os.Getenv("ARDUINO_APP_CLI__DATA_DIR"))
if dataDir == nil {
xdgHome, err := os.UserHomeDir()
if err != nil {
return Configuration{}, err
}
dataDir = paths.New(xdgHome).Join(".local", "share", "arduino-app-cli")
dataDir = paths.New("/var/lib/arduino-app-cli")
}

routerSocket := paths.New(os.Getenv("ARDUINO_ROUTER_SOCKET"))
Expand Down Expand Up @@ -113,7 +109,7 @@ func NewFromEnv() (Configuration, error) {
customEIModelsDir: customEIModelsDir,
PythonImage: pythonImage,
UsedPythonImageTag: usedPythonImageTag,
RunnerVersion: runnerVersion,
RunnerVersion: RunnerVersion,
AllowRoot: allowRoot,
LibrariesAPIURL: parsedLibrariesURL,
}
Expand Down Expand Up @@ -165,7 +161,7 @@ func getPythonImageAndTag() (string, string) {
// Python image: image name (repository) and optionally a tag.
pythonImageAndTag := os.Getenv("DOCKER_PYTHON_BASE_IMAGE")
if pythonImageAndTag == "" {
pythonImageAndTag = fmt.Sprintf("app-bricks/python-apps-base:%s", runnerVersion)
pythonImageAndTag = fmt.Sprintf("app-bricks/python-apps-base:%s", RunnerVersion)
}
pythonImage := path.Join(registryBase, pythonImageAndTag)
var usedPythonImageTag string
Expand Down