hypriot / flash

Command line script to flash SD card images of any kind
MIT License
1k stars 176 forks source link

Allow to download files related to cloud-init via http(s) #172

Closed witsch closed 4 years ago

witsch commented 4 years ago

With this URLs can be specified instead of local files for --bootconf, --config, --userdata, --metadata and --file.

StefanScherer commented 4 years ago

Thank you @witsch that sounds Like a super cool feature! I‘ll have a look at it soon.

witsch commented 4 years ago

Hmm, unfortunately the tests fail, but locally I've had the same strange failure for the "cloud-init: flash --metadata replaces meta-data" test I borrowed from…

> flash-test@0.0.1 test /code
> if [ -e ../node_modules/.bin/bats ]; then ../node_modules/.bin/bats --tap test; else node_modules/.bin/bats --tap test; fi

1..28
ok 1 cloud-init: flash aborts if YAML is not valid
ok 2 cloud-init: flash works
ok 3 cloud-init: flash --hostname sets hostname
ok 4 cloud-init: flash --ssid does NOT set ssid as it's COMMENTED in default image
ok 5 cloud-init: flash --password does NOT set psk as it's COMMENTED in default image
ok 6 cloud-init: flash --ssid still sets ssid when user-data also specified
ok 7 cloud-init: flash --password still sets psk when user-data also specified
ok 8 cloud-init: flash --ssid does NOT set ssid if COMMENTED when user-data also specified
ok 9 cloud-init: flash --password does NOT set psk if COMMENTED when user-data also specified
ok 10 cloud-init: flash --config does not replace user-data
ok 11 cloud-init: flash --userdata replaces user-data
not ok 12 cloud-init: flash --metadata replaces meta-data
# (from function `assert_contains' in file test/../../node_modules/bats-assert/all.bash, line 63,
#  from function `assert_output_contains' in file test/../../node_modules/bats-assert/all.bash, line 98,
#  in test file test/cloud-init.bats, line 212)
#   `assert_output_contains "hostname: good"' failed
# expected:   instance-id: iid-local01
# to contain: hostname: good
ok 13 cloud-init: flash --bootconf replaces config.txt
ok 14 cloud-init: flash --userdata can be downloaded
not ok 15 cloud-init: flash --metadata replaces meta-data
# (from function `assert_contains' in file test/../../node_modules/bats-assert/all.bash, line 63,
#  from function `assert_output_contains' in file test/../../node_modules/bats-assert/all.bash, line 98,
#  in test file test/cloud-init.bats, line 212)
#   `assert_output_contains "hostname: good"' failed
# expected:   instance-id: iid-local01
# to contain: hostname: good
ok 16 cloud-init: flash --userdata aborts on 'not found' (404)
ok 17 device-init: flash works
ok 18 device-init: flash --hostname sets hostname
ok 19 device-init: flash --ssid sets WiFi
ok 20 device-init: flash --config replaces device-init.yaml
ok 21 device-init: flash --bootconf replaces config.txt
ok 22 fake-hwclock: flash updates fake-hwclock.data
ok 23 flash with url to img.zip works
ok 24 # skip (Download is really slow and the use-case very rare) flash with url to img.xz works
ok 25 # skip (Download is really slow) flash with url to Raspbian LITE zip works
ok 26 flash --help shows usage
ok 27 flash without parameters shows usage
ok 28 flash --version shows version dirty
npm ERR! Test failed.  See above for more details.
make: *** [test] Error 1

I suppose I'll leave that assertion out of the new one as setting the hostname correctly is actually unrelated to downloading the file, right?

witsch commented 4 years ago

I suppose I'll leave that assertion out of the new one as setting the hostname correctly is actually unrelated to downloading the file, right?

Oops, turns out to be a bad "copy & paste"… 😊 It should be fixed in 024db1f88adfc5bca3069ba77243b232ae0394a9.

witsch commented 4 years ago

Thank you, that's really convenient, I can put my user-data file to GitHub :-)

Yes, that was the idea… after I recently got a new Pi and found HyprioOS (big props, btw) I started playing with Docker stacks (and I suppose that was mainly because of that blog post you guys put up), but most of the examples I found were either using compose or didn't quite work out of the box. Or at least for me, albeit not being very familar with the topic didn't help… 🙂

Anyway, after figuring a few things out I thought it might be useful to make it available somewhere, and at that point it just seemed nice to be able to avoid the extra step of downloading an example user-data file to get you started. But now I can… 😄