Skip to content

Commit 07f7937

Browse files
author
Your Name
committed
dind
1 parent 1e534da commit 07f7937

File tree

3 files changed

+153
-44
lines changed

3 files changed

+153
-44
lines changed

.github/workflows/test-update.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Build & Update with Arduino CLI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- test_package_update
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
build-and-update:
15+
runs-on: ubuntu-22.04
16+
17+
env:
18+
TAG_VERSION: "v0.6.7"
19+
ARCH: amd64
20+
APPCLI_REPO: arduino/arduino-app-cli
21+
ROUTER_REPO: arduino/arduino-router
22+
23+
APPCLI_TAG: ""
24+
APPCLI_REGEX: "amd64\\.deb$"
25+
26+
ROUTER_TAG: ""
27+
ROUTER_REGEX: "amd64\\.deb$"
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Go
34+
uses: actions/setup-go@v5
35+
with:
36+
go-version-file: go.mod
37+
38+
- name: Build deb
39+
run: |
40+
go tool task build-deb VERSION=${TAG_VERSION} ARCH=${ARCH}
41+
42+
- name: Fetch .debs dynamically into build/stable
43+
env:
44+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
run: |
46+
set -euo pipefail
47+
mkdir -p build/stable
48+
49+
fetch_deb () {
50+
local repo="$1" tag="${2:-}" regex="$3"
51+
52+
echo "==> Resolving release for ${repo} (tag='${tag:-<latest>}')"
53+
if [ -n "${tag}" ]; then
54+
url="https://api.github.com/repos/${repo}/releases/tags/${tag}"
55+
else
56+
url="https://api.github.com/repos/${repo}/releases/latest"
57+
fi
58+
59+
rel="$(curl -sfL -H "Authorization: token ${GH_TOKEN}" -H "Accept: application/vnd.github+json" "${url}")"
60+
61+
name="$(echo "$rel" | jq -r --arg re "${regex}" '.assets[] | select(.name | test($re)) | .name' | head -n1)"
62+
dl="$(echo "$rel" | jq -r --arg re "${regex}" '.assets[] | select(.name | test($re)) | .browser_download_url' | head -n1)"
63+
64+
if [ -z "${name}" ] || [ "${name}" = "null" ] || [ -z "${dl}" ] || [ "${dl}" = "null" ]; then
65+
echo "!! No asset found in ${repo} matching regex: ${regex}"
66+
echo " Available assets:"
67+
echo "$rel" | jq -r '.assets[].name'
68+
exit 1
69+
fi
70+
71+
echo "Found: ${name}"
72+
echo "Downloading: ${dl}"
73+
74+
curl -sfL -H "Authorization: token ${GH_TOKEN}" \
75+
-o "build/stable/${name}" \
76+
"${dl}"
77+
78+
ls -lh "build/stable/${name}"
79+
}
80+
81+
fetch_deb "${APPCLI_REPO}" "${APPCLI_TAG}" "${APPCLI_REGEX}"
82+
fetch_deb "${ROUTER_REPO}" "${ROUTER_TAG}" "${ROUTER_REGEX}"
83+
84+
echo "✅ Downloaded files:"
85+
ls -lh build/stable/
86+
ls -lh build/
87+
88+
- name: Build Docker image (no cache)
89+
run: |
90+
docker build -t mock-apt-repo -f test.Dockerfile .
91+
92+
- name: Run mock-apt-repo container
93+
run: |
94+
docker run --rm -d \
95+
--privileged \
96+
--cgroupns=host \
97+
-v /sys/fs/cgroup:/sys/fs/cgroup:rw \
98+
-v /var/run/docker.sock:/var/run/docker.sock \
99+
-e DOCKER_HOST=unix:///var/run/docker.sock \
100+
--name apt-test-update \
101+
mock-apt-repo
102+
103+
- name: Run arduino-app-cli current version
104+
run: |
105+
docker exec --user arduino apt-test-update arduino-app-cli version
106+
107+
- name: Run arduino-app-cli with auto-yes (as arduino)
108+
run: |
109+
mkdir -p artifacts
110+
docker exec apt-test-update sh -lc 'su - arduino -c "yes | arduino-app-cli system update"' \
111+
| tee artifacts/arduino-system-update.log
112+
113+
- name: Run arduino-app-cli version updated
114+
run: |
115+
docker exec --user arduino apt-test-update arduino-app-cli version
116+
117+
- name: Restart arduino-app-cli service and verify
118+
run: |
119+
docker exec apt-test-update sh -lc '
120+
sudo systemctl status arduino-app-cli --no-pager
121+
sudo systemctl status arduino-router --no-pager
122+
'
123+
124+

Taskfile.yml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ vars:
1313
VERSION: # if version is not passed we hack the semver by encoding the commit as pre-release
1414
sh: echo "${VERSION:-0.0.0-$(git rev-parse --short HEAD)}"
1515
NEW_PACKAGE:
16-
sh: ls -1 ./build/arduino-app-cli_*.deb 2>/dev/null | head -n 1
16+
sh: ls -1 ./build/arduino-app-cli_*.deb 2>/dev/null | head -n 1
1717
GITHUB_TOKEN_FILE: ./github_token.txt
1818

