Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

What is the best way to copy a file during a provision script? #3402

etho201 started this conversation in General
Discussion options

Let's say I have a directory with my project files:

.
├── README.md
├── files
│  ├── Dockerfile
│  └── local-yum.repo
├── oraclelinux9.yaml
└── variables.yaml

In my oraclelinux9.yaml file, I have a provision section where I want to copy the files/local-yum.repo file to some other directory in the VM.

For example:

provision:
 - mode: system
 script: |
 #!/bin/bash
 mkdir -p /var/www/html/yum
 cp files/local-yum.repo /var/www/html/yum/

In addition to specifying a relative path, I tried specifying cp $LIMA_WORKDIR/files/local-yum.repo /var/www/html/yum/ but that doesn't work. I also tried adding a mount so I could predict where in the VM it will show up but that doesn't seem to be working either. What is the best way to do this?

You must be logged in to vote

Replies: 1 comment 7 replies

Comment options

You should be able to do this with a "data" provisioning file. Something like:

provision:
- mode: data
 file: files/local-yum.repo
 path: /var/www/html/yum/local-yum.repo

This also requires Lima 1.1.0-alpha.0 or later.

You must be logged in to vote
7 replies
Comment options

What about when/if I need a folder with several files (or if the file was a binary of sorts)?

Yes, data provisioning needs to specify each file individually.

Binary files will work as long as they are short. This can probably be fixed to work with long files too (#3403), but embedding long binary files in YAML (e.g. base64 encoded) will become unwieldy quickly.

printf "\x00\x01" > binary.datahexdump -C binary.data
00000000 00 01 |..|
00000002cat tmpl.yaml
base: template://alpine
provision:
- mode: data
 file: binary.data
 path: /tmp/binary.datalimactl tmpl copy --embed tmpl.yaml -
WARN[0000] `provision[*].file` and `probes[*].file` are experimental
base: template://alpine
provision:
- mode: data
 content: \x00\x01
 path: /tmp/binary.data
Comment options

Very cool that binary files can be passed through YAML as well. Thank you.

By the way, I was able to get the mount stuff working... the problem I faced yesterday is because I was using 1.1.0-alpha.0 to start the VM, but was using 1.0.7 to connect to the shell since that is what's in my environment path.

mounts:
 - location: files/
 mountPoint: /tmp/files
 writable: true

The error was WARN[0000] instance "ksplice-offline" has errors errors="[field mounts[2].location must be an absolute path, got \"files/\"]" but I guess that's just something that isn't supported in 1.0.7.

Comment options

No, the mount location must always be an absolute path, even with 1.1.0.

Things that can be relative paths are base and provision[].file locators, which are resolved when the instance is created, not when it is started (like the mounts).

Note that the relative locators are resolved relative to the location of the template that references them, not relative to your current directory. Assuming your recent example template:

limactl create https://example.com/oraclelinux.yaml

In that case values.yaml will be fetched from https://example.com/values.yaml and not from ./values.yaml.

Comment options

I've just created #3404 to allow combination of external templates and local settings without requiring you to create yet another local base template.

Comment options

Binary files will work as long as they are short. This can probably be fixed to work with long files too (#3403), but embedding long binary files in YAML (e.g. base64 encoded) will become unwieldy quickly.

I've implemented embedding of binary files as multi-line base64 strings in #3421 (but has not yet been merged).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /