-
Notifications
You must be signed in to change notification settings - Fork 660
Embed binary files as base64 encoded strings #3421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm going to switch this to draft because I just thought of 2 changes I want to make:
|
4d3ad7e
to
ec7cfe9
Compare
Implemented: ❯ cat tmpl.yaml
base: template://alpine
provision:
- mode: data
file: sample.data
path: /tmp/data
❯ perl -E 'say "A" x 66000' > sample.data
❯ limactl tmpl copy --embed tmpl.yaml /dev/null
WARN[0000] `base` is experimental
WARN[0000] `provision[*].file` and `probes[*].file` are experimental
INFO[0000] File "/Users/jan/suse/lima/sample.data" is being base64 encoded: line 1 (offset 0) is longer than 65000 characters
❯ cp /bin/cat sample.data
❯ limactl tmpl copy --embed tmpl.yaml /dev/null
WARN[0000] `base` is experimental
WARN[0000] `provision[*].file` and `probes[*].file` are experimental
INFO[0000] File "/Users/jan/suse/lima/sample.data" is being base64 encoded: unprintable character '\x00' at offset 4 |
Full example: ❯ cat tmpl.yaml
base: template://alpine
provision:
- mode: system
file: my.script
❯ echo -e 'echo "Hello world\a\n"' > my.script
❯ hexdump -C my.script
00000000 65 63 68 6f 20 22 48 65 6c 6c 6f 20 77 6f 72 6c |echo "Hello worl|
00000010 64 07 0a 22 0a |d..".|
00000015
❯ limactl start -y tmpl.yaml
WARN[0000] `base` is experimental
WARN[0000] `provision[*].file` and `probes[*].file` are experimental
INFO[0000] File "/Users/jan/suse/lima/my.script" is being base64 encoded: unprintable character '\a' at offset 17
…
❯ grep -A2 provision ~/.lima/tmpl/lima.yaml
provision:
- mode: system
script: !!binary ZWNobyAiSGVsbG8gd29ybGQHCiIK
❯ limactl shell tmpl sudo grep Hello /var/log/cloud-init-output.log
Hello world |
ec7cfe9
to
953427a
Compare
953427a
to
f8a0b5d
Compare
Sorry, did one more force-push to move |
63f9a5d
to
3833782
Compare
Not that it really matters, but I've decided that |
3833782
to
5b1b52e
Compare
They need to be broken into smaller lines; yqlib doesn't do this, and yamlfmt fails with a buffer overflow when it tries to keep existing line breaks. Signed-off-by: Jan Dubois <[email protected]>
5b1b52e
to
715f78e
Compare
// yamlfmt will fail with a buffer overflow while trying to retain line breaks if the line | ||
// is longer than 64K. We will encode all text files that have a line that comes close. | ||
// maxLineLength is a constant; it is only a variable for the benefit of the unit tests. | ||
var maxLineLength = 65000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's a good idea to declare maxLineLength
as var
instead of const
.
For unit tests, we can use strings.Repeat
to construct a very long string.
var maxLineLength = 65000 | |
const maxLineLength = 65000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using strings.Repeat
before, but changed it in response to a request from @AkihiroSuda to add a test for `maxLineLength'.
It is not an exported variable, and the comment right above says it is only mutable so unit tests can mock it. Unit tests should use constant data for "expected" results. Otherwise a thinko in the implementation of the function that is being tested can carry over in the test function constructing the test data and cancel out the error in the implementation. Not that it matters in a trivial case like this.
I think it is fine as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
They need to be broken into smaller lines; yqlib doesn't do this, and yamlfmt fails with a buffer overflow when it tries to keep existing line breaks.
Fixes #3403