Skip to content

Commit ccc7a24

Browse files
authored
Merge pull request #674 from AkihiroSuda/choose-examples
limactl start: support `limactl start template://TEMPLATE`
2 parents 53cd475 + d619d38 commit ccc7a24

File tree

13 files changed

+694
-488
lines changed

13 files changed

+694
-488
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ GO_BUILD := $(GO) build -ldflags="-s -w -X $(PACKAGE)/pkg/version.Version=$(VERS
1717
all: binaries
1818

1919
.PHONY: binaries
20-
binaries: \
20+
binaries: clean \
2121
_output/bin/lima \
2222
_output/bin/limactl \
2323
_output/bin/nerdctl.lima \
2424
_output/share/lima/lima-guestagent.Linux-x86_64 \
2525
_output/share/lima/lima-guestagent.Linux-aarch64
26+
cp -aL examples _output/share/lima
2627
mkdir -p _output/share/doc/lima
27-
cp -aL README.md LICENSE docs examples _output/share/doc/lima
28+
cp -aL *.md LICENSE docs _output/share/doc/lima
29+
ln -sf ../../lima/examples _output/share/doc/lima
2830
echo $(VERSION) > _output/share/doc/lima/VERSION
2931

3032
.PHONY: _output/bin/lima
@@ -54,14 +56,15 @@ _output/share/lima/lima-guestagent.Linux-aarch64:
5456
chmod 644 $@
5557

5658
.PHONY: install
57-
install:
59+
install: uninstall
5860
mkdir -p "$(DEST)"
59-
cp -av _output/* "$(DEST)"
61+
# Use tar rather than cp, for better symlink handling
62+
( cd _output && tar c * | tar Cxv "$(DEST)" )
6063
if [ "$(shell uname -s )" != "Linux" -a ! -e "$(DEST)/bin/nerdctl" ]; then ln -sf nerdctl.lima "$(DEST)/bin/nerdctl"; fi
6164

6265
.PHONY: uninstall
6366
uninstall:
64-
@test -f "$(DEST)/bin/lima" || (echo "lima not found in $(DEST) prefix"; exit 1)
67+
@test -f "$(DEST)/bin/lima" || echo "lima not found in $(DEST) prefix"
6568
rm -rf \
6669
"$(DEST)/bin/lima" \
6770
"$(DEST)/bin/limactl" \

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,28 @@ Detailed usage:
144144

145145
- Run `limactl start <INSTANCE> [--tty=false]` to start the Linux instance.
146146
The default instance name is "default".
147-
Lima automatically opens an editor (`vi`) for reviewing and modifying the configuration.
148147
Wait until "READY" to be printed on the host terminal.
149148
`--tty=false` disables the interactive prompt to open an editor.
150149

150+
```
151+
To create an instance "default" (if not created yet) from the default Ubuntu template, and start it:
152+
$ limactl start
153+
154+
To create an instance "default" from a template "docker":
155+
$ limactl start --name=default template://docker
156+
157+
To see the template list:
158+
$ limactl start --list-templates
159+
160+
To create an instance "default" from a local file:
161+
$ limactl start --name=default /usr/local/share/lima/examples/fedora.yaml
162+
163+
To create an instance "default" from a remote URL (use carefully, with a trustable source):
164+
$ limactl start --name=default https://raw.githubusercontent.com/lima-vm/lima/master/examples/alpine.yaml
165+
```
166+
NOTE: `limactl start template://TEMPLATE` requires Lima v0.9.0 or later.
167+
Older releases require `limactl start /usr/local/share/doc/lima/examples/TEMPLATE.yaml` instead.
168+
151169
- Run `limactl shell <INSTANCE> <COMMAND>` to launch `<COMMAND>` on Linux.
152170
For the "default" instance, this command can be shortened as `lima <COMMAND>`.
153171
The `lima` command also accepts the instance name as the environment variable `$LIMA_INSTANCE`.
@@ -178,7 +196,7 @@ Especially, the following data might be easily lost:
178196

179197
### Configuration
180198

181-
See [`./pkg/limayaml/default.yaml`](./pkg/limayaml/default.yaml).
199+
See [`./examples/default.yaml`](./examples/default.yaml).
182200

183201
The current default spec:
184202
- OS: Ubuntu 21.10 (Impish Indri)

cmd/limactl/edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func editAction(cmd *cobra.Command, args []string) error {
5656
hdr += "# and an empty file will abort the edit.\n"
5757
hdr += "\n"
5858
hdr += generateEditorWarningHeader()
59-
yBytes, err := openEditor(cmd, instName, yContent, hdr)
59+
yBytes, err := openEditor(instName, yContent, hdr)
6060
if err != nil {
6161
return err
6262
}

cmd/limactl/info.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,36 @@ func newInfoCommand() *cobra.Command {
2020
return infoCommand
2121
}
2222

23+
type TemplateYAML struct {
24+
Name string `json:"name"`
25+
Location string `json:"location"`
26+
}
27+
2328
type Info struct {
2429
Version string `json:"version"`
30+
Templates []TemplateYAML `json:"templates"`
2531
DefaultTemplate *limayaml.LimaYAML `json:"defaultTemplate"`
2632
LimaHome string `json:"limaHome"`
2733
// TODO: add diagnostic info of QEMU
2834
}
2935

3036
func infoAction(cmd *cobra.Command, args []string) error {
31-
y, err := limayaml.Load(limayaml.DefaultTemplate, "")
37+
b, err := readDefaultTemplate()
38+
if err != nil {
39+
return err
40+
}
41+
y, err := limayaml.Load(b, "")
3242
if err != nil {
3343
return err
3444
}
3545
info := &Info{
3646
Version: version.Version,
3747
DefaultTemplate: y,
3848
}
49+
info.Templates, err = listTemplateYAMLs()
50+
if err != nil {
51+
return err
52+
}
3953
info.LimaHome, err = dirnames.LimaDir()
4054
if err != nil {
4155
return err

0 commit comments

Comments
 (0)