Skip to content

Commit 2be4c57

Browse files
committed
website: add a guide for running Lima on GHA
Lima is also useful for: - Running commands on non-Ubuntu operating systems such as Fedora - Emulating multiple hosts Signed-off-by: Akihiro Suda <[email protected]>
1 parent 591ce7e commit 2be4c57

File tree

1 file changed

+89
-0
lines changed
  • website/content/en/docs/examples

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
title: GitHub Actions
3+
weight: 10
4+
---
5+
6+
## Running Lima on GitHub Actions
7+
8+
Lima is also useful for:
9+
- Running commands on non-Ubuntu operating systems (e.g., Fedora for testing SELinux)
10+
- Emulating multiple hosts.
11+
12+
These tasks can be also partially accomplished with containers like Docker,
13+
but they are still stick to Ubuntu's kernel configuration and cannot use non-Ubuntu features such as SELinux.
14+
15+
On the other hand, Lima executes virtual machines that are decoupled from Ubuntu's kernel.
16+
17+
```yaml
18+
name: Fedora
19+
20+
on:
21+
workflow_dispatch:
22+
pull_request:
23+
24+
jobs:
25+
fedora:
26+
runs-on: ubuntu-24.04
27+
steps:
28+
- name: Check out code
29+
uses: actions/checkout@v4
30+
31+
- name: "Install QEMU"
32+
run: |
33+
set -eux
34+
sudo apt-get update
35+
sudo apt-get install -y --no-install-recommends ovmf qemu-system-x86 qemu-utils
36+
sudo modprobe kvm
37+
# `sudo usermod -aG kvm $(whoami)` does not take an effect on GHA
38+
sudo chown $(whoami) /dev/kvm
39+
40+
- name: "Install Lima"
41+
run: |
42+
set -eux
43+
LIMA_VERSION=$(curl -fsSL https://api.github.com/repos/lima-vm/lima/releases/latest | jq -r .tag_name)
44+
curl -fsSL https://github.com/lima-vm/lima/releases/download/${LIMA_VERSION}/lima-${LIMA_VERSION:1}-Linux-x86_64.tar.gz | sudo tar Cxzvf /usr/local -
45+
46+
- name: "Cache ~/.cache/lima"
47+
uses: actions/cache@v4
48+
with:
49+
path: ~/.cache/lima
50+
key: lima-${{ env.LIMA_VERSION }}
51+
52+
- name: "Start an instance of Fedora"
53+
run: |
54+
set -eux
55+
limactl start --name=default --cpus=1 --memory=1 --network=lima:user-v2 template://fedora
56+
lima sudo dnf install -y httpd
57+
58+
- name: "Start another instance of Fedora"
59+
run: |
60+
set -eux
61+
limactl start --name=another --cpus=1 --memory=1 --network=lima:user-v2 template://fedora
62+
limactl shell another curl http://lima-default.internal
63+
```
64+
65+
### Plain mode
66+
67+
The `--plain` mode is useful when you want the VM instance to be as close as possible to physical hosts:
68+
69+
```yaml
70+
- name: "Start Fedora"
71+
# --plain is set to disable file sharing, port forwarding, built-in containerd, etc.
72+
run: limactl start --plain --name=default --cpus=1 --memory=1 --network=lima:user-v2 template://fedora
73+
74+
- name: "Initialize Fedora"
75+
# plain old rsync and ssh are used for the initialization of the guest,
76+
# so that people who are not familiar with Lima can understand the initialization steps.
77+
run: |
78+
set -eux -o pipefail
79+
# Initialize SSH
80+
mkdir -p -m 0700 ~/.ssh
81+
cat ~/.lima/default/ssh.config >> ~/.ssh/config
82+
# Sync the current directory to /tmp/repo in the guest
83+
rsync -a -e ssh . lima-default:/tmp/repo
84+
# Install packages
85+
ssh lima-default sudo dnf install -y httpd
86+
```
87+
88+
### Full examples
89+
- https://github.com/kubernetes-sigs/kind/blob/v0.25.0/.github/workflows/vm.yaml#L47-L84

0 commit comments

Comments
 (0)