Skip to content

Commit dce2040

Browse files
Flasher: download images from production
1 parent 9c1567c commit dce2040

File tree

3 files changed

+10
-54
lines changed

3 files changed

+10
-54
lines changed

README.md

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,12 @@ A tool to download and flash Debian images on the board.
44

55
## Build and test it locally
66

7-
Build it with `task arduino-flasher-cli:build` and run `task flash:staging` to download and flash the latest image from staging.
8-
9-
Alternatively, these are the steps to test it locally:
10-
11-
1. download a debian image release (for example from [here](https:/downloads.oniudra.cc/debian-im/Stable/20250902-166/arduino-unoq-debian-image-20250902-166.tar.xz), then create the following structure under `arduino-flasher-cli/`:
12-
13-
```
14-
arduino-flasher-cli/public/
15-
└── debian-im
16-
└── Stable
17-
├── 20250902-166
18-
│ └── arduino-unoq-debian-image-20250902-166.tar.xz
19-
└── info.json
20-
```
21-
22-
2. Populate `info.json`:
23-
24-
```
25-
{
26-
"latest": {
27-
"version": "20250902-166",
28-
"url": "http://127.0.0.1:3001/debian-im/Stable/20250902-166/arduino-unoq-debian-image-20250902-166.tar.xz",
29-
"md5sum": "ad0aac0a9b18982e9dce0dd99808a5e5"
30-
}
31-
}
32-
```
33-
34-
3. `task debian:release-server:start`
35-
4. `UPDATE_URL=http://127.0.0.1:3001 ./build/arduino-flasher-cli flash latest`
36-
37-
## Flash from staging
38-
39-
To download and flash the latest image from staging, the tool needs cloudflare credentials. This is the command that should be used:
7+
Build it with `task arduino-flasher-cli:build` and run:
408

419
```sh
42-
CF_ACCESS_CLIENT_ID="$(aws ssm get-parameter --profile arduino-staging --with-decryption --name /devops/downloads/cloudflare_access_client_id --query Parameter.Value --output text)" CF_ACCESS_CLIENT_SECRET="$(aws ssm get-parameter --profile arduino-staging --with-decryption --name /devops/downloads/cloudflare_access_client_secret --query Parameter.Value --output text)" ./arduino-flasher-cli flash latest
10+
# Flash the latest release of the Debian image
11+
./build/arduino-flasher-cli flash latest
12+
13+
# Flash a local image. It works with either an archived or extracted image
14+
./build/arduino-flasher-cli flash path/to/downloaded/image
4315
```

updater/flasher.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"log/slog"
77
"net/url"
8-
"os"
98
"runtime"
109
"strings"
1110

@@ -20,31 +19,14 @@ var assets embed.FS
2019

2120
func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes bool) error {
2221
if !imagePath.Exist() {
23-
updateURL := os.Getenv("UPDATE_URL")
24-
if updateURL == "" {
25-
// TODO: change to prod
26-
updateURL = "https://downloads.oniudra.cc"
27-
}
22+
updateURL := "https://downloads.arduino.cc"
2823

2924
parsedURL, err := url.Parse(updateURL)
3025
if err != nil {
3126
return fmt.Errorf("invalid UPDATE_URL: %v", err)
3227
}
3328

34-
headers := map[string]string{}
35-
clientID := os.Getenv("CF_ACCESS_CLIENT_ID")
36-
clientSecret := os.Getenv("CF_ACCESS_CLIENT_SECRET")
37-
if clientID != "" && clientSecret != "" {
38-
headers["CF-Access-Client-Id"] = clientID
39-
headers["CF-Access-Client-Secret"] = clientSecret
40-
}
41-
42-
var client *Client
43-
if len(headers) == 2 {
44-
client = NewClient(parsedURL, "debian-im/Stable", WithHeaders(headers))
45-
} else {
46-
client = NewClient(parsedURL, "debian-im/Stable")
47-
}
29+
client := NewClient(parsedURL, "debian-im/Stable")
4830

4931
tempImagePath, err := DownloadAndExtract(client, version, func(target string) (bool, error) {
5032
feedback.Printf("Found Debian image version: %s", target)

updater/http_client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (c *Client) GetInfoManifest() (Manifest, error) {
6969
return Manifest{}, fmt.Errorf("failed to create request: %w", err)
7070
}
7171
c.addHeaders(req)
72+
req.SetBasicAuth("arduino", "changeme")
7273
// #nosec G107 -- manifestURL is constructed from trusted config and parameters
7374
resp, err := c.HTTPClient.Do(req)
7475
if err != nil {
@@ -98,6 +99,7 @@ func (c *Client) FetchZip(zipURL string) (io.ReadCloser, int64, error) {
9899
return nil, 0, fmt.Errorf("failed to create request: %w", err)
99100
}
100101
c.addHeaders(req)
102+
req.SetBasicAuth("arduino", "changeme")
101103
// #nosec G107 -- zipURL is constructed from trusted config and parameters
102104
resp, err := c.HTTPClient.Do(req)
103105
if err != nil {

0 commit comments

Comments
 (0)