Skip to content

Commit a9ceb2d

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 3b1eec8 commit a9ceb2d

File tree

1 file changed

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

1 file changed

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

0 commit comments

Comments
 (0)