1919
tasks:
@@ -130,26 +130,26 @@ tasks:
130130
desc: "Builds the mock-repo Docker image (requires GITHUB_TOKEN_FILE)"
131131
deps: [build-deb]
132132
vars:
133-
PKG_PATH: '{{.NEW_PACKAGE}}'
133+
PKG_PATH: "{{.NEW_PACKAGE}}"
134134
cmds:
135135
# --- MODIFIED ---
136136
# Check for both the package and the token file
137137
- |
138-
if [ ! -f "{{.GITHUB_TOKEN_FILE}}" ]; then
139-
echo "Error: GitHub token file not found at {{.GITHUB_TOKEN_FILE}}"
140-
echo "Please create this file and add your GitHub PAT to it."
141-
exit 1
142-
fi
138+
if [ ! -f "{{.GITHUB_TOKEN_FILE}}" ]; then
139+
echo "Error: GitHub token file not found at {{.GITHUB_TOKEN_FILE}}"
140+
echo "Please create this file and add your GitHub PAT to it."
141+
exit 1
142+
fi
143143
- |
144-
echo "Using package: {{.PKG_PATH}}"
145-
echo "Using GitHub token from: {{.GITHUB_TOKEN_FILE}}"
146-
147-
# Enable BuildKit and pass the secret
148-
DOCKER_BUILDKIT=1 docker build \
149-
--secret id=github_token,src={{.GITHUB_TOKEN_FILE}} \
150-
--build-arg NEW_PACKAGE_PATH={{.PKG_PATH}} \
151-
-t newdeb \
152-
-f test.Dockerfile .
144+
echo "Using package: {{.PKG_PATH}}"
145+
echo "Using GitHub token from: {{.GITHUB_TOKEN_FILE}}"
146+
147+
# Enable BuildKit and pass the secret
148+
DOCKER_BUILDKIT=1 docker build \
149+
--secret id=github_token,src={{.GITHUB_TOKEN_FILE}} \
150+
--build-arg NEW_PACKAGE_PATH={{.PKG_PATH}} \
151+
-t newdeb \
152+
-f test.Dockerfile .
153153
status:
154154
- '[[ -f "{{.PKG_PATH}}" ]]'
155155
- '[[ -f "{{.DOCKERFILE_NAME}}" ]]'
@@ -167,7 +167,6 @@ tasks:
167167
- docker run --rm -it --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro --name apt-test-update mock-apt-repo
168168
- docker exec -d apt-test-update /usr/bin/arduino-router
169169

170-
171170
arduino-app-cli:build:local:
172171
desc: "Build the arduino-app-cli locally"
173172
cmds:

test.Dockerfile

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,32 @@
11
FROM debian:trixie
22

3-
ENV container docker
4-
STOPSIGNAL SIGRTMIN+3
5-
VOLUME ["/sys/fs/cgroup"]
6-
7-
# Install systemd + dependencies
8-
RUN apt update && apt install -y systemd systemd-sysv dbus \
9-
dpkg-dev apt-utils adduser gzip \
10-
&& rm -rf /var/lib/apt/lists/*
11-
12-
# Copy your packages and setup repo (as before)
13-
ARG OLD_PACKAGE_PATH=build/old_package
14-
ARG NEW_PACKAGE_PATH=build
15-
ARG APP_PACKAGE_NAME=arduino-app-cli
16-
ARG ROUTER_PACKAGE_NAME=arduino-router
3+
RUN apt update && \
4+
apt install -y systemd systemd-sysv dbus \
5+
sudo docker.io ca-certificates curl gnupg \
6+
dpkg-dev apt-utils adduser gzip && \
7+
rm -rf /var/lib/apt/lists/*
8+
179
ARG ARCH=arm64
1810

19-
COPY ${OLD_PACKAGE_PATH}/${APP_PACKAGE_NAME}*.deb /tmp/old_app.deb
20-
COPY ${NEW_PACKAGE_PATH}/${APP_PACKAGE_NAME}*.deb /tmp/new_app.deb
21-
COPY ${NEW_PACKAGE_PATH}/${ROUTER_PACKAGE_NAME}*.deb /tmp/new_router.deb
11+
COPY build/stable/arduino-app-cli*.deb /tmp/stable.deb
12+
COPY build/arduino-app-cli*.deb /tmp/unstable.deb
13+
COPY build/stable/arduino-router*.deb /tmp/router.deb
2214

23-
RUN apt update && apt install -y /tmp/old_app.deb /tmp/new_router.deb \
24-
&& rm /tmp/old_app.deb \
15+
RUN apt update && apt install -y /tmp/stable.deb /tmp/router.deb \
16+
&& rm /tmp/stable.deb /tmp/router.deb \
2517
&& mkdir -p /var/www/html/myrepo/dists/trixie/main/binary-${ARCH} \
26-
&& mv /tmp/new_app.deb /var/www/html/myrepo/dists/trixie/main/binary-${ARCH}/ \
27-
&& mv /tmp/new_router.deb /var/www/html/myrepo/dists/trixie/main/binary-${ARCH}/
18+
&& mv /tmp/unstable.deb /var/www/html/myrepo/dists/trixie/main/binary-${ARCH}/
2819

2920
WORKDIR /var/www/html/myrepo
3021
RUN dpkg-scanpackages dists/trixie/main/binary-${ARCH} /dev/null | gzip -9c > dists/trixie/main/binary-${ARCH}/Packages.gz
3122
WORKDIR /
3223

3324
RUN usermod -s /bin/bash arduino || true
3425
RUN mkdir -p /home/arduino && chown -R arduino:arduino /home/arduino
35-
26+
RUN usermod -aG docker arduino
3627

3728
RUN echo "deb [trusted=yes arch=${ARCH}] file:/var/www/html/myrepo trixie main" \
3829
> /etc/apt/sources.list.d/my-mock-repo.list
3930

40-
41-
VOLUME [ "/sys/fs/cgroup" ]
42-
43-
44-
4531
# CMD: systemd must be PID 1
4632
CMD ["/sbin/init"]

0 commit comments

Comments
 (0